2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Banzai::ReferenceParser::ProjectParser do
|
2018-11-20 20:47:30 +05:30
|
|
|
include ReferenceParserHelpers
|
|
|
|
|
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
subject { described_class.new(Banzai::RenderContext.new(project, user)) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
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
|
|
|
|
|
2020-02-01 01:16:34 +05:30
|
|
|
expect_gathered_references(subject.gather_references([link]), [project], 0)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'using a non-existing project ID' do
|
|
|
|
it 'returns an empty Array' do
|
|
|
|
link['data-project'] = ''
|
|
|
|
|
2020-02-01 01:16:34 +05:30
|
|
|
expect_gathered_references(subject.gather_references([link]), [], 1)
|
2018-11-20 20:47:30 +05:30
|
|
|
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
|
|
|
|
|
2020-02-01 01:16:34 +05:30
|
|
|
expect_gathered_references(subject.gather_references([link]), [], 1)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an Array when authorized' do
|
|
|
|
private_project = create(:project, :private, namespace: user.namespace)
|
|
|
|
|
|
|
|
link['data-project'] = private_project.id.to_s
|
|
|
|
|
2020-02-01 01:16:34 +05:30
|
|
|
expect_gathered_references(subject.gather_references([link]), [private_project], 0)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|