summaryrefslogtreecommitdiff
path: root/spec/services/issuable/destroy_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/issuable/destroy_service_spec.rb')
-rw-r--r--spec/services/issuable/destroy_service_spec.rb44
1 files changed, 32 insertions, 12 deletions
diff --git a/spec/services/issuable/destroy_service_spec.rb b/spec/services/issuable/destroy_service_spec.rb
index 8d62932f986..fadab77a043 100644
--- a/spec/services/issuable/destroy_service_spec.rb
+++ b/spec/services/issuable/destroy_service_spec.rb
@@ -9,6 +9,32 @@ RSpec.describe Issuable::DestroyService do
subject(:service) { described_class.new(project, user) }
describe '#execute' do
+ shared_examples_for 'service deleting todos' do
+ it 'destroys associated todos asynchronously' do
+ expect(TodosDestroyer::DestroyedIssuableWorker)
+ .to receive(:perform_async)
+ .with(issuable.id, issuable.class.name)
+
+ subject.execute(issuable)
+ end
+
+ context 'when destroy_issuable_todos_async feature is disabled' do
+ before do
+ stub_feature_flags(destroy_issuable_todos_async: false)
+ end
+
+ it 'destroy associated todos synchronously' do
+ expect_next_instance_of(TodosDestroyer::DestroyedIssuableWorker) do |worker|
+ expect(worker)
+ .to receive(:perform)
+ .with(issuable.id, issuable.class.name)
+ end
+
+ subject.execute(issuable)
+ end
+ end
+ end
+
context 'when issuable is an issue' do
let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
@@ -22,17 +48,14 @@ RSpec.describe Issuable::DestroyService do
service.execute(issue)
end
- it 'updates the todo caches for users with todos on the issue' do
- create(:todo, target: issue, user: user, author: user, project: project)
-
- expect { service.execute(issue) }
- .to change { user.todos_pending_count }.from(1).to(0)
- end
-
it 'invalidates the issues count cache for the assignees' do
expect_any_instance_of(User).to receive(:invalidate_cache_counts).once
service.execute(issue)
end
+
+ it_behaves_like 'service deleting todos' do
+ let(:issuable) { issue }
+ end
end
context 'when issuable is a merge request' do
@@ -53,11 +76,8 @@ RSpec.describe Issuable::DestroyService do
service.execute(merge_request)
end
- it 'updates the todo caches for users with todos on the merge request' do
- create(:todo, target: merge_request, user: user, author: user, project: project)
-
- expect { service.execute(merge_request) }
- .to change { user.todos_pending_count }.from(1).to(0)
+ it_behaves_like 'service deleting todos' do
+ let(:issuable) { merge_request }
end
end
end