diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/services/ci/create_pipeline_service/merge_requests_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/services/ci/create_pipeline_service/merge_requests_spec.rb')
-rw-r--r-- | spec/services/ci/create_pipeline_service/merge_requests_spec.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/services/ci/create_pipeline_service/merge_requests_spec.rb b/spec/services/ci/create_pipeline_service/merge_requests_spec.rb new file mode 100644 index 00000000000..e5347faed6a --- /dev/null +++ b/spec/services/ci/create_pipeline_service/merge_requests_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::CreatePipelineService do + context 'merge requests handling' do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { project.owner } + + let(:ref) { 'refs/heads/feature' } + let(:source) { :push } + let(:service) { described_class.new(project, user, { ref: ref }) } + let(:pipeline) { service.execute(source) } + + before do + stub_ci_pipeline_yaml_file <<-EOS + workflow: + rules: + # do not create pipelines if merge requests are opened + - if: $CI_OPEN_MERGE_REQUESTS + when: never + + - if: $CI_COMMIT_BRANCH + + rspec: + script: echo Hello World + EOS + end + + context 'when pushing a change' do + context 'when a merge request already exists' do + let!(:merge_request) do + create(:merge_request, + source_project: project, + source_branch: 'feature', + target_project: project, + target_branch: 'master') + end + + it 'does not create a pipeline' do + expect(pipeline).not_to be_persisted + end + end + + context 'when no merge request exists' do + it 'does create a pipeline' do + expect(pipeline.errors).to be_empty + expect(pipeline).to be_persisted + end + end + end + end +end |