2019-04-11 12:17:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-25 15:04:45 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe Issuable::DestroyService do
|
2017-11-25 15:04:45 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-12-08 12:17:22 +00:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-11-25 15:04:45 +00:00
|
|
|
|
|
|
|
subject(:service) { described_class.new(project, user) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
2021-04-08 03:09:23 +00:00
|
|
|
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
|
|
|
|
|
2017-11-25 15:04:45 +00:00
|
|
|
context 'when issuable is an issue' do
|
2018-03-23 05:09:26 +00:00
|
|
|
let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
|
2017-11-25 15:04:45 +00:00
|
|
|
|
|
|
|
it 'destroys the issue' do
|
|
|
|
expect { service.execute(issue) }.to change { project.issues.count }.by(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates open issues count cache' do
|
|
|
|
expect_any_instance_of(Projects::OpenIssuesCountService).to receive(:refresh_cache)
|
|
|
|
|
|
|
|
service.execute(issue)
|
|
|
|
end
|
2017-12-08 12:17:22 +00:00
|
|
|
|
2018-03-23 05:09:26 +00:00
|
|
|
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
|
2021-04-08 03:09:23 +00:00
|
|
|
|
|
|
|
it_behaves_like 'service deleting todos' do
|
|
|
|
let(:issuable) { issue }
|
|
|
|
end
|
2017-11-25 15:04:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issuable is a merge request' do
|
2019-04-07 18:35:16 +00:00
|
|
|
let!(:merge_request) { create(:merge_request, target_project: project, source_project: project, author: user, assignees: [user]) }
|
2017-11-25 15:04:45 +00:00
|
|
|
|
|
|
|
it 'destroys the merge request' do
|
|
|
|
expect { service.execute(merge_request) }.to change { project.merge_requests.count }.by(-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates open merge requests count cache' do
|
|
|
|
expect_any_instance_of(Projects::OpenMergeRequestsCountService).to receive(:refresh_cache)
|
|
|
|
|
|
|
|
service.execute(merge_request)
|
|
|
|
end
|
2017-12-08 12:17:22 +00:00
|
|
|
|
2018-03-23 05:09:26 +00:00
|
|
|
it 'invalidates the merge request caches for the MR assignee' do
|
|
|
|
expect_any_instance_of(User).to receive(:invalidate_cache_counts).once
|
|
|
|
service.execute(merge_request)
|
|
|
|
end
|
|
|
|
|
2021-04-08 03:09:23 +00:00
|
|
|
it_behaves_like 'service deleting todos' do
|
|
|
|
let(:issuable) { merge_request }
|
2017-12-08 12:17:22 +00:00
|
|
|
end
|
2017-11-25 15:04:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|