summaryrefslogtreecommitdiff
path: root/spec/policies/board_policy_spec.rb
blob: 35eac8a02c435212903cc51786f22c1de3f09363 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# frozen_string_literal: true

require 'spec_helper'

describe BoardPolicy do
  let(:user) { create(:user) }
  let(:project) { create(:project, :private) }
  let(:group) { create(:group, :private) }
  let(:group_board) { create(:board, group: group) }
  let(:project_board) { create(:board, project: project) }

  let(:board_permissions) do
    [
      :read_parent,
      :read_milestone,
      :read_issue
    ]
  end

  context 'group board' do
    subject { described_class.new(user, group_board) }

    context 'user has access' do
      before do
        group.add_developer(user)
      end

      it do
        expect_allowed(*board_permissions)
      end
    end

    context 'user does not have access' do
      it do
        expect_disallowed(*board_permissions)
      end
    end
  end

  context 'project board' do
    subject { described_class.new(user, project_board) }

    context 'user has access' do
      before do
        project.add_developer(user)
      end

      it do
        expect_allowed(*board_permissions)
      end
    end

    context 'user does not have access' do
      it do
        expect_disallowed(*board_permissions)
      end
    end
  end

  context 'create_non_backlog_issues' do
    context 'for project boards' do
      let!(:current_user) { create(:user) }

      subject { described_class.new(current_user, project_board) }

      context 'when user can admin project issues' do
        it 'allows to add non backlog issues from issue board' do
          project.add_reporter(current_user)

          expect_allowed(:create_non_backlog_issues)
        end
      end

      context 'when user cannot admin project issues' do
        it 'does not allow to add non backlog issues from issue board' do
          project.add_guest(current_user)

          expect_disallowed(:create_non_backlog_issues)
        end
      end
    end

    context 'for group boards' do
      let!(:current_user) { create(:user) }
      let!(:project_1) { create(:project, namespace: group) }
      let!(:project_2) { create(:project, namespace: group) }
      let!(:group_board) { create(:board, group: group) }

      subject { described_class.new(current_user, group_board) }

      before do
        project_1.add_guest(current_user)
      end

      context 'when user is at least reporter in one of the child projects' do
        it 'allows to add non backlog issues from issue board' do
          project_2.add_reporter(current_user)

          expect_allowed(:create_non_backlog_issues)
        end
      end

      context 'when user is not a reporter from any child projects' do
        it 'does not allow to add non backlog issues from issue board' do
          project_2.add_guest(current_user)

          expect_disallowed(:create_non_backlog_issues)
        end
      end
    end
  end
end