2016-08-09 15:51:40 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Issues::ReopenService do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2016-08-12 19:05:10 +00:00
|
|
|
let(:issue) { create(:issue, :closed, project: project) }
|
2016-08-09 15:51:40 +00:00
|
|
|
|
|
|
|
describe '#execute' do
|
2016-08-30 22:11:46 +00:00
|
|
|
context 'when user is not authorized to reopen issue' do
|
2016-08-09 15:51:40 +00:00
|
|
|
before do
|
2016-08-12 19:05:10 +00:00
|
|
|
guest = create(:user)
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_guest(guest)
|
2016-08-12 19:05:10 +00:00
|
|
|
|
2016-08-09 15:51:40 +00:00
|
|
|
perform_enqueued_jobs do
|
2016-08-29 19:08:40 +00:00
|
|
|
described_class.new(project, guest).execute(issue)
|
2016-08-09 15:51:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not reopen the issue' do
|
2016-08-29 19:08:40 +00:00
|
|
|
expect(issue).to be_closed
|
2016-08-09 15:51:40 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-12 19:05:10 +00:00
|
|
|
|
2016-08-30 22:11:46 +00:00
|
|
|
context 'when user is authrized to reopen issue' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_master(user)
|
2016-08-30 22:11:46 +00:00
|
|
|
end
|
|
|
|
|
2017-05-26 13:29:42 +00:00
|
|
|
it 'invalidates counter cache for assignees' do
|
|
|
|
issue.assignees << user
|
|
|
|
expect_any_instance_of(User).to receive(:invalidate_issue_cache_counts)
|
|
|
|
|
|
|
|
described_class.new(project, user).execute(issue)
|
|
|
|
end
|
|
|
|
|
2017-08-17 15:21:25 +00:00
|
|
|
it 'refreshes the number of opened issues' do
|
|
|
|
service = described_class.new(project, user)
|
|
|
|
|
|
|
|
expect { service.execute(issue) }
|
|
|
|
.to change { project.open_issues_count }.from(0).to(1)
|
|
|
|
end
|
|
|
|
|
2016-08-30 22:11:46 +00:00
|
|
|
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)
|
2016-08-12 19:05:10 +00:00
|
|
|
|
2016-08-30 22:11:46 +00:00
|
|
|
described_class.new(project, user).execute(issue)
|
|
|
|
end
|
|
|
|
end
|
2016-08-12 19:05:10 +00:00
|
|
|
|
2016-08-30 22:11:46 +00:00
|
|
|
context 'when issue is confidential' do
|
|
|
|
it 'executes confidential issue hooks' do
|
|
|
|
issue = create(:issue, :confidential, :closed, project: project)
|
2016-08-12 19:05:10 +00:00
|
|
|
|
2016-08-30 22:11:46 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
described_class.new(project, user).execute(issue)
|
|
|
|
end
|
2016-08-12 19:05:10 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-09 15:51:40 +00:00
|
|
|
end
|
|
|
|
end
|