File: participable_shared_examples.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (48 lines) | stat: -rw-r--r-- 1,675 bytes parent folder | download
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

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, ability_source: nil|
    it 'receives expected ability' do
      instance = model.new
      source = ability_source == :participable_source ? participable_source : instance

      allow(instance).to receive(:bar).and_return(participable_source)
      allow(Ability).to receive(:allowed?).with(anything, ability_name, source)

      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

  context 'when source is a system note' do
    let(:participable_source) { build(:system_note) }

    it_behaves_like 'check for participables read ability', :read_note, ability_source: :participable_source
  end
end