debian-mirror-gitlab/spec/lib/banzai/cross_project_reference_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
2.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2015-12-23 02:04:40 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Banzai::CrossProjectReference do
2018-12-05 23:21:45 +05:30
let(:including_class) { Class.new.include(described_class).new }
2022-08-27 11:52:29 +05:30
let(:reference_cache) { Banzai::Filter::References::ReferenceCache.new(including_class, {}, {}) }
2018-12-05 23:21:45 +05:30
before do
allow(including_class).to receive(:context).and_return({})
allow(including_class).to receive(:parent_from_ref).and_call_original
2021-06-08 01:23:25 +05:30
allow(including_class).to receive(:reference_cache).and_return(reference_cache)
2018-12-05 23:21:45 +05:30
end
2015-12-23 02:04:40 +05:30
2018-03-17 18:26:18 +05:30
describe '#parent_from_ref' do
2015-12-23 02:04:40 +05:30
context 'when no project was referenced' do
it 'returns the project from context' do
project = double
2018-12-05 23:21:45 +05:30
allow(including_class).to receive(:context).and_return({ project: project })
2015-12-23 02:04:40 +05:30
2018-12-05 23:21:45 +05:30
expect(including_class.parent_from_ref(nil)).to eq project
2015-12-23 02:04:40 +05:30
end
end
2018-05-09 12:01:36 +05:30
context 'when no project was referenced in group context' do
it 'returns the group from context' do
group = double
2018-12-05 23:21:45 +05:30
allow(including_class).to receive(:context).and_return({ group: group })
2018-05-09 12:01:36 +05:30
2018-12-05 23:21:45 +05:30
expect(including_class.parent_from_ref(nil)).to eq group
2018-05-09 12:01:36 +05:30
end
end
2015-12-23 02:04:40 +05:30
context 'when referenced project does not exist' do
it 'returns nil' do
2018-12-05 23:21:45 +05:30
expect(including_class.parent_from_ref('invalid/reference')).to be_nil
2015-12-23 02:04:40 +05:30
end
end
context 'when referenced project exists' do
it 'returns the referenced project' do
project2 = double('referenced project')
2017-09-10 17:25:29 +05:30
expect(Project).to receive(:find_by_full_path)
.with('cross/reference').and_return(project2)
2015-12-23 02:04:40 +05:30
2018-12-05 23:21:45 +05:30
expect(including_class.parent_from_ref('cross/reference')).to eq project2
2015-12-23 02:04:40 +05:30
end
end
2021-06-08 01:23:25 +05:30
context 'when reference cache is loaded' do
let(:project2) { double('referenced project') }
before do
allow(reference_cache).to receive(:cache_loaded?).and_return(true)
allow(reference_cache).to receive(:parent_per_reference).and_return({ 'cross/reference' => project2 })
end
it 'pulls from the reference cache' do
expect(including_class.parent_from_ref('cross/reference')).to eq project2
end
end
2015-12-23 02:04:40 +05:30
end
end