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: 55ceff4ce821c7efc39e445721e6cea057dab249 (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
# 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') }

  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

  it 'loads the given section config' do
    expect(settings.config1.value1).to eq(1)
  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
end