debian-mirror-gitlab/spec/services/issues/reopen_service_spec.rb

87 lines
2.8 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Issues::ReopenService do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2016-09-29 09:46:39 +05:30
let(:issue) { create(:issue, :closed, project: project) }
2016-09-13 17:45:13 +05:30
describe '#execute' do
2016-09-29 09:46:39 +05:30
context 'when user is not authorized to reopen issue' do
2016-09-13 17:45:13 +05:30
before do
2016-09-29 09:46:39 +05:30
guest = create(:user)
2018-03-17 18:26:18 +05:30
project.add_guest(guest)
2016-09-29 09:46:39 +05:30
2016-09-13 17:45:13 +05:30
perform_enqueued_jobs do
2021-06-08 01:23:25 +05:30
described_class.new(project: project, current_user: guest).execute(issue)
2016-09-13 17:45:13 +05:30
end
end
it 'does not reopen the issue' do
2016-09-29 09:46:39 +05:30
expect(issue).to be_closed
end
end
2018-11-18 11:00:15 +05:30
context 'when user is authorized to reopen issue' do
2016-09-29 09:46:39 +05:30
let(:user) { create(:user) }
before do
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2016-09-29 09:46:39 +05:30
end
2017-08-17 22:00:37 +05:30
it 'invalidates counter cache for assignees' do
issue.assignees << user
expect_any_instance_of(User).to receive(:invalidate_issue_cache_counts)
2021-06-08 01:23:25 +05:30
described_class.new(project: project, current_user: user).execute(issue)
2017-08-17 22:00:37 +05:30
end
2018-03-17 18:26:18 +05:30
it 'refreshes the number of opened issues' do
2021-06-08 01:23:25 +05:30
service = described_class.new(project: project, current_user: user)
2018-03-17 18:26:18 +05:30
expect { service.execute(issue) }
.to change { project.open_issues_count }.from(0).to(1)
end
2020-04-08 14:13:33 +05:30
it 'deletes milestone issue counters cache' do
2020-11-24 15:15:51 +05:30
issue.update!(milestone: create(:milestone, project: project))
2020-04-08 14:13:33 +05:30
expect_next_instance_of(Milestones::ClosedIssuesCountService, issue.milestone) do |service|
expect(service).to receive(:delete_cache).and_call_original
end
2021-06-08 01:23:25 +05:30
described_class.new(project: project, current_user: user).execute(issue)
2020-04-08 14:13:33 +05:30
end
2020-11-24 15:15:51 +05:30
context 'issue is incident type' do
let(:issue) { create(:incident, :closed, project: project) }
let(:current_user) { user }
2021-06-08 01:23:25 +05:30
subject { described_class.new(project: project, current_user: user).execute(issue) }
2020-11-24 15:15:51 +05:30
it_behaves_like 'an incident management tracked event', :incident_management_incident_reopened
end
2016-09-29 09:46:39 +05:30
context 'when issue is not confidential' do
it 'executes issue hooks' do
expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :issue_hooks)
expect(project).to receive(:execute_services).with(an_instance_of(Hash), :issue_hooks)
2021-06-08 01:23:25 +05:30
described_class.new(project: project, current_user: user).execute(issue)
2016-09-29 09:46:39 +05:30
end
end
context 'when issue is confidential' do
it 'executes confidential issue hooks' do
issue = create(:issue, :confidential, :closed, project: project)
expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :confidential_issue_hooks)
expect(project).to receive(:execute_services).with(an_instance_of(Hash), :confidential_issue_hooks)
2021-06-08 01:23:25 +05:30
described_class.new(project: project, current_user: user).execute(issue)
2016-09-29 09:46:39 +05:30
end
2016-09-13 17:45:13 +05:30
end
end
end
end