summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-03-27 14:34:55 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-03-27 14:34:55 +0200
commitb1ce3ba142d3b735eded44bb5490984042c9d2e1 (patch)
treef5813f9af1d911dae850b229f5a6dcf9ad7a2cc7
parenta60ccef9fec1d798dd0178d10b6a6a109612c17d (diff)
downloadgitlab-ce-b1ce3ba142d3b735eded44bb5490984042c9d2e1.tar.gz
Improve specs for predefined build variables
-rw-r--r--spec/lib/gitlab/ci/build/policy/variables_spec.rb6
-rw-r--r--spec/models/ci/build_spec.rb26
2 files changed, 22 insertions, 10 deletions
diff --git a/spec/lib/gitlab/ci/build/policy/variables_spec.rb b/spec/lib/gitlab/ci/build/policy/variables_spec.rb
index a66a9144a16..fd259560a6d 100644
--- a/spec/lib/gitlab/ci/build/policy/variables_spec.rb
+++ b/spec/lib/gitlab/ci/build/policy/variables_spec.rb
@@ -49,11 +49,9 @@ describe Gitlab::Ci::Build::Policy::Variables do
end
it 'allows to evaluate regular secret variables' do
- secret = create(:ci_variable, project: project,
- key: 'SECRET',
- value: 'secret value')
+ create(:ci_variable, project: project, key: 'SECRET', value: 'my secret')
- policy = described_class.new(["$SECRET == 'secret value'"])
+ policy = described_class.new(["$SECRET == 'my secret'"])
expect(policy).to be_satisfied_by(pipeline, seed)
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 0f62ff4ccae..48eeca53f46 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -2054,14 +2054,28 @@ describe Ci::Build do
end
describe '#variables_hash' do
- before do
- project.variables.create!(key: 'MY_VAR', value: 'my value 1')
- pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2')
+ context 'when overriding secret variables' do
+ before do
+ project.variables.create!(key: 'MY_VAR', value: 'my value 1')
+ pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2')
+ end
+
+ it 'returns a regular hash created using valid ordering' do
+ expect(build.variables_hash).to include('MY_VAR': 'my value 2')
+ expect(build.variables_hash).not_to include('MY_VAR': 'my value 1')
+ end
end
- it 'returns a regular hash created in valid order' do
- expect(build.variables_hash).to include('MY_VAR': 'my value 2')
- expect(build.variables_hash).not_to include('MY_VAR': 'my value 1')
+ context 'when overriding user-provided variables' do
+ before do
+ pipeline.variables.build(key: 'MY_VAR', value: 'pipeline value')
+ build.yaml_variables = [{ key: 'MY_VAR', value: 'myvar', public: true }]
+ end
+
+ it 'returns a hash including variable with higher precedence' do
+ expect(build.variables_hash).to include('MY_VAR': 'pipeline value')
+ expect(build.variables_hash).not_to include('MY_VAR': 'myvar')
+ end
end
end