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/models/concerns/issuable_link_spec.rb')
-rw-r--r--spec/models/concerns/issuable_link_spec.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/models/concerns/issuable_link_spec.rb b/spec/models/concerns/issuable_link_spec.rb
new file mode 100644
index 00000000000..7be6d8a074d
--- /dev/null
+++ b/spec/models/concerns/issuable_link_spec.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IssuableLink do
+ let(:test_class) do
+ Class.new(ApplicationRecord) do
+ include IssuableLink
+
+ self.table_name = 'issue_links'
+
+ belongs_to :source, class_name: 'Issue'
+ belongs_to :target, class_name: 'Issue'
+
+ def self.name
+ 'TestClass'
+ end
+ end
+ end
+
+ describe '.inverse_link_type' do
+ it 'returns the inverse type of link' do
+ expect(test_class.inverse_link_type('relates_to')).to eq('relates_to')
+ end
+ end
+
+ describe '.issuable_type' do
+ let_it_be(:source_issue) { create(:issue) }
+ let_it_be(:target_issue) { create(:issue) }
+
+ before do
+ test_class.create!(source: source_issue, target: target_issue)
+ end
+
+ context 'when opposite relation already exists' do
+ it 'raises NotImplementedError when performing validations' do
+ instance = test_class.new(source: target_issue, target: source_issue)
+
+ expect { instance.save! }.to raise_error(NotImplementedError)
+ end
+ end
+ end
+end