2018-08-10 07:41:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-30 05:17:03 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Banzai::ReferenceParser::ProjectParser do
|
|
|
|
include ReferenceParserHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
subject { described_class.new(Banzai::RenderContext.new(project, user)) }
|
|
|
|
let(:link) { empty_html_link }
|
|
|
|
|
|
|
|
describe '#referenced_by' do
|
|
|
|
describe 'when the link has a data-project attribute' do
|
|
|
|
context 'using an existing project ID' do
|
|
|
|
it 'returns an Array of projects' do
|
|
|
|
link['data-project'] = project.id.to_s
|
|
|
|
|
2018-07-02 14:46:25 -04:00
|
|
|
expect(subject.gather_references([link])).to eq([project])
|
2018-06-30 05:17:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'using a non-existing project ID' do
|
|
|
|
it 'returns an empty Array' do
|
|
|
|
link['data-project'] = ''
|
|
|
|
|
2018-07-02 14:46:25 -04:00
|
|
|
expect(subject.gather_references([link])).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'using a private project ID' do
|
|
|
|
it 'returns an empty Array when unauthorized' do
|
|
|
|
private_project = create(:project, :private)
|
|
|
|
|
|
|
|
link['data-project'] = private_project.id.to_s
|
|
|
|
|
|
|
|
expect(subject.gather_references([link])).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an Array when authorized' do
|
|
|
|
private_project = create(:project, :private, namespace: user.namespace)
|
|
|
|
|
|
|
|
link['data-project'] = private_project.id.to_s
|
|
|
|
|
|
|
|
expect(subject.gather_references([link])).to eq([private_project])
|
2018-06-30 05:17:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|