Commit f84d3dc0 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix deserializing yaml variables in imported projects

parent 59eb9938
......@@ -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
......
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 }
......
......@@ -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) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment