diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-07-20 16:01:25 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-07-20 16:01:25 +0300 |
commit | 470e526a2053a9a1b726380d851679d30fe46ea7 (patch) | |
tree | 70e71972873145323862891f65b4783080f75f7d /spec | |
parent | 3bd8a783e8e91cc863655a46c02f8c3391f2a1a4 (diff) | |
parent | 200766051ef241ee45a70d5db5c6b9eb8a1c72af (diff) |
Merge branch 'fix/gb/fix-deserializing-ci-yaml-variables' into 'master'
Fix deserializing YAML variables when a build has been imported
Closes #49406
See merge request gitlab-org/gitlab-ce!20713
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/ci/variables/collection/item_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/serializer/ci/variables_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 28 |
3 files changed, 39 insertions, 3 deletions
diff --git a/spec/lib/gitlab/ci/variables/collection/item_spec.rb b/spec/lib/gitlab/ci/variables/collection/item_spec.rb index adb3ff4321f..46874662edd 100644 --- a/spec/lib/gitlab/ci/variables/collection/item_spec.rb +++ b/spec/lib/gitlab/ci/variables/collection/item_spec.rb @@ -75,6 +75,14 @@ describe Gitlab::Ci::Variables::Collection::Item do expect(resource).to eq variable end + it 'supports using a hash with stringified values' do + variable = { 'key' => 'VARIABLE', 'value' => 'my value' } + + resource = described_class.fabricate(variable) + + expect(resource).to eq(key: 'VARIABLE', value: 'my value') + end + it 'supports using an active record resource' do variable = create(:ci_variable, key: 'CI_VAR', value: '123') resource = described_class.fabricate(variable) diff --git a/spec/lib/gitlab/serializer/ci/variables_spec.rb b/spec/lib/gitlab/serializer/ci/variables_spec.rb index c4b7fda5dbb..1d1fd5b0763 100644 --- a/spec/lib/gitlab/serializer/ci/variables_spec.rb +++ b/spec/lib/gitlab/serializer/ci/variables_spec.rb @@ -1,4 +1,4 @@ -require 'spec_helper' +require 'fast_spec_helper' describe Gitlab::Serializer::Ci::Variables do subject do @@ -6,11 +6,11 @@ describe Gitlab::Serializer::Ci::Variables do end let(:object) do - [{ key: :key, value: 'value', public: true }, + [{ 'key' => :key, 'value' => 'value', 'public' => true }, { key: 'wee', value: 1, public: false }] end - it 'converts keys into strings' do + it 'converts keys into strings and symbolizes hash' do is_expected.to eq([ { key: 'key', value: 'value', public: true }, { key: 'wee', value: 1, public: false } diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index ee923374480..67199eb6d26 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2269,6 +2269,34 @@ describe Ci::Build do end end + describe '#yaml_variables' do + before do + build.update_attribute(:yaml_variables, variables) + end + + context 'when serialized valu is a symbolized hash' do + let(:variables) do + [{ key: :VARIABLE, value: 'my value 1' }] + end + + it 'keeps symbolizes keys and stringifies variables names' do + expect(build.yaml_variables) + .to eq [{ key: 'VARIABLE', value: 'my value 1' }] + end + end + + context 'when serialized value is a hash with string keys' do + let(:variables) do + [{ 'key' => :VARIABLE, 'value' => 'my value 2' }] + end + + it 'symblizes variables hash' do + expect(build.yaml_variables) + .to eq [{ key: 'VARIABLE', value: 'my value 2' }] + end + end + end + describe 'state transition: any => [:pending]' do let(:build) { create(:ci_build, :created) } |