summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/cross_project_access/check_collection_spec.rb
blob: a9e7575240e333c290bc8aed5dae053848995e32 (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
require 'spec_helper'

describe Gitlab::CrossProjectAccess::CheckCollection do
  subject(:collection) { described_class.new }

  describe '#add_collection' do
    it 'merges the checks of 2 collections' do
      initial_check = double('check')
      collection.add_check(initial_check)

      other_collection = described_class.new
      other_check = double('other_check')
      other_collection.add_check(other_check)

      shared_check = double('shared check')
      other_collection.add_check(shared_check)
      collection.add_check(shared_check)

      collection.add_collection(other_collection)

      expect(collection.checks).to contain_exactly(initial_check, shared_check, other_check)
    end
  end

  describe '#should_run?' do
    def fake_check(run, skip)
      check = double("Check: run=#{run} - skip={skip}")
      allow(check).to receive(:should_run?).and_return(run)
      allow(check).to receive(:should_skip?).and_return(skip)
      allow(check).to receive(:skip).and_return(skip)

      check
    end

    it 'returns true if one of the check says it should run' do
      check = fake_check(true, false)
      other_check = fake_check(false, false)

      collection.add_check(check)
      collection.add_check(other_check)

      expect(collection.should_run?(double)).to be_truthy
    end

    it 'returns false if one of the check says it should be skipped' do
      check = fake_check(true, false)
      other_check = fake_check(false, true)

      collection.add_check(check)
      collection.add_check(other_check)

      expect(collection.should_run?(double)).to be_falsey
    end
  end
end