2017-11-25 10:04:45 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Issuable::DestroyService do
|
|
|
|
let(:user) { create(:user) }
|
2017-12-08 07:17:22 -05:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-11-25 10:04:45 -05:00
|
|
|
|
|
|
|
subject(:service) { described_class.new(project, user) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'when issuable is an issue' do
|
2018-03-23 01:09:26 -04:00
|
|
|
let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
|
2017-11-25 10:04:45 -05: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 07:17:22 -05:00
|
|
|
|
|
|
|
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
|
2018-03-23 01:09:26 -04: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
|
2017-11-25 10:04:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when issuable is a merge request' do
|
2018-03-23 01:09:26 -04:00
|
|
|
let!(:merge_request) { create(:merge_request, target_project: project, source_project: project, author: user, assignee: user) }
|
2017-11-25 10:04:45 -05: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 07:17:22 -05:00
|
|
|
|
2018-03-23 01:09:26 -04: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
|
|
|
|
|
2017-12-08 07:17:22 -05:00
|
|
|
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)
|
|
|
|
end
|
2017-11-25 10:04:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|