2016-06-16 23:09:34 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
describe Gitlab::Config::Entry::Factory do
|
2016-06-16 23:09:34 +05:30
|
|
|
describe '#create!' do
|
2018-12-23 12:14:25 +05:30
|
|
|
class Script < Gitlab::Config::Entry::Node
|
|
|
|
include Gitlab::Config::Entry::Validatable
|
|
|
|
|
|
|
|
validations do
|
|
|
|
validates :config, array_of_strings: true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:entry) { Script }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:factory) { described_class.new(entry) }
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'when setting a concrete value' do
|
2016-06-16 23:09:34 +05:30
|
|
|
it 'creates entry with valid value' do
|
|
|
|
entry = factory
|
2017-08-17 22:00:37 +05:30
|
|
|
.value(%w(ls pwd))
|
2016-06-16 23:09:34 +05:30
|
|
|
.create!
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(entry.value).to eq %w(ls pwd)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when setting description' do
|
|
|
|
it 'creates entry with description' do
|
|
|
|
entry = factory
|
2017-08-17 22:00:37 +05:30
|
|
|
.value(%w(ls pwd))
|
2016-06-16 23:09:34 +05:30
|
|
|
.with(description: 'test description')
|
|
|
|
.create!
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(entry.value).to eq %w(ls pwd)
|
2016-06-16 23:09:34 +05:30
|
|
|
expect(entry.description).to eq 'test description'
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
context 'when setting key' do
|
|
|
|
it 'creates entry with custom key' do
|
|
|
|
entry = factory
|
2017-08-17 22:00:37 +05:30
|
|
|
.value(%w(ls pwd))
|
2016-09-13 17:45:13 +05:30
|
|
|
.with(key: 'test key')
|
2016-08-24 12:49:21 +05:30
|
|
|
.create!
|
|
|
|
|
|
|
|
expect(entry.key).to eq 'test key'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when setting a parent' do
|
2016-09-13 17:45:13 +05:30
|
|
|
let(:object) { Object.new }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
|
|
|
it 'creates entry with valid parent' do
|
|
|
|
entry = factory
|
2016-09-13 17:45:13 +05:30
|
|
|
.value('ls')
|
|
|
|
.with(parent: object)
|
2016-08-24 12:49:21 +05:30
|
|
|
.create!
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(entry.parent).to eq object
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
context 'when not setting a value' do
|
2016-06-16 23:09:34 +05:30
|
|
|
it 'raises error' do
|
|
|
|
expect { factory.create! }.to raise_error(
|
2018-12-23 12:14:25 +05:30
|
|
|
Gitlab::Config::Entry::Factory::InvalidFactory
|
2016-06-16 23:09:34 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
context 'when creating entry with nil value' do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'creates an unspecified entry' do
|
2016-06-16 23:09:34 +05:30
|
|
|
entry = factory
|
2016-09-13 17:45:13 +05:30
|
|
|
.value(nil)
|
2016-06-16 23:09:34 +05:30
|
|
|
.create!
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
expect(entry)
|
2017-08-17 22:00:37 +05:30
|
|
|
.not_to be_specified
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
context 'when passing metadata' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:entry) { spy('entry') }
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
it 'passes metadata as a parameter' do
|
|
|
|
factory
|
|
|
|
.value('some value')
|
|
|
|
.metadata(some: 'hash')
|
|
|
|
.create!
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(entry).to have_received(:new)
|
2016-09-13 17:45:13 +05:30
|
|
|
.with('some value', { some: 'hash' })
|
|
|
|
end
|
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|