summaryrefslogtreecommitdiff
path: root/spec/policies/award_emoji_policy_spec.rb
blob: 2e3693c58d7755e39e2378a586073bf07971ba65 (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
# frozen_string_literal: true

require 'spec_helper'

describe AwardEmojiPolicy do
  let(:user) { create(:user) }
  let(:award_emoji) { create(:award_emoji, awardable: awardable) }

  subject { described_class.new(user, award_emoji) }

  shared_examples 'when the user can read the awardable' do
    context do
      let(:project) { create(:project, :public) }

      it { expect_allowed(:read_emoji) }
    end
  end

  shared_examples 'when the user cannot read the awardable' do
    context do
      let(:project) { create(:project, :private) }

      it { expect_disallowed(:read_emoji) }
    end
  end

  context 'when the awardable is an issue' do
    let(:awardable) { create(:issue, project: project) }

    include_examples 'when the user can read the awardable'
    include_examples 'when the user cannot read the awardable'
  end

  context 'when the awardable is a merge request' do
    let(:awardable) { create(:merge_request, source_project: project) }

    include_examples 'when the user can read the awardable'
    include_examples 'when the user cannot read the awardable'
  end

  context 'when the awardable is a note' do
    let(:awardable) { create(:note_on_merge_request, project: project) }

    include_examples 'when the user can read the awardable'
    include_examples 'when the user cannot read the awardable'
  end

  context 'when the awardable is a snippet' do
    let(:awardable) { create(:project_snippet, :public, project: project) }

    include_examples 'when the user can read the awardable'
    include_examples 'when the user cannot read the awardable'
  end
end