summaryrefslogtreecommitdiff
path: root/spec/services/ci/create_pipeline_service/needs_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/ci/create_pipeline_service/needs_spec.rb')
-rw-r--r--spec/services/ci/create_pipeline_service/needs_spec.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/services/ci/create_pipeline_service/needs_spec.rb b/spec/services/ci/create_pipeline_service/needs_spec.rb
index 512091035a2..a6b0a9662c9 100644
--- a/spec/services/ci/create_pipeline_service/needs_spec.rb
+++ b/spec/services/ci/create_pipeline_service/needs_spec.rb
@@ -238,5 +238,51 @@ RSpec.describe Ci::CreatePipelineService do
.to eq('jobs:invalid_dag_job:needs config can not be an empty hash')
end
end
+
+ context 'when the needed job has rules' do
+ let(:config) do
+ <<~YAML
+ build:
+ stage: build
+ script: exit 0
+ rules:
+ - if: $CI_COMMIT_REF_NAME == "invalid"
+
+ test:
+ stage: test
+ script: exit 0
+ needs: [build]
+ YAML
+ end
+
+ it 'returns error' do
+ expect(pipeline.yaml_errors)
+ .to eq("'test' job needs 'build' job, but it was not added to the pipeline")
+ end
+
+ context 'when need is optional' do
+ let(:config) do
+ <<~YAML
+ build:
+ stage: build
+ script: exit 0
+ rules:
+ - if: $CI_COMMIT_REF_NAME == "invalid"
+
+ test:
+ stage: test
+ script: exit 0
+ needs:
+ - job: build
+ optional: true
+ YAML
+ end
+
+ it 'creates the pipeline without an error' do
+ expect(pipeline).to be_persisted
+ expect(pipeline.builds.pluck(:name)).to contain_exactly('test')
+ end
+ end
+ end
end
end