Fix passing a hash with string keys when fabricating a variable

This commit is contained in:
Grzegorz Bizon 2018-07-19 14:13:49 +02:00
parent 3779d76d6e
commit fd4fd25d3c
2 changed files with 9 additions and 1 deletions

View File

@ -34,7 +34,7 @@ module Gitlab
def self.fabricate(resource)
case resource
when Hash
self.new(resource)
self.new(resource.symbolize_keys)
when ::HasVariable
self.new(resource.to_runner_variable)
when self

View File

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