summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-07-19 14:00:35 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-07-19 14:00:35 +0200
commitf84d3dc0ee9131ce1ab8716b833764d40c025eee (patch)
treefdadb4a4e066b48ec5eacaa6c84a24cf9c6eaa5c
parent59eb9938f66f8c24770b06f4d435e4df0acef252 (diff)
downloadgitlab-ce-f84d3dc0ee9131ce1ab8716b833764d40c025eee.tar.gz
Fix deserializing yaml variables in imported projects
-rw-r--r--lib/gitlab/serializer/ci/variables.rb5
-rw-r--r--spec/lib/gitlab/serializer/ci/variables_spec.rb6
-rw-r--r--spec/models/ci/build_spec.rb28
3 files changed, 34 insertions, 5 deletions
diff --git a/lib/gitlab/serializer/ci/variables.rb b/lib/gitlab/serializer/ci/variables.rb
index c059c454eac..292c8de6229 100644
--- a/lib/gitlab/serializer/ci/variables.rb
+++ b/lib/gitlab/serializer/ci/variables.rb
@@ -13,8 +13,9 @@ module Gitlab
object = YAML.safe_load(string, [Symbol])
object.map do |variable|
- variable[:key] = variable[:key].to_s
- variable
+ variable.symbolize_keys.tap do |variable|
+ variable[:key] = variable[:key].to_s
+ end
end
end
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..e7bca70b548 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) }