summaryrefslogtreecommitdiff
path: root/spec/services/issues/close_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/issues/close_service_spec.rb')
-rw-r--r--spec/services/issues/close_service_spec.rb67
1 files changed, 52 insertions, 15 deletions
diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb
index aff022a573e..4465f22a001 100644
--- a/spec/services/issues/close_service_spec.rb
+++ b/spec/services/issues/close_service_spec.rb
@@ -15,15 +15,44 @@ describe Issues::CloseService, services: true do
end
describe '#execute' do
+ let(:service) { described_class.new(project, user) }
+
+ it 'checks if the user is authorized to update the issue' do
+ expect(service).to receive(:can?).with(user, :update_issue, issue).
+ and_call_original
+
+ service.execute(issue)
+ end
+
+ it 'does not close the issue when the user is not authorized to do so' do
+ allow(service).to receive(:can?).with(user, :update_issue, issue).
+ and_return(false)
+
+ expect(service).not_to receive(:close_issue)
+ expect(service.execute(issue)).to eq(issue)
+ end
+
+ it 'closes the issue when the user is authorized to do so' do
+ allow(service).to receive(:can?).with(user, :update_issue, issue).
+ and_return(true)
+
+ expect(service).to receive(:close_issue).
+ with(issue, commit: nil, notifications: true, system_note: true)
+
+ service.execute(issue)
+ end
+ end
+
+ describe '#close_issue' do
context "valid params" do
before do
perform_enqueued_jobs do
- @issue = described_class.new(project, user, {}).execute(issue)
+ described_class.new(project, user).close_issue(issue)
end
end
- it { expect(@issue).to be_valid }
- it { expect(@issue).to be_closed }
+ it { expect(issue).to be_valid }
+ it { expect(issue).to be_closed }
it 'sends email to user2 about assign of new issue' do
email = ActionMailer::Base.deliveries.last
@@ -32,7 +61,7 @@ describe Issues::CloseService, services: true do
end
it 'creates system note about issue reassign' do
- note = @issue.notes.last
+ note = issue.notes.last
expect(note.note).to include "Status changed to closed"
end
@@ -41,26 +70,34 @@ describe Issues::CloseService, services: true do
end
end
- context 'current user is not authorized to close issue' do
- before do
- perform_enqueued_jobs do
- @issue = described_class.new(project, guest).execute(issue)
- end
+ 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)
+
+ described_class.new(project, user).close_issue(issue)
end
+ end
+
+ context 'when issue is confidential' do
+ it 'executes confidential issue hooks' do
+ issue = create(:issue, :confidential, 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)
- it 'does not close the issue' do
- expect(@issue).to be_open
+ described_class.new(project, user).close_issue(issue)
end
end
- context "external issue tracker" do
+ context 'external issue tracker' do
before do
allow(project).to receive(:default_issues_tracker?).and_return(false)
- @issue = described_class.new(project, user, {}).execute(issue)
+ described_class.new(project, user).close_issue(issue)
end
- it { expect(@issue).to be_valid }
- it { expect(@issue).to be_opened }
+ it { expect(issue).to be_valid }
+ it { expect(issue).to be_opened }
it { expect(todo.reload).to be_pending }
end
end