diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/services/ci/create_pipeline_service_spec.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/services/ci/create_pipeline_service_spec.rb')
-rw-r--r-- | spec/services/ci/create_pipeline_service_spec.rb | 307 |
1 files changed, 176 insertions, 131 deletions
diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 56bfeda3bff..2fdb0ed3c0d 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -19,7 +19,6 @@ RSpec.describe Ci::CreatePipelineService do def execute_service( source: :push, after: project.commit.id, - message: 'Message', ref: ref_name, trigger_request: nil, variables_attributes: nil, @@ -32,7 +31,6 @@ RSpec.describe Ci::CreatePipelineService do params = { ref: ref, before: '00000000', after: after, - commits: [{ message: message }], variables_attributes: variables_attributes, push_options: push_options, source_sha: source_sha, @@ -49,12 +47,16 @@ RSpec.describe Ci::CreatePipelineService do # rubocop:enable Metrics/ParameterLists context 'valid params' do - let(:pipeline) { execute_service } + let(:pipeline) { execute_service.payload } let(:pipeline_on_previous_commit) do execute_service( after: previous_commit_sha_from_ref('master') - ) + ).payload + end + + it 'responds with success' do + expect(execute_service).to be_success end it 'creates a pipeline' do @@ -128,7 +130,7 @@ RSpec.describe Ci::CreatePipelineService do merge_request_1 merge_request_2 - head_pipeline = execute_service(ref: 'feature', after: nil) + head_pipeline = execute_service(ref: 'feature', after: nil).payload expect(merge_request_1.reload.head_pipeline).to eq(head_pipeline) expect(merge_request_2.reload.head_pipeline).to eq(head_pipeline) @@ -157,7 +159,7 @@ RSpec.describe Ci::CreatePipelineService do target_branch: "branch_1", source_project: project) - head_pipeline = execute_service + head_pipeline = execute_service.payload expect(merge_request.reload.head_pipeline).not_to eq(head_pipeline) end @@ -178,7 +180,7 @@ RSpec.describe Ci::CreatePipelineService do source_project: project, target_project: target_project) - head_pipeline = execute_service(ref: 'feature', after: nil) + head_pipeline = execute_service(ref: 'feature', after: nil).payload expect(merge_request.reload.head_pipeline).to eq(head_pipeline) end @@ -209,7 +211,7 @@ RSpec.describe Ci::CreatePipelineService do target_branch: 'feature', source_project: project) - head_pipeline = execute_service + head_pipeline = execute_service.payload expect(head_pipeline).to be_persisted expect(head_pipeline.yaml_errors).to be_present @@ -230,7 +232,7 @@ RSpec.describe Ci::CreatePipelineService do target_branch: 'feature', source_project: project) - head_pipeline = execute_service + head_pipeline = execute_service.payload expect(head_pipeline).to be_skipped expect(head_pipeline).to be_persisted @@ -260,7 +262,7 @@ RSpec.describe Ci::CreatePipelineService do it 'cancels running outdated pipelines', :sidekiq_inline do pipeline_on_previous_commit.reload.run - head_pipeline = execute_service + head_pipeline = execute_service.payload expect(pipeline_on_previous_commit.reload).to have_attributes(status: 'canceled', auto_canceled_by_id: head_pipeline.id) end @@ -276,7 +278,8 @@ RSpec.describe Ci::CreatePipelineService do new_pipeline = execute_service( ref: 'refs/heads/feature', after: previous_commit_sha_from_ref('feature') - ) + ).payload + pipeline expect(new_pipeline.reload).to have_attributes(status: 'created', auto_canceled_by_id: nil) @@ -290,7 +293,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'is cancelable' do - pipeline = execute_service + pipeline = execute_service.payload expect(pipeline.builds.find_by(name: 'rspec').interruptible).to be_nil end @@ -303,7 +306,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'is cancelable' do - pipeline = execute_service + pipeline = execute_service.payload expect(pipeline.builds.find_by(name: 'rspec').interruptible).to be_truthy end @@ -316,7 +319,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'is not cancelable' do - pipeline = execute_service + pipeline = execute_service.payload expect(pipeline.builds.find_by(name: 'rspec').interruptible).to be_falsy end @@ -476,21 +479,25 @@ RSpec.describe Ci::CreatePipelineService do context "skip tag if there is no build for it" do it "creates commit if there is appropriate job" do - expect(execute_service).to be_persisted + expect(execute_service.payload).to be_persisted end it "creates commit if there is no appropriate job but deploy job has right ref setting" do config = YAML.dump({ deploy: { script: "ls", only: ["master"] } }) stub_ci_pipeline_yaml_file(config) - expect(execute_service).to be_persisted + expect(execute_service.payload).to be_persisted end end - it 'skips creating pipeline for refs without .gitlab-ci.yml' do + it 'skips creating pipeline for refs without .gitlab-ci.yml', :aggregate_failures do stub_ci_pipeline_yaml_file(nil) - expect(execute_service).not_to be_persisted + response = execute_service + + expect(response).to be_error + expect(response.message).to eq('Missing CI config file') + expect(response.payload).not_to be_persisted expect(Ci::Pipeline.count).to eq(0) expect(Namespaces::OnboardingPipelineCreatedWorker).not_to receive(:perform_async) end @@ -499,7 +506,7 @@ RSpec.describe Ci::CreatePipelineService do it 'creates failed pipeline' do stub_ci_pipeline_yaml_file(ci_yaml) - pipeline = execute_service(message: message) + pipeline = execute_service.payload expect(pipeline).to be_persisted expect(pipeline.builds.any?).to be false @@ -516,7 +523,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'pull it from the repository' do - pipeline = execute_service + pipeline = execute_service.payload expect(pipeline).to be_repository_source expect(pipeline.builds.map(&:name)).to eq ['rspec'] end @@ -530,7 +537,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'pull it from Auto-DevOps' do - pipeline = execute_service + pipeline = execute_service.payload expect(pipeline).to be_auto_devops_source expect(pipeline.builds.map(&:name)).to match_array(%w[brakeman-sast build code_quality eslint-sast secret_detection semgrep-sast test]) end @@ -541,11 +548,12 @@ RSpec.describe Ci::CreatePipelineService do stub_ci_pipeline_yaml_file(nil) end - it 'attaches errors to the pipeline' do - pipeline = execute_service + it 'responds with error message', :aggregate_failures do + response = execute_service - expect(pipeline.errors.full_messages).to eq ['Missing CI config file'] - expect(pipeline).not_to be_persisted + expect(response).to be_error + expect(response.message).to eq('Missing CI config file') + expect(response.payload).not_to be_persisted end end @@ -556,7 +564,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'saves error in pipeline' do - pipeline = execute_service + pipeline = execute_service.payload expect(pipeline.yaml_errors).to include('Undefined error') end @@ -648,7 +656,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'saves error in pipeline' do - pipeline = execute_service + pipeline = execute_service.payload expect(pipeline.yaml_errors).to include('Undefined error') end @@ -661,26 +669,18 @@ RSpec.describe Ci::CreatePipelineService do end context 'when commit contains a [ci skip] directive' do - let(:message) { "some message[ci skip]" } - - ci_messages = [ - "some message[ci skip]", - "some message[skip ci]", - "some message[CI SKIP]", - "some message[SKIP CI]", - "some message[ci_skip]", - "some message[skip_ci]", - "some message[ci-skip]", - "some message[skip-ci]" - ] + shared_examples 'creating a pipeline' do + it 'does not skip pipeline creation' do + pipeline = execute_service.payload - before do - allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { message } + expect(pipeline).to be_persisted + expect(pipeline.builds.first.name).to eq("rspec") + end end - ci_messages.each do |ci_message| - it "skips builds creation if the commit message is #{ci_message}" do - pipeline = execute_service(message: ci_message) + shared_examples 'skipping a pipeline' do + it 'skips pipeline creation' do + pipeline = execute_service.payload expect(pipeline).to be_persisted expect(pipeline.builds.any?).to be false @@ -688,14 +688,26 @@ RSpec.describe Ci::CreatePipelineService do end end - shared_examples 'creating a pipeline' do - it 'does not skip pipeline creation' do - allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { commit_message } + before do + allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { commit_message } + end + + skip_commit_messages = [ + "some message[ci skip]", + "some message[skip ci]", + "some message[CI SKIP]", + "some message[SKIP CI]", + "some message[ci_skip]", + "some message[skip_ci]", + "some message[ci-skip]", + "some message[skip-ci]" + ] - pipeline = execute_service(message: commit_message) + skip_commit_messages.each do |skip_commit_message| + context "when the commit message is #{skip_commit_message}" do + let(:commit_message) { skip_commit_message } - expect(pipeline).to be_persisted - expect(pipeline.builds.first.name).to eq("rspec") + it_behaves_like 'skipping a pipeline' end end @@ -712,9 +724,14 @@ RSpec.describe Ci::CreatePipelineService do end context 'when there is [ci skip] tag in commit message and yaml is invalid' do + let(:commit_message) { 'some message [ci skip]' } let(:ci_yaml) { 'invalid: file: fiile' } - it_behaves_like 'a failed pipeline' + before do + stub_ci_pipeline_yaml_file(ci_yaml) + end + + it_behaves_like 'skipping a pipeline' end end @@ -724,7 +741,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'creates a pipline in the skipped state' do - pipeline = execute_service(push_options: push_options) + pipeline = execute_service(push_options: push_options).payload # TODO: DRY these up with "skips builds creation if the commit message" expect(pipeline).to be_persisted @@ -739,10 +756,12 @@ RSpec.describe Ci::CreatePipelineService do stub_ci_pipeline_yaml_file(config) end - it 'does not create a new pipeline' do + it 'does not create a new pipeline', :aggregate_failures do result = execute_service - expect(result).not_to be_persisted + expect(result).to be_error + expect(result.message).to eq('No stages / jobs for this pipeline.') + expect(result.payload).not_to be_persisted expect(Ci::Build.all).to be_empty expect(Ci::Pipeline.count).to eq(0) end @@ -757,10 +776,11 @@ RSpec.describe Ci::CreatePipelineService do .and_call_original end - it 'rewinds iid' do + it 'rewinds iid', :aggregate_failures do result = execute_service - expect(result).not_to be_persisted + expect(result).to be_error + expect(result.payload).not_to be_persisted expect(internal_id.last_value).to eq(0) end end @@ -773,7 +793,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'does not create a new pipeline', :sidekiq_inline do - result = execute_service + result = execute_service.payload expect(result).to be_persisted expect(result.manual_actions).not_to be_empty @@ -793,7 +813,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'creates the environment with tags' do - result = execute_service + result = execute_service.payload expect(result).to be_persisted expect(Environment.find_by(name: "review/master")).to be_present @@ -815,7 +835,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'creates the environment with auto stop in' do - result = execute_service + result = execute_service.payload expect(result).to be_persisted expect(result.builds.first.options[:environment][:auto_stop_in]).to eq('1 day') @@ -835,7 +855,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'skipps persisted variables in environment name' do - result = execute_service + result = execute_service.payload expect(result).to be_persisted expect(Environment.find_by(name: "review/id1/id2")).to be_present @@ -860,7 +880,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'stores the requested namespace' do - result = execute_service + result = execute_service.payload build = result.builds.first expect(result).to be_persisted @@ -876,7 +896,7 @@ RSpec.describe Ci::CreatePipelineService do it 'does not create an environment' do expect do - result = execute_service + result = execute_service.payload expect(result).to be_persisted end.not_to change { Environment.count } @@ -896,7 +916,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'creates a pipeline with the environment' do - result = execute_service + result = execute_service.payload expect(result).to be_persisted expect(Environment.find_by(name: 'production')).to be_present @@ -906,7 +926,7 @@ RSpec.describe Ci::CreatePipelineService do end context 'when builds with auto-retries are configured' do - let(:pipeline) { execute_service } + let(:pipeline) { execute_service.payload } let(:rspec_job) { pipeline.builds.find_by(name: 'rspec') } before do @@ -946,7 +966,7 @@ RSpec.describe Ci::CreatePipelineService do let(:resource_group_key) { 'iOS' } it 'persists the association correctly' do - result = execute_service + result = execute_service.payload deploy_job = result.builds.find_by_name!(:test) resource_group = project.resource_groups.find_by_key!(resource_group_key) @@ -962,7 +982,7 @@ RSpec.describe Ci::CreatePipelineService do let(:resource_group_key) { '$CI_COMMIT_REF_NAME-$CI_JOB_NAME' } it 'interpolates the variables into the key correctly' do - result = execute_service + result = execute_service.payload expect(result).to be_persisted expect(project.resource_groups.exists?(key: 'master-test')).to eq(true) @@ -979,7 +999,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'correctly creates builds with custom timeout value configured' do - pipeline = execute_service + pipeline = execute_service.payload expect(pipeline).to be_persisted expect(pipeline.builds.find_by(name: 'rspec').options[:job_timeout]).to eq 123 @@ -994,7 +1014,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'is valid config' do - pipeline = execute_service + pipeline = execute_service.payload build = pipeline.builds.first expect(pipeline).to be_kind_of(Ci::Pipeline) expect(pipeline).to be_valid @@ -1059,14 +1079,14 @@ RSpec.describe Ci::CreatePipelineService do project.add_developer(user) end - it 'does not create a pipeline' do - expect(execute_service).not_to be_persisted + it 'does not create a pipeline', :aggregate_failures do + expect(execute_service.payload).not_to be_persisted expect(Ci::Pipeline.count).to eq(0) end end context 'when user is maintainer' do - let(:pipeline) { execute_service } + let(:pipeline) { execute_service.payload } before do project.add_maintainer(user) @@ -1083,9 +1103,11 @@ RSpec.describe Ci::CreatePipelineService do let(:user) {} let(:trigger_request) { create(:ci_trigger_request) } - it 'does not create a pipeline' do - expect(execute_service(trigger_request: trigger_request)) - .not_to be_persisted + it 'does not create a pipeline', :aggregate_failures do + response = execute_service(trigger_request: trigger_request) + + expect(response).to be_error + expect(response.payload).not_to be_persisted expect(Ci::Pipeline.count).to eq(0) end end @@ -1099,9 +1121,11 @@ RSpec.describe Ci::CreatePipelineService do project.add_developer(user) end - it 'does not create a pipeline' do - expect(execute_service(trigger_request: trigger_request)) - .not_to be_persisted + it 'does not create a pipeline', :aggregate_failures do + response = execute_service(trigger_request: trigger_request) + + expect(response).to be_error + expect(response.payload).not_to be_persisted expect(Ci::Pipeline.count).to eq(0) end end @@ -1116,7 +1140,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'creates a pipeline' do - expect(execute_service(trigger_request: trigger_request)) + expect(execute_service(trigger_request: trigger_request).payload) .to be_persisted expect(Ci::Pipeline.count).to eq(1) end @@ -1150,7 +1174,7 @@ RSpec.describe Ci::CreatePipelineService do end it 'creates a tagged pipeline' do - pipeline = execute_service(ref: 'v1.0.0') + pipeline = execute_service(ref: 'v1.0.0').payload expect(pipeline.tag?).to be true end @@ -1161,7 +1185,7 @@ RSpec.describe Ci::CreatePipelineService do let(:ref_name) { 'refs/heads/nonexistant-branch' } - let(:pipeline) { execute_service } + let(:pipeline) { execute_service.payload } it 'does not create the pipeline' do expect(pipeline).not_to be_created_successfully @@ -1185,7 +1209,7 @@ RSpec.describe Ci::CreatePipelineService do # v1.1.0 is on the test repo as branch and tag let(:ref_name) { 'refs/heads/v1.1.0' } - let(:pipeline) { execute_service } + let(:pipeline) { execute_service.payload } it 'creates the pipeline for the branch' do expect(pipeline).to be_created_successfully @@ -1200,7 +1224,7 @@ RSpec.describe Ci::CreatePipelineService do # v1.1.0 is on the test repo as branch and tag let(:ref_name) { 'refs/tags/v1.1.0' } - let(:pipeline) { execute_service } + let(:pipeline) { execute_service.payload } it 'creates the pipeline for the tag' do expect(pipeline).to be_created_successfully @@ -1215,7 +1239,7 @@ RSpec.describe Ci::CreatePipelineService do # v1.1.0 is on the test repo as branch and tag let(:ref_name) { 'v1.1.0' } - let(:pipeline) { execute_service } + let(:pipeline) { execute_service.payload } it 'does not create the pipeline' do expect(pipeline).not_to be_created_successfully @@ -1229,16 +1253,16 @@ RSpec.describe Ci::CreatePipelineService do { key: 'second', secret_value: 'second_world' }] end - subject { execute_service(variables_attributes: variables_attributes) } + subject(:pipeline) { execute_service(variables_attributes: variables_attributes).payload } it 'creates a pipeline with specified variables' do - expect(subject.variables.map { |var| var.slice(:key, :secret_value) }) + expect(pipeline.variables.map { |var| var.slice(:key, :secret_value) }) .to eq variables_attributes.map(&:with_indifferent_access) end end context 'when pipeline has a job with environment' do - let(:pipeline) { execute_service } + let(:pipeline) { execute_service.payload } before do stub_ci_pipeline_yaml_file(YAML.dump(config)) @@ -1286,7 +1310,7 @@ RSpec.describe Ci::CreatePipelineService do end describe 'Pipeline for external pull requests' do - let(:pipeline) do + let(:response) do execute_service(source: source, external_pull_request: pull_request, ref: ref_name, @@ -1294,6 +1318,8 @@ RSpec.describe Ci::CreatePipelineService do target_sha: target_sha) end + let(:pipeline) { response.payload } + before do stub_ci_pipeline_yaml_file(YAML.dump(config)) end @@ -1342,9 +1368,11 @@ RSpec.describe Ci::CreatePipelineService do context 'when ref is tag' do let(:ref_name) { 'refs/tags/v1.1.0' } - it 'does not create an extrnal pull request pipeline' do + it 'does not create an extrnal pull request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq('Tag is not included in the list and Failed to build the pipeline!') expect(pipeline).not_to be_persisted - expect(pipeline.errors[:tag]).to eq(["is not included in the list"]) + expect(pipeline.errors[:tag]).to eq(['is not included in the list']) end end @@ -1363,9 +1391,11 @@ RSpec.describe Ci::CreatePipelineService do } end - it 'does not create a detached merge request pipeline' do + it 'does not create a detached merge request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq('No stages / jobs for this pipeline.') expect(pipeline).not_to be_persisted - expect(pipeline.errors[:base]).to eq(["No stages / jobs for this pipeline."]) + expect(pipeline.errors[:base]).to eq(['No stages / jobs for this pipeline.']) end end end @@ -1373,7 +1403,9 @@ RSpec.describe Ci::CreatePipelineService do context 'when external pull request is not specified' do let(:pull_request) { nil } - it 'does not create an external pull request pipeline' do + it 'does not create an external pull request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq("External pull request can't be blank and Failed to build the pipeline!") expect(pipeline).not_to be_persisted expect(pipeline.errors[:external_pull_request]).to eq(["can't be blank"]) end @@ -1420,11 +1452,11 @@ RSpec.describe Ci::CreatePipelineService do context 'when external pull request is not specified' do let(:pull_request) { nil } - it 'does not create an external pull request pipeline' do + it 'does not create an external pull request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq("External pull request can't be blank and Failed to build the pipeline!") expect(pipeline).not_to be_persisted - - expect(pipeline.errors[:base]) - .to eq(['Failed to build the pipeline!']) + expect(pipeline.errors[:base]).to eq(['Failed to build the pipeline!']) end end end @@ -1432,7 +1464,7 @@ RSpec.describe Ci::CreatePipelineService do end describe 'Pipelines for merge requests' do - let(:pipeline) do + let(:response) do execute_service(source: source, merge_request: merge_request, ref: ref_name, @@ -1440,6 +1472,8 @@ RSpec.describe Ci::CreatePipelineService do target_sha: target_sha) end + let(:pipeline) { response.payload } + before do stub_ci_pipeline_yaml_file(YAML.dump(config)) end @@ -1522,9 +1556,11 @@ RSpec.describe Ci::CreatePipelineService do context 'when ref is tag' do let(:ref_name) { 'refs/tags/v1.1.0' } - it 'does not create a merge request pipeline' do + it 'does not create a merge request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq('Tag is not included in the list and Failed to build the pipeline!') expect(pipeline).not_to be_persisted - expect(pipeline.errors[:tag]).to eq(["is not included in the list"]) + expect(pipeline.errors[:tag]).to eq(['is not included in the list']) end end @@ -1564,9 +1600,10 @@ RSpec.describe Ci::CreatePipelineService do } end - it 'does not create a detached merge request pipeline' do + it 'does not create a detached merge request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq('No stages / jobs for this pipeline.') expect(pipeline).not_to be_persisted - expect(pipeline.errors[:base]).to eq(["No stages / jobs for this pipeline."]) end end end @@ -1599,11 +1636,10 @@ RSpec.describe Ci::CreatePipelineService do target_branch: 'master') end - it 'does not create a detached merge request pipeline' do + it 'does not create a detached merge request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq('No stages / jobs for this pipeline.') expect(pipeline).not_to be_persisted - - expect(pipeline.errors[:base]) - .to eq(['No stages / jobs for this pipeline.']) end end end @@ -1628,11 +1664,10 @@ RSpec.describe Ci::CreatePipelineService do target_branch: 'master') end - it 'does not create a detached merge request pipeline' do + it 'does not create a detached merge request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq('No stages / jobs for this pipeline.') expect(pipeline).not_to be_persisted - - expect(pipeline.errors[:base]) - .to eq(['No stages / jobs for this pipeline.']) end end end @@ -1659,11 +1694,10 @@ RSpec.describe Ci::CreatePipelineService do target_branch: 'master') end - it 'does not create a detached merge request pipeline' do + it 'does not create a detached merge request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq('No stages / jobs for this pipeline.') expect(pipeline).not_to be_persisted - - expect(pipeline.errors[:base]) - .to eq(['No stages / jobs for this pipeline.']) end end end @@ -1688,11 +1722,10 @@ RSpec.describe Ci::CreatePipelineService do target_branch: 'master') end - it 'does not create a detached merge request pipeline' do + it 'does not create a detached merge request pipeline', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq('No stages / jobs for this pipeline.') expect(pipeline).not_to be_persisted - - expect(pipeline.errors[:base]) - .to eq(['No stages / jobs for this pipeline.']) end end end @@ -1733,7 +1766,8 @@ RSpec.describe Ci::CreatePipelineService do end context 'when needs is used' do - let(:pipeline) { execute_service } + let(:response) { execute_service } + let(:pipeline) { response.payload } let(:config) do { @@ -1779,7 +1813,7 @@ RSpec.describe Ci::CreatePipelineService do let(:ref_name) { 'refs/heads/feature' } shared_examples 'has errors' do - it 'contains the expected errors' do + it 'contains the expected errors', :aggregate_failures do expect(pipeline.builds).to be_empty error_message = "'test_a' job needs 'build_a' job, but 'build_a' is not in any previous stage" @@ -1790,9 +1824,12 @@ RSpec.describe Ci::CreatePipelineService do end context 'when save_on_errors is enabled' do - let(:pipeline) { execute_service(save_on_errors: true) } + let(:response) { execute_service(save_on_errors: true) } + let(:pipeline) { response.payload } - it 'does create a pipeline as test_a depends on build_a' do + it 'does create a pipeline as test_a depends on build_a', :aggregate_failures do + expect(response).to be_error + expect(response.message).to eq("'test_a' job needs 'build_a' job, but 'build_a' is not in any previous stage") expect(pipeline).to be_persisted end @@ -1800,9 +1837,11 @@ RSpec.describe Ci::CreatePipelineService do end context 'when save_on_errors is disabled' do - let(:pipeline) { execute_service(save_on_errors: false) } + let(:response) { execute_service(save_on_errors: false) } + let(:pipeline) { response.payload } - it 'does not create a pipeline as test_a depends on build_a' do + it 'does not create a pipeline as test_a depends on build_a', :aggregate_failures do + expect(response).to be_error expect(pipeline).not_to be_persisted end @@ -1822,7 +1861,8 @@ RSpec.describe Ci::CreatePipelineService do context 'when rules are used' do let(:ref_name) { 'refs/heads/master' } - let(:pipeline) { execute_service } + let(:response) { execute_service } + let(:pipeline) { response.payload } let(:build_names) { pipeline.builds.pluck(:name) } let(:regular_job) { find_job('regular-job') } let(:rules_job) { find_job('rules-job') } @@ -2379,8 +2419,9 @@ RSpec.describe Ci::CreatePipelineService do end context 'when inside freeze period' do - it 'does not create the pipeline' do + it 'does not create the pipeline', :aggregate_failures do Timecop.freeze(2020, 4, 10, 23, 1) do + expect(response).to be_error expect(pipeline).not_to be_persisted end end @@ -2410,7 +2451,8 @@ RSpec.describe Ci::CreatePipelineService do context 'with no matches' do let(:ref_name) { 'refs/heads/feature' } - it 'does not create a pipeline' do + it 'does not create a pipeline', :aggregate_failures do + expect(response).to be_error expect(pipeline).not_to be_persisted end end @@ -2418,7 +2460,7 @@ RSpec.describe Ci::CreatePipelineService do context 'with workflow rules with pipeline variables' do let(:pipeline) do - execute_service(variables_attributes: variables_attributes) + execute_service(variables_attributes: variables_attributes).payload end let(:config) do @@ -2446,7 +2488,8 @@ RSpec.describe Ci::CreatePipelineService do context 'with no matches' do let(:variables_attributes) { {} } - it 'does not create a pipeline' do + it 'does not create a pipeline', :aggregate_failures do + expect(response).to be_error expect(pipeline).not_to be_persisted end end @@ -2456,7 +2499,7 @@ RSpec.describe Ci::CreatePipelineService do let(:pipeline) do execute_service do |pipeline| pipeline.variables.build(variables) - end + end.payload end let(:config) do @@ -2514,7 +2557,8 @@ RSpec.describe Ci::CreatePipelineService do context 'with no matches' do let(:variables) { {} } - it 'does not create a pipeline' do + it 'does not create a pipeline', :aggregate_failures do + expect(response).to be_error expect(pipeline).not_to be_persisted end @@ -2542,7 +2586,8 @@ RSpec.describe Ci::CreatePipelineService do EOY end - it 'does not create a pipeline' do + it 'does not create a pipeline', :aggregate_failures do + expect(response).to be_error expect(pipeline).not_to be_persisted end end |