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

50 lines
1.4 KiB
Ruby
Raw Normal View History

2015-12-23 02:04:40 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Banzai::CrossProjectReference do
2018-12-05 23:21:45 +05:30
let(:including_class) { Class.new.include(described_class).new }
before do
allow(including_class).to receive(:context).and_return({})
allow(including_class).to receive(:parent_from_ref).and_call_original
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
end
end