debian-mirror-gitlab/spec/services/issuable/destroy_service_spec.rb

68 lines
2.1 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Issuable::DestroyService do
2018-03-17 18:26:18 +05:30
let(:user) { create(:user) }
2021-04-29 21:17:54 +05:30
let(:group) { create(:group, :public) }
let(:project) { create(:project, :public, group: group) }
2018-03-17 18:26:18 +05:30
2021-06-08 01:23:25 +05:30
subject(:service) { described_class.new(project: project, current_user: user) }
2018-03-17 18:26:18 +05:30
describe '#execute' do
context 'when issuable is an issue' do
2018-05-09 12:01:36 +05:30
let!(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
2018-03-17 18:26:18 +05:30
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
2018-05-09 12:01:36 +05:30
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-29 21:17:54 +05:30
it_behaves_like 'service deleting todos' do
let(:issuable) { issue }
end
2021-06-08 01:23:25 +05:30
it_behaves_like 'service deleting label links' do
let(:issuable) { issue }
end
2018-03-17 18:26:18 +05:30
end
context 'when issuable is a merge request' do
2019-07-31 22:56:46 +05:30
let!(:merge_request) { create(:merge_request, target_project: project, source_project: project, author: user, assignees: [user]) }
2018-03-17 18:26:18 +05:30
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
2018-05-09 12:01:36 +05:30
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-29 21:17:54 +05:30
it_behaves_like 'service deleting todos' do
let(:issuable) { merge_request }
2018-03-17 18:26:18 +05:30
end
2021-06-08 01:23:25 +05:30
it_behaves_like 'service deleting label links' do
let(:issuable) { merge_request }
end
2018-03-17 18:26:18 +05:30
end
end
end