2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe Gitlab::Ci::Config::Entry::Key do
|
2016-08-24 12:49:21 +05:30
|
|
|
let(:entry) { described_class.new(config) }
|
|
|
|
|
|
|
|
describe 'validations' do
|
2019-12-26 22:10:19 +05:30
|
|
|
it_behaves_like 'key entry validations', 'simple key'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'when entry config value is correct' do
|
|
|
|
context 'when key is a hash' do
|
|
|
|
let(:config) { { files: ['test'], prefix: 'something' } }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
describe '#value' do
|
|
|
|
it 'returns key value' do
|
|
|
|
expect(entry.value).to match(config)
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
context 'when key is a symbol' do
|
|
|
|
let(:config) { :key }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
describe '#value' do
|
|
|
|
it 'returns key value' do
|
|
|
|
expect(entry.value).to eq(config.to_s)
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
describe '#valid?' do
|
|
|
|
it 'is valid' do
|
|
|
|
expect(entry).to be_valid
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when entry value is not correct' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:config) { ['incorrect'] }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
describe '#errors' do
|
|
|
|
it 'saves errors' do
|
2019-12-26 22:10:19 +05:30
|
|
|
expect(entry.errors.first)
|
|
|
|
.to match /should be a hash, a string or a symbol/
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '.default' do
|
|
|
|
it 'returns default key' do
|
|
|
|
expect(described_class.default).to eq 'default'
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|