File: config_spec.rb

package info (click to toggle)
schleuder-gitlab-ticketing 1.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 260 kB
  • sloc: ruby: 775; makefile: 5
file content (63 lines) | stat: -rw-r--r-- 2,641 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'
describe SchleuderGitlabTicketing::Config do

  describe 'non existing config' do
    let(:config){ SchleuderGitlabTicketing::Config.new('spec/fixtures/gitlab.yml.nonexistent') }
    context 'with a config' do
      it 'provides a way to process a list' do
        expect(config).to respond_to(:process_list)
      end
      it 'loads the configured lists' do
        expect(config.lists.length).to eql(0)
      end
    end
  end

  describe 'basic' do
    let(:config){ SchleuderGitlabTicketing::Config.new('spec/fixtures/gitlab.yml') }
    context 'with a config' do
      it 'provides a way to process a list' do
        expect(config).to respond_to(:process_list)
      end
      it 'loads the configured lists' do
        expect(config.lists.length).to eql(8)
        expect(config.lists.values.first).to be_instance_of(SchleuderGitlabTicketing::List)
      end
    end
    context 'gitlab config' do
      it 'adds the global gitlab config to all the lists' do
        test_list = config.lists['test']
        expect(test_list.gitlab.endpoint).to eql('https://gitlab.example.com/api/v4')
        expect(config.lists['invalid1'].gitlab).to eql(test_list.gitlab)
      end
      it 'supports dedicated gitlabs for certain lists' do
        test_list = config.lists['test2']
        expect(test_list.gitlab.endpoint).to eql('https://gitlab2.example.com/api/v4')
        expect(config.lists['invalid1'].gitlab).to_not eql(test_list.gitlab)
      end
    end
    context 'merging filters' do
      it 'merges global and local subject filters' do
        test_list = config.lists['test']
        expect(test_list.subject_filters.length).to eql(2)
        expect(test_list.subject_filters).to include('\[announce\]')
        expect(test_list.subject_filters).to include('ignore me')
        test_list = config.lists['test2']
        expect(test_list.subject_filters.length).to eql(1)
        expect(test_list.subject_filters).to include('\[announce\]')
        expect(test_list.subject_filters).to_not include('ignore me')
      end
      it 'merges global and local sender filters' do
        test_list = config.lists['test2']
        expect(test_list.sender_filters.length).to eql(2)
        expect(test_list.sender_filters).to include('^test@example\.com$')
        expect(test_list.sender_filters).to include('noreply@example\.com')
        test_list = config.lists['test']
        expect(test_list.sender_filters.length).to eql(1)
        expect(test_list.sender_filters).to include('^test@example\.com$')
        expect(test_list.sender_filters).to_not include('noreply@example\.com')
      end
    end
  end
end