1# frozen_string_literal: true
2
3require 'spec_helper'
4
5RSpec.describe AwardEmojiPolicy do
6  let(:user) { create(:user) }
7  let(:award_emoji) { create(:award_emoji, awardable: awardable) }
8
9  subject { described_class.new(user, award_emoji) }
10
11  shared_examples 'when the user can read the awardable' do
12    context do
13      let(:project) { create(:project, :public) }
14
15      it { expect_allowed(:read_emoji) }
16    end
17  end
18
19  shared_examples 'when the user cannot read the awardable' do
20    context do
21      let(:project) { create(:project, :private) }
22
23      it { expect_disallowed(:read_emoji) }
24    end
25  end
26
27  context 'when the awardable is an issue' do
28    let(:awardable) { create(:issue, project: project) }
29
30    include_examples 'when the user can read the awardable'
31    include_examples 'when the user cannot read the awardable'
32  end
33
34  context 'when the awardable is a merge request' do
35    let(:awardable) { create(:merge_request, source_project: project) }
36
37    include_examples 'when the user can read the awardable'
38    include_examples 'when the user cannot read the awardable'
39  end
40
41  context 'when the awardable is a note' do
42    let(:awardable) { create(:note_on_merge_request, project: project) }
43
44    include_examples 'when the user can read the awardable'
45    include_examples 'when the user cannot read the awardable'
46  end
47
48  context 'when the awardable is a snippet' do
49    let(:awardable) { create(:project_snippet, :public, project: project) }
50
51    include_examples 'when the user can read the awardable'
52    include_examples 'when the user cannot read the awardable'
53  end
54end
55