diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-05-27 15:26:39 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-06-06 06:35:43 +0300 |
commit | 31afb0e8addf73f6cbcf4213ad2c386488c95715 (patch) | |
tree | 7aa22bfc5ba270e586b46ea9a2763dacf23d2df4 /spec/services/merge_requests/create_pipeline_service_spec.rb | |
parent | 1bec362138bfcf6343a9cbc951ef5c8c07d2baaa (diff) |
Introduce service for merge request pipeline creation
We don't have a way to create MR pipeline today, this is one
of the headaches for users.
This change is a preliminary work for the capability.
Diffstat (limited to 'spec/services/merge_requests/create_pipeline_service_spec.rb')
-rw-r--r-- | spec/services/merge_requests/create_pipeline_service_spec.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/services/merge_requests/create_pipeline_service_spec.rb b/spec/services/merge_requests/create_pipeline_service_spec.rb new file mode 100644 index 00000000000..9479439bde8 --- /dev/null +++ b/spec/services/merge_requests/create_pipeline_service_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe MergeRequests::CreatePipelineService do + set(:project) { create(:project, :repository) } + set(:user) { create(:user) } + let(:service) { described_class.new(project, user, params) } + let(:params) { {} } + + before do + project.add_developer(user) + end + + describe '#execute' do + subject { service.execute(merge_request) } + + before do + stub_ci_pipeline_yaml_file(YAML.dump(config)) + end + + let(:config) do + { rspec: { script: 'echo', only: ['merge_requests'] } } + end + + let(:merge_request) do + create(:merge_request, + source_branch: 'feature', + source_project: project, + target_branch: 'master', + target_project: project) + end + + it 'creates a detached merge request pipeline' do + expect { subject }.to change { Ci::Pipeline.count }.by(1) + + expect(subject).to be_persisted + expect(subject).to be_detached_merge_request_pipeline + end + + context 'when service is called multiple times' do + it 'creates a pipeline once' do + expect do + service.execute(merge_request) + service.execute(merge_request) + end.to change { Ci::Pipeline.count }.by(1) + end + + context 'when allow_duplicate option is true' do + let(:params) { { allow_duplicate: true } } + + it 'creates pipelines multiple times' do + expect do + service.execute(merge_request) + service.execute(merge_request) + end.to change { Ci::Pipeline.count }.by(2) + end + end + end + + context 'when .gitlab-ci.yml does not have only: [merge_requests] keyword' do + let(:config) do + { rspec: { script: 'echo' } } + end + + it 'does not create a pipeline' do + expect { subject }.not_to change { Ci::Pipeline.count } + end + end + end +end |