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

60 lines
1.4 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2019-02-15 15:39:39 +05:30
describe Gitlab::Config::Entry::Configurable do
2018-03-17 18:26:18 +05:30
let(:entry) do
2019-02-15 15:39:39 +05:30
Class.new(Gitlab::Config::Entry::Node) do
include Gitlab::Config::Entry::Configurable
2018-03-17 18:26:18 +05:30
end
2017-08-17 22:00:37 +05:30
end
2019-03-02 22:35:43 +05:30
before do
allow(entry).to receive(:default)
end
2017-08-17 22:00:37 +05:30
describe 'validations' do
2018-03-17 18:26:18 +05:30
context 'when entry is a hash' do
let(:instance) { entry.new(key: 'value') }
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
it 'correctly validates an instance' do
expect(instance).to be_valid
2017-08-17 22:00:37 +05:30
end
end
2018-03-17 18:26:18 +05:30
context 'when entry is not a hash' do
2017-08-17 22:00:37 +05:30
let(:instance) { entry.new('ls') }
2018-03-17 18:26:18 +05:30
it 'invalidates the instance' do
expect(instance).not_to be_valid
2017-08-17 22:00:37 +05:30
end
end
end
describe 'configured entries' do
2019-03-02 22:35:43 +05:30
let(:entry_class) { double('entry_class', default: nil) }
2017-08-17 22:00:37 +05:30
before do
2019-03-02 22:35:43 +05:30
entry.class_exec(entry_class) do |entry_class|
entry :object, entry_class, description: 'test object'
2017-08-17 22:00:37 +05:30
end
end
describe '.nodes' do
it 'has valid nodes' do
expect(entry.nodes).to include :object
end
it 'creates a node factory' do
expect(entry.nodes[:object])
2019-02-15 15:39:39 +05:30
.to be_an_instance_of Gitlab::Config::Entry::Factory
2017-08-17 22:00:37 +05:30
end
it 'returns a duplicated factory object' do
first_factory = entry.nodes[:object]
second_factory = entry.nodes[:object]
expect(first_factory).not_to be_equal(second_factory)
end
end
end
end