Fix deserializing yaml variables in imported projects

This commit is contained in:
Grzegorz Bizon 2018-07-19 14:00:35 +02:00
parent 59eb9938f6
commit f84d3dc0ee
3 changed files with 34 additions and 5 deletions

View File

@ -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

View File

@ -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 }

View File

@ -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) }