Commit 9ddd2535 authored by Tan Le's avatar Tan Le

Ensure method return result of destroy operation

Remove `destroyed?` check to handle cases where
destroy operation fail and returns `false` instead of
the user object.

Add test to ensure the return interface is honoured.
parent 9f019158
...@@ -11,7 +11,9 @@ module EE ...@@ -11,7 +11,9 @@ module EE
mirror_cleanup(delete_user) mirror_cleanup(delete_user)
end end
log_audit_event(user) if result.destroyed? log_audit_event(user) if result
result
end end
def mirror_cleanup(user) def mirror_cleanup(user)
......
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
require 'spec_helper' require 'spec_helper'
describe Users::DestroyService do describe Users::DestroyService do
let(:current_user) { create(:admin) }
let(:user) { create(:user) }
subject(:service) { described_class.new(current_user) }
it 'returns result' do
allow(user).to receive(:destroy).and_return(user)
expect(service.execute(user)).to eq(user)
end
context 'when project is a mirror' do context 'when project is a mirror' do
it 'assigns mirror_user to a project owner' do it 'assigns mirror_user to a project owner' do
mirror_user = create(:user) mirror_user = create(:user)
...@@ -18,11 +29,6 @@ describe Users::DestroyService do ...@@ -18,11 +29,6 @@ describe Users::DestroyService do
end end
describe 'audit events' do describe 'audit events' do
let(:current_user) { create(:admin) }
let(:user) { create(:user) }
subject(:service) { described_class.new(current_user) }
before do before do
stub_licensed_features(admin_audit_log: true) stub_licensed_features(admin_audit_log: true)
end end
...@@ -44,7 +50,7 @@ describe Users::DestroyService do ...@@ -44,7 +50,7 @@ describe Users::DestroyService do
context 'when user destroy operation fails' do context 'when user destroy operation fails' do
before do before do
allow(user).to receive(:destroy).and_return(user) allow(user).to receive(:destroy).and_return(false)
end end
it 'logs audit events for ghost user migration operation' do it 'logs audit events for ghost user migration operation' do
...@@ -72,7 +78,7 @@ describe Users::DestroyService do ...@@ -72,7 +78,7 @@ describe Users::DestroyService do
context 'when user destroy operation fails' do context 'when user destroy operation fails' do
before do before do
allow(user).to receive(:destroy).and_return(user) allow(user).to receive(:destroy).and_return(false)
end end
it 'does not log any audit event' do it 'does not log any audit event' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment