Commit 13bf7094 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix/gb/fix-variables-collection-item-file' into 'master'

Fix file-specific variables collection item option

Closes gitlab-ee#5444

See merge request gitlab-org/gitlab-ce!18307
parents 7e3bb679 07c781dc
...@@ -3,12 +3,9 @@ module Gitlab ...@@ -3,12 +3,9 @@ module Gitlab
module Variables module Variables
class Collection class Collection
class Item class Item
def initialize(**options) def initialize(key:, value:, public: true, file: false)
@variable = { @variable = {
key: options.fetch(:key), key: key, value: value, public: public, file: file
value: options.fetch(:value),
public: options.fetch(:public, true),
file: options.fetch(:files, false)
} }
end end
......
...@@ -5,6 +5,18 @@ describe Gitlab::Ci::Variables::Collection::Item do ...@@ -5,6 +5,18 @@ describe Gitlab::Ci::Variables::Collection::Item do
{ key: 'VAR', value: 'something', public: true } { key: 'VAR', value: 'something', public: true }
end end
describe '.new' do
it 'raises error if unknown key i specified' do
expect { described_class.new(key: 'VAR', value: 'abc', files: true) }
.to raise_error ArgumentError, 'unknown keyword: files'
end
it 'raises error when required keywords are not specified' do
expect { described_class.new(key: 'VAR') }
.to raise_error ArgumentError, 'missing keyword: value'
end
end
describe '.fabricate' do describe '.fabricate' do
it 'supports using a hash' do it 'supports using a hash' do
resource = described_class.fabricate(variable) resource = described_class.fabricate(variable)
...@@ -47,12 +59,25 @@ describe Gitlab::Ci::Variables::Collection::Item do ...@@ -47,12 +59,25 @@ describe Gitlab::Ci::Variables::Collection::Item do
end end
describe '#to_runner_variable' do describe '#to_runner_variable' do
it 'returns a runner-compatible hash representation' do context 'when variable is not a file-related' do
runner_variable = described_class it 'returns a runner-compatible hash representation' do
.new(**variable) runner_variable = described_class
.to_runner_variable .new(**variable)
.to_runner_variable
expect(runner_variable).to eq variable
end
end
context 'when variable is file-related' do
it 'appends file description component' do
runner_variable = described_class
.new(key: 'VAR', value: 'value', file: true)
.to_runner_variable
expect(runner_variable).to eq variable expect(runner_variable)
.to eq(key: 'VAR', value: 'value', public: true, file: true)
end
end end
end end
end end
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