Welcome to mirror list, hosted at ThFree Co, Russian Federation.

settings_spec.rb « gitlab_settings « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 161c26dbb9f605018d2526808e0f32c0f786eef4 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe GitlabSettings::Settings, :aggregate_failures, feature_category: :shared do
  let(:config) do
    {
      section1: {
        config1: {
          value1: 1
        }
      }
    }
  end

  let(:source) { Tempfile.new('config.yaml') }

  before do
    File.write(source, config.to_yaml)
  end

  subject(:settings) { described_class.new(source.path, 'section1') }

  describe '#initialize' do
    it 'requires a source' do
      expect { described_class.new('', '') }
        .to raise_error(ArgumentError, 'config source is required')
    end

    it 'requires a section' do
      expect { described_class.new(source, '') }
        .to raise_error(ArgumentError, 'config section is required')
    end
  end

  describe '#reload!' do
    it 'reloads the config' do
      expect(settings.config1.value1).to eq(1)

      File.write(source, { section1: { config1: { value1: 2 } } }.to_yaml)

      # config doesn't change when source changes
      expect(settings.config1.value1).to eq(1)

      settings.reload!

      # config changes after reload! if source changed
      expect(settings.config1.value1).to eq(2)
    end
  end

  it 'loads the given section config' do
    expect(settings.config1.value1).to eq(1)
  end

  context 'on lazy loading' do
    it 'does not raise exception on initialization if source does not exists' do
      settings = nil

      expect { settings = described_class.new('/tmp/any/inexisting/file.yml', 'section1') }
        .not_to raise_error

      expect { settings['any key'] }
        .to raise_error(Errno::ENOENT)
    end
  end
end