summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/cross_project_access/class_methods_spec.rb
blob: 17d265542dd1a7a604afe974befad039d9812d19 (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
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::CrossProjectAccess::ClassMethods do
  let(:dummy_class) do
    Class.new do
      extend Gitlab::CrossProjectAccess::ClassMethods
    end
  end
  let(:dummy_proc) { lambda { false } }

  describe '#requires_cross_project_access' do
    it 'creates a correct check when a hash is passed' do
      expect(Gitlab::CrossProjectAccess)
        .to receive(:add_check).with(dummy_class,
                                     actions: { hello: true, world: false },
                                     positive_condition: dummy_proc,
                                     negative_condition: dummy_proc)

      dummy_class.requires_cross_project_access(
        hello: true, world: false, if: dummy_proc, unless: dummy_proc
      )
    end

    it 'creates a correct check when an array is passed' do
      expect(Gitlab::CrossProjectAccess)
        .to receive(:add_check).with(dummy_class,
                                     actions: { hello: true, world: true },
                                     positive_condition: nil,
                                     negative_condition: nil)

      dummy_class.requires_cross_project_access(:hello, :world)
    end

    it 'creates a correct check when an array and a hash is passed' do
      expect(Gitlab::CrossProjectAccess)
        .to receive(:add_check).with(dummy_class,
                                     actions: { hello: true, world: true },
                                     positive_condition: dummy_proc,
                                     negative_condition: dummy_proc)

      dummy_class.requires_cross_project_access(
        :hello, :world, if: dummy_proc, unless: dummy_proc
      )
    end
  end
end