Fix deserializing yaml variables in imported projects
This commit is contained in:
parent
59eb9938f6
commit
f84d3dc0ee
|
@ -13,8 +13,9 @@ module Gitlab
|
||||||
object = YAML.safe_load(string, [Symbol])
|
object = YAML.safe_load(string, [Symbol])
|
||||||
|
|
||||||
object.map do |variable|
|
object.map do |variable|
|
||||||
variable[:key] = variable[:key].to_s
|
variable.symbolize_keys.tap do |variable|
|
||||||
variable
|
variable[:key] = variable[:key].to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require 'fast_spec_helper'
|
||||||
|
|
||||||
describe Gitlab::Serializer::Ci::Variables do
|
describe Gitlab::Serializer::Ci::Variables do
|
||||||
subject do
|
subject do
|
||||||
|
@ -6,11 +6,11 @@ describe Gitlab::Serializer::Ci::Variables do
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:object) do
|
let(:object) do
|
||||||
[{ key: :key, value: 'value', public: true },
|
[{ 'key' => :key, 'value' => 'value', 'public' => true },
|
||||||
{ key: 'wee', value: 1, public: false }]
|
{ key: 'wee', value: 1, public: false }]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'converts keys into strings' do
|
it 'converts keys into strings and symbolizes hash' do
|
||||||
is_expected.to eq([
|
is_expected.to eq([
|
||||||
{ key: 'key', value: 'value', public: true },
|
{ key: 'key', value: 'value', public: true },
|
||||||
{ key: 'wee', value: 1, public: false }
|
{ key: 'wee', value: 1, public: false }
|
||||||
|
|
|
@ -2269,6 +2269,34 @@ describe Ci::Build do
|
||||||
end
|
end
|
||||||
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
|
describe 'state transition: any => [:pending]' do
|
||||||
let(:build) { create(:ci_build, :created) }
|
let(:build) { create(:ci_build, :created) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue