Add more unit tests for variables collection class
This commit is contained in:
parent
e16fba6726
commit
d4319e1700
3 changed files with 33 additions and 1 deletions
|
@ -14,7 +14,6 @@ module Gitlab
|
|||
@variables.append(Collection::Item.fabricate(resource))
|
||||
end
|
||||
|
||||
# TODO, specs
|
||||
def concat(resources)
|
||||
resources.each { |variable| self.append(variable) }
|
||||
end
|
||||
|
|
|
@ -39,6 +39,14 @@ describe Gitlab::Ci::Variables::Collection::Item do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#[]' do
|
||||
it 'behaves like a hash accessor' do
|
||||
item = described_class.new(**variable)
|
||||
|
||||
expect(item[:key]).to eq 'VAR'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#to_hash' do
|
||||
it 'returns a hash representation of a collection item' do
|
||||
expect(described_class.new(**variable).to_hash).to eq variable
|
||||
|
|
|
@ -37,6 +37,31 @@ describe Gitlab::Ci::Variables::Collection do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#concat' do
|
||||
it 'appends all elements from an array' do
|
||||
collection = described_class.new([{ key: 'VAR_1', value: '1' }])
|
||||
variables = [{ key: 'VAR_2', value: '2' }, { key: 'VAR_3', value: '3' }]
|
||||
|
||||
collection.concat(variables)
|
||||
|
||||
expect(collection).to include(key: 'VAR_1', value: '1', public: true)
|
||||
expect(collection).to include(key: 'VAR_2', value: '2', public: true)
|
||||
expect(collection).to include(key: 'VAR_3', value: '3', public: true)
|
||||
end
|
||||
|
||||
it 'appends all elements from other collection' do
|
||||
collection = described_class.new([{ key: 'VAR_1', value: '1' }])
|
||||
additional = described_class.new([{ key: 'VAR_2', value: '2' },
|
||||
{ key: 'VAR_3', value: '3' }])
|
||||
|
||||
collection.concat(additional)
|
||||
|
||||
expect(collection).to include(key: 'VAR_1', value: '1', public: true)
|
||||
expect(collection).to include(key: 'VAR_2', value: '2', public: true)
|
||||
expect(collection).to include(key: 'VAR_3', value: '3', public: true)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#+' do
|
||||
it 'makes it possible to combine with an array' do
|
||||
collection = described_class.new([{ key: 'TEST', value: 1 }])
|
||||
|
|
Loading…
Reference in a new issue