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

88 lines
2.2 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.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
2021-02-22 17:27:13 +05:30
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|
2019-09-30 21:07:59 +05:30
entry :object, entry_class,
description: 'test object',
inherit: true,
2022-03-02 08:16:31 +05:30
reserved: true,
deprecation: { deprecated: '10.0', warning: '10.1', removed: '11.0', documentation: 'docs.gitlab.com' }
2017-08-17 22:00:37 +05:30
end
end
describe '.nodes' do
it 'has valid nodes' do
2019-09-30 21:07:59 +05:30
expect(entry.nodes).to include(:object)
2017-08-17 22:00:37 +05:30
end
it 'creates a node factory' do
2019-09-30 21:07:59 +05:30
factory = entry.nodes[:object]
expect(factory).to be_an_instance_of(Gitlab::Config::Entry::Factory)
2022-03-02 08:16:31 +05:30
expect(factory.deprecation).to eq(
deprecated: '10.0',
warning: '10.1',
removed: '11.0',
documentation: 'docs.gitlab.com'
)
2019-09-30 21:07:59 +05:30
expect(factory.description).to eq('test object')
expect(factory.inheritable?).to eq(true)
expect(factory.reserved?).to eq(true)
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
2019-09-30 21:07:59 +05:30
describe '.reserved_node_names' do
before do
entry.class_exec(entry_class) do |entry_class|
entry :not_reserved, entry_class
end
end
it 'returns all nodes with reserved: true' do
expect(entry.reserved_node_names).to contain_exactly(:object)
end
end
2017-08-17 22:00:37 +05:30
end
end