summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/config/entry/configurable_spec.rb
blob: 8c3a4490d08eb95110e0b5613aa0403a5587efde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Config::Entry::Configurable do
  let(:entry) do
    Class.new(Gitlab::Config::Entry::Node) do
      include Gitlab::Config::Entry::Configurable
    end
  end

  before do
    allow(entry).to receive(:default)
  end

  describe 'validations' do
    context 'when entry is a hash' do
      let(:instance) { entry.new(key: 'value') }

      it 'correctly validates an instance' do
        expect(instance).to be_valid
      end
    end

    context 'when entry is not a hash' do
      let(:instance) { entry.new('ls') }

      it 'invalidates the instance' do
        expect(instance).not_to be_valid
      end
    end
  end

  describe 'configured entries' do
    let(:entry_class) { double('entry_class', default: nil) }

    before do
      entry.class_exec(entry_class) do |entry_class|
        entry :object, entry_class,
          description: 'test object',
          inherit: true,
          reserved: true
      end
    end

    describe '.nodes' do
      it 'has valid nodes' do
        expect(entry.nodes).to include(:object)
      end

      it 'creates a node factory' do
        factory = entry.nodes[:object]

        expect(factory).to be_an_instance_of(Gitlab::Config::Entry::Factory)
        expect(factory.description).to eq('test object')
        expect(factory.inheritable?).to eq(true)
        expect(factory.reserved?).to eq(true)
      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

    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
  end
end