diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /spec/workers/deployments/link_merge_request_worker_spec.rb | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'spec/workers/deployments/link_merge_request_worker_spec.rb')
-rw-r--r-- | spec/workers/deployments/link_merge_request_worker_spec.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/workers/deployments/link_merge_request_worker_spec.rb b/spec/workers/deployments/link_merge_request_worker_spec.rb new file mode 100644 index 00000000000..a55dd897bc7 --- /dev/null +++ b/spec/workers/deployments/link_merge_request_worker_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Deployments::LinkMergeRequestWorker do + subject(:worker) { described_class.new } + + describe '#perform' do + it 'links merge requests to the deployment' do + deployment = create(:deployment) + service = instance_double(Deployments::LinkMergeRequestsService) + + expect(Deployments::LinkMergeRequestsService) + .to receive(:new) + .with(deployment) + .and_return(service) + + expect(service).to receive(:execute) + + worker.perform(deployment.id) + end + + it 'does not link merge requests when the deployment is not found' do + expect(Deployments::LinkMergeRequestsService).not_to receive(:new) + + worker.perform(non_existing_record_id) + end + end + + context 'idempotent' do + include_examples 'an idempotent worker' do + let(:project) { create(:project, :repository) } + let(:environment) { create(:environment, project: project) } + let(:deployment) { create(:deployment, :success, project: project, environment: environment) } + let(:job_args) { deployment.id } + + it 'links merge requests to deployment' do + mr1 = create( + :merge_request, + :merged, + source_project: project, + target_project: project, + source_branch: 'source1', + target_branch: deployment.ref + ) + + mr2 = create( + :merge_request, + :merged, + source_project: project, + target_project: project, + source_branch: 'source2', + target_branch: deployment.ref + ) + + mr3 = create( + :merge_request, + :merged, + source_project: project, + target_project: project, + target_branch: 'foo' + ) + + subject + + expect(deployment.merge_requests).to include(mr1, mr2) + expect(deployment.merge_requests).not_to include(mr3) + end + end + end +end |