diff options
Diffstat (limited to 'spec/services/users')
-rw-r--r-- | spec/services/users/destroy_service_spec.rb | 35 | ||||
-rw-r--r-- | spec/services/users/saved_replies/destroy_service_spec.rb | 35 | ||||
-rw-r--r-- | spec/services/users/saved_replies/update_service_spec.rb | 2 |
3 files changed, 71 insertions, 1 deletions
diff --git a/spec/services/users/destroy_service_spec.rb b/spec/services/users/destroy_service_spec.rb index 602db66dba1..80a506bb1d6 100644 --- a/spec/services/users/destroy_service_spec.rb +++ b/spec/services/users/destroy_service_spec.rb @@ -332,4 +332,39 @@ RSpec.describe Users::DestroyService do expect(User.exists?(other_user.id)).to be(false) end end + + context 'batched nullify' do + let(:other_user) { create(:user) } + + context 'when :nullify_in_batches_on_user_deletion feature flag is enabled' do + it 'nullifies related associations in batches' do + expect(other_user).to receive(:nullify_dependent_associations_in_batches).and_call_original + + described_class.new(user).execute(other_user, skip_authorization: true) + end + + it 'nullifies last_updated_issues and closed_issues' do + issue = create(:issue, closed_by: other_user, updated_by: other_user) + + described_class.new(user).execute(other_user, skip_authorization: true) + + issue.reload + + expect(issue.closed_by).to be_nil + expect(issue.updated_by).to be_nil + end + end + + context 'when :nullify_in_batches_on_user_deletion feature flag is disabled' do + before do + stub_feature_flags(nullify_in_batches_on_user_deletion: false) + end + + it 'does not use batching' do + expect(other_user).not_to receive(:nullify_dependent_associations_in_batches) + + described_class.new(user).execute(other_user, skip_authorization: true) + end + end + end end diff --git a/spec/services/users/saved_replies/destroy_service_spec.rb b/spec/services/users/saved_replies/destroy_service_spec.rb new file mode 100644 index 00000000000..cb97fac7b7c --- /dev/null +++ b/spec/services/users/saved_replies/destroy_service_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Users::SavedReplies::DestroyService do + describe '#execute' do + let!(:saved_reply) { create(:saved_reply) } + + subject { described_class.new(saved_reply: saved_reply).execute } + + context 'when destroy fails' do + before do + allow(saved_reply).to receive(:destroy).and_return(false) + end + + it 'does not remove Saved Reply from database' do + expect { subject }.not_to change(::Users::SavedReply, :count) + end + + it { is_expected.not_to be_success } + end + + context 'when destroy succeeds' do + it { is_expected.to be_success } + + it 'removes Saved Reply from database' do + expect { subject }.to change(::Users::SavedReply, :count).by(-1) + end + + it 'returns saved reply' do + expect(subject[:saved_reply]).to eq(saved_reply) + end + end + end +end diff --git a/spec/services/users/saved_replies/update_service_spec.rb b/spec/services/users/saved_replies/update_service_spec.rb index b67d09977c6..bdb54d7c8f7 100644 --- a/spec/services/users/saved_replies/update_service_spec.rb +++ b/spec/services/users/saved_replies/update_service_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Users::SavedReplies::UpdateService do let_it_be(:other_saved_reply) { create(:saved_reply, user: current_user) } let_it_be(:saved_reply_from_other_user) { create(:saved_reply) } - subject { described_class.new(current_user: current_user, saved_reply: saved_reply, name: name, content: content).execute } + subject { described_class.new(saved_reply: saved_reply, name: name, content: content).execute } context 'when update fails' do let(:name) { other_saved_reply.name } |