2020-08-20 20:10:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe IssueLink do
|
2022-02-21 10:19:50 -05:00
|
|
|
it_behaves_like 'issuable link' do
|
|
|
|
let_it_be_with_reload(:issuable_link) { create(:issue_link) }
|
|
|
|
let_it_be(:issuable) { create(:issue) }
|
|
|
|
let(:issuable_class) { 'Issue' }
|
|
|
|
let(:issuable_link_factory) { :issue_link }
|
2020-08-20 20:10:44 -04:00
|
|
|
end
|
|
|
|
|
2022-03-01 07:19:32 -05:00
|
|
|
describe '.issuable_type' do
|
|
|
|
it { expect(described_class.issuable_type).to eq(:issue) }
|
|
|
|
end
|
|
|
|
|
2022-02-21 10:19:50 -05:00
|
|
|
describe 'Scopes' do
|
|
|
|
let_it_be(:issue1) { create(:issue) }
|
|
|
|
let_it_be(:issue2) { create(:issue) }
|
2020-08-20 20:10:44 -04:00
|
|
|
|
2022-02-21 10:19:50 -05:00
|
|
|
describe '.for_source_issue' do
|
|
|
|
it 'includes linked issues for source issue' do
|
|
|
|
source_issue = create(:issue)
|
|
|
|
issue_link_1 = create(:issue_link, source: source_issue, target: issue1)
|
|
|
|
issue_link_2 = create(:issue_link, source: source_issue, target: issue2)
|
2020-08-20 20:10:44 -04:00
|
|
|
|
2022-02-21 10:19:50 -05:00
|
|
|
result = described_class.for_source_issue(source_issue)
|
2020-11-10 22:08:57 -05:00
|
|
|
|
2022-02-21 10:19:50 -05:00
|
|
|
expect(result).to contain_exactly(issue_link_1, issue_link_2)
|
|
|
|
end
|
2020-11-10 22:08:57 -05:00
|
|
|
end
|
|
|
|
|
2022-02-21 10:19:50 -05:00
|
|
|
describe '.for_target_issue' do
|
|
|
|
it 'includes linked issues for target issue' do
|
|
|
|
target_issue = create(:issue)
|
|
|
|
issue_link_1 = create(:issue_link, source: issue1, target: target_issue)
|
|
|
|
issue_link_2 = create(:issue_link, source: issue2, target: target_issue)
|
2020-08-20 20:10:44 -04:00
|
|
|
|
2022-02-21 10:19:50 -05:00
|
|
|
result = described_class.for_target_issue(target_issue)
|
2020-08-20 20:10:44 -04:00
|
|
|
|
2022-02-21 10:19:50 -05:00
|
|
|
expect(result).to contain_exactly(issue_link_1, issue_link_2)
|
2020-08-20 20:10:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|