debian-mirror-gitlab/spec/lib/gitlab/config/entry/factory_spec.rb

115 lines
2.6 KiB
Ruby
Raw Normal View History

require 'spec_helper'
2019-02-15 15:39:39 +05:30
describe Gitlab::Config::Entry::Factory do
describe '#create!' do
2019-02-15 15:39:39 +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-09-13 17:45:13 +05:30
context 'when setting a concrete value' do
it 'creates entry with valid value' do
entry = factory
2017-08-17 22:00:37 +05:30
.value(%w(ls pwd))
.create!
2017-08-17 22:00:37 +05:30
expect(entry.value).to eq %w(ls pwd)
end
context 'when setting description' do
2019-09-30 21:07:59 +05:30
before do
factory
2017-08-17 22:00:37 +05:30
.value(%w(ls pwd))
.with(description: 'test description')
2019-09-30 21:07:59 +05:30
end
it 'configures description' do
expect(factory.description).to eq 'test description'
end
it 'creates entry with description' do
entry = factory.create!
2017-08-17 22:00:37 +05:30
expect(entry.value).to eq %w(ls pwd)
expect(entry.description).to eq 'test description'
end
end
2016-08-24 12:49:21 +05:30
2019-09-30 21:07:59 +05:30
context 'when setting inherit' do
before do
factory
.value(%w(ls pwd))
.with(inherit: true)
end
it 'makes object inheritable' do
expect(factory.inheritable?).to eq true
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
end
2016-09-13 17:45:13 +05:30
context 'when not setting a value' do
it 'raises error' do
expect { factory.create! }.to raise_error(
2019-02-15 15:39:39 +05:30
Gitlab::Config::Entry::Factory::InvalidFactory
)
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
entry = factory
2016-09-13 17:45:13 +05:30
.value(nil)
.create!
2016-09-29 09:46:39 +05:30
expect(entry)
2017-08-17 22:00:37 +05:30
.not_to be_specified
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
end
end