Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb b/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb
new file mode 100644
index 00000000000..53d637a9094
--- /dev/null
+++ b/spec/support/shared_examples/services/issuable_links/destroyable_issuable_links_shared_examples.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+shared_examples 'a destroyable issuable link' do
+ context 'when successfully removes an issuable link' do
+ before do
+ issuable_link.source.resource_parent.add_reporter(user)
+ issuable_link.target.resource_parent.add_reporter(user)
+ 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