Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers/merge_requests/close_issue_worker_spec.rb')
-rw-r--r--spec/workers/merge_requests/close_issue_worker_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/workers/merge_requests/close_issue_worker_spec.rb b/spec/workers/merge_requests/close_issue_worker_spec.rb
new file mode 100644
index 00000000000..5e6bdc2a43e
--- /dev/null
+++ b/spec/workers/merge_requests/close_issue_worker_spec.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe MergeRequests::CloseIssueWorker do
+ subject(:worker) { described_class.new }
+
+ describe '#perform' do
+ let!(:user) { create(:user) }
+ let!(:project) { create(:project) }
+ let!(:issue) { create(:issue, project: project) }
+ let!(:merge_request) { create(:merge_request, source_project: project) }
+
+ it 'calls the close issue service' do
+ expect_next_instance_of(Issues::CloseService, project: project, current_user: user) do |service|
+ expect(service).to receive(:execute).with(issue, commit: merge_request)
+ end
+
+ subject.perform(project.id, user.id, issue.id, merge_request.id)
+ end
+
+ shared_examples 'when object does not exist' do
+ it 'does not call the close issue service' do
+ expect(Issues::CloseService).not_to receive(:new)
+
+ expect { subject.perform(project.id, user.id, issue.id, merge_request.id) }
+ .not_to raise_exception
+ end
+ end
+
+ context 'when the project does not exist' do
+ before do
+ project.destroy!
+ end
+
+ it_behaves_like 'when object does not exist'
+ end
+
+ context 'when the user does not exist' do
+ before do
+ user.destroy!
+ end
+
+ it_behaves_like 'when object does not exist'
+ end
+
+ context 'when the issue does not exist' do
+ before do
+ issue.destroy!
+ end
+
+ it_behaves_like 'when object does not exist'
+ end
+
+ context 'when the merge request does not exist' do
+ before do
+ merge_request.destroy!
+ end
+
+ it_behaves_like 'when object does not exist'
+ end
+ end
+end