diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-07-19 14:23:14 +0300 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-07-19 15:53:35 +0300 |
commit | 41fa516bb67e97e59ad8a38fe8296bbd3a091c82 (patch) | |
tree | 26b335bd7354af2e85f1a5f04c2f13da39dfb105 /spec | |
parent | 61e7453e0465ceb631d3e8445429cfed7c1449d3 (diff) |
Use value of `yaml_variables` and `when` from config_processor if undefined
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/builds.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/badge/build_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/build_spec.rb | 113 |
3 files changed, 107 insertions, 10 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index fb111889501..5e19e403c6b 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -3,6 +3,8 @@ include ActionDispatch::TestProcess FactoryGirl.define do factory :ci_build, class: Ci::Build do name 'test' + stage 'test' + stage_idx 0 ref 'master' tag false created_at 'Di 29. Okt 09:50:00 CET 2013' diff --git a/spec/lib/gitlab/badge/build_spec.rb b/spec/lib/gitlab/badge/build_spec.rb index 2034445a197..f3b522a02f5 100644 --- a/spec/lib/gitlab/badge/build_spec.rb +++ b/spec/lib/gitlab/badge/build_spec.rb @@ -113,7 +113,7 @@ describe Gitlab::Badge::Build do sha: sha, ref: branch) - create(:ci_build, pipeline: pipeline) + create(:ci_build, pipeline: pipeline, stage: 'notify') end def status_node(data, status) diff --git a/spec/models/build_spec.rb b/spec/models/build_spec.rb index 4846c87a100..7f301d7ef00 100644 --- a/spec/models/build_spec.rb +++ b/spec/models/build_spec.rb @@ -191,16 +191,16 @@ describe Ci::Build, models: true do end describe '#variables' do - context 'returns variables' do - subject { build.variables } + let(:predefined_variables) do + [ + { key: :CI_BUILD_NAME, value: 'test', public: true }, + { key: :CI_BUILD_STAGE, value: 'test', public: true }, + ] + end - let(:predefined_variables) do - [ - { key: :CI_BUILD_NAME, value: 'test', public: true }, - { key: :CI_BUILD_STAGE, value: 'stage', public: true }, - ] - end + subject { build.variables } + context 'returns variables' do let(:yaml_variables) do [ { key: :DB_NAME, value: 'postgres', public: true } @@ -208,7 +208,7 @@ describe Ci::Build, models: true do end before do - build.update_attributes(stage: 'stage', yaml_variables: yaml_variables) + build.yaml_variables = yaml_variables end it { is_expected.to eq(predefined_variables + yaml_variables) } @@ -262,6 +262,54 @@ describe Ci::Build, models: true do end end end + + context 'when yaml_variables is undefined' do + before do + build.yaml_variables = nil + end + + context 'use from gitlab-ci.yml' do + before do + stub_ci_pipeline_yaml_file(config) + end + + context 'if config is not found' do + let(:config) { nil } + + it { is_expected.to eq(predefined_variables) } + end + + context 'if config does not have a questioned job' do + let(:config) do + YAML.dump({ + test_other: { + script: 'Hello World' + } + }) + end + + it { is_expected.to eq(predefined_variables) } + end + + context 'if config has variables' do + let(:config) do + YAML.dump({ + test: { + script: 'Hello World', + variables: { + KEY: 'value' + } + } + }) + end + let(:variables) do + [{ key: :KEY, value: 'value', public: true }] + end + + it { is_expected.to eq(predefined_variables + variables) } + end + end + end end describe '#has_tags?' do @@ -721,4 +769,51 @@ describe Ci::Build, models: true do end end end + + describe '#when' do + subject { build.when } + + context 'if is undefined' do + before do + build.when = nil + end + + context 'use from gitlab-ci.yml' do + before do + stub_ci_pipeline_yaml_file(config) + end + + context 'if config is not found' do + let(:config) { nil } + + it { is_expected.to eq('on_success') } + end + + context 'if config does not have a questioned job' do + let(:config) do + YAML.dump({ + test_other: { + script: 'Hello World' + } + }) + end + + it { is_expected.to eq('on_success') } + end + + context 'if config has when' do + let(:config) do + YAML.dump({ + test: { + script: 'Hello World', + when: 'always' + } + }) + end + + it { is_expected.to eq('always') } + end + end + end + end end |