2016-05-26 07:16:43 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Banzai::ReferenceParser::IssueParser, lib: true do
|
|
|
|
include ReferenceParserHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:empty_project, :public) }
|
2016-11-01 16:18:51 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:issue) { create(:issue, project: project) }
|
|
|
|
let(:link) { empty_html_link }
|
|
|
|
subject { described_class.new(project, user) }
|
2016-05-26 07:16:43 -04:00
|
|
|
|
|
|
|
describe '#nodes_visible_to_user' do
|
|
|
|
context 'when the link has a data-issue attribute' do
|
|
|
|
before do
|
|
|
|
link['data-issue'] = issue.id.to_s
|
|
|
|
end
|
|
|
|
|
2016-11-01 16:18:51 -04:00
|
|
|
it_behaves_like "referenced feature visibility", "issues"
|
|
|
|
|
2016-05-26 07:16:43 -04:00
|
|
|
it 'returns the nodes when the user can read the issue' do
|
2016-07-20 14:13:02 -04:00
|
|
|
expect(Ability).to receive(:issues_readable_by_user).
|
|
|
|
with([issue], user).
|
|
|
|
and_return([issue])
|
2016-05-26 07:16:43 -04:00
|
|
|
|
|
|
|
expect(subject.nodes_visible_to_user(user, [link])).to eq([link])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty Array when the user can not read the issue' do
|
2016-07-20 14:13:02 -04:00
|
|
|
expect(Ability).to receive(:issues_readable_by_user).
|
|
|
|
with([issue], user).
|
|
|
|
and_return([])
|
2016-05-26 07:16:43 -04:00
|
|
|
|
|
|
|
expect(subject.nodes_visible_to_user(user, [link])).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the link does not have a data-issue attribute' do
|
|
|
|
it 'returns an empty Array' do
|
|
|
|
expect(subject.nodes_visible_to_user(user, [link])).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project uses an external issue tracker' do
|
|
|
|
it 'returns all nodes' do
|
|
|
|
link = double(:link)
|
|
|
|
|
|
|
|
expect(project).to receive(:external_issue_tracker).and_return(true)
|
|
|
|
|
|
|
|
expect(subject.nodes_visible_to_user(user, [link])).to eq([link])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#referenced_by' do
|
|
|
|
context 'when the link has a data-issue attribute' do
|
|
|
|
context 'using an existing issue ID' do
|
|
|
|
before do
|
|
|
|
link['data-issue'] = issue.id.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an Array of issues' do
|
|
|
|
expect(subject.referenced_by([link])).to eq([issue])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty Array when the list of nodes is empty' do
|
|
|
|
expect(subject.referenced_by([link])).to eq([issue])
|
|
|
|
expect(subject.referenced_by([])).to eq([])
|
|
|
|
end
|
|
|
|
end
|
2016-08-24 13:11:48 -04:00
|
|
|
|
|
|
|
context 'when issue with given ID does not exist' do
|
|
|
|
before do
|
|
|
|
link['data-issue'] = '-1'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty Array' do
|
|
|
|
expect(subject.referenced_by([link])).to eq([])
|
|
|
|
end
|
|
|
|
end
|
2016-05-26 07:16:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#issues_for_nodes' do
|
|
|
|
it 'returns a Hash containing the issues for a list of nodes' do
|
|
|
|
link['data-issue'] = issue.id.to_s
|
|
|
|
nodes = [link]
|
|
|
|
|
2016-08-24 13:11:48 -04:00
|
|
|
expect(subject.issues_for_nodes(nodes)).to eq({ link => issue })
|
2016-05-26 07:16:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|