blob: ec7a9105bb2843fb8c7469194f9377462ac9f34b (
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
|
# frozen_string_literal: true
RSpec.shared_examples 'visible participants for issuable with read ability' do |model_class|
let_it_be(:user1) { create(:user) }
let(:model) { model_class.to_s.classify.constantize }
before do
allow(Ability).to receive(:allowed?).with(anything, :"read_#{model_class}", anything).and_return(true)
allow(model).to receive(:participant_attrs).and_return([:bar])
end
shared_examples 'check for participables read ability' do |ability_name|
it 'receives expected ability' do
instance = model.new
allow(instance).to receive(:bar).and_return(participable_source)
expect(Ability).to receive(:allowed?).with(anything, ability_name, instance)
expect(instance.visible_participants(user1)).to be_empty
end
end
context 'when source is an award emoji' do
let(:participable_source) { build(:award_emoji, :upvote) }
it_behaves_like 'check for participables read ability', :read_issuable_participables
end
context 'when source is a note' do
let(:participable_source) { build(:note) }
it_behaves_like 'check for participables read ability', :read_note
end
context 'when source is an internal note' do
let(:participable_source) { build(:note, :confidential) }
it_behaves_like 'check for participables read ability', :read_internal_note
end
end
|