summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb
blob: 1532e870dccb7f4c1dbfbb2c7bd575cc31f9f851 (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
# frozen_string_literal: true

RSpec.shared_examples 'a destroyable issuable link' do |required_role: :reporter|
  context 'when successfully removes an issuable link' do
    before do
      [issuable_link.target, issuable_link.source].each do |issuable|
        issuable.resource_parent.try(:"add_#{required_role}", user)
      end
    end

    it 'removes related issue' do
      expect { subject }.to change { issuable_link.class.count }.by(-1)
    end

    it 'creates notes' do
      # Two-way notes creation
      expect(SystemNoteService).to receive(:unrelate_issuable)
                                     .with(issuable_link.source, issuable_link.target, user)
      expect(SystemNoteService).to receive(:unrelate_issuable)
                                     .with(issuable_link.target, issuable_link.source, user)

      subject
    end

    it 'returns success message' do
      is_expected.to eq(message: 'Relation was removed', status: :success)
    end
  end

  context 'when failing to remove an issuable link' do
    it 'does not remove relation' do
      expect { subject }.not_to change { issuable_link.class.count }.from(1)
    end

    it 'does not create notes' do
      expect(SystemNoteService).not_to receive(:unrelate_issuable)
    end

    it 'returns error message' do
      is_expected.to eq(message: "No #{issuable_link.class.model_name.human.titleize} found", status: :error, http_status: 404)
    end
  end
end