2015-04-03 00:46:43 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-12-15 14:51:16 +00:00
|
|
|
describe Banzai::CrossProjectReference, lib: true do
|
2015-11-19 15:18:13 +00:00
|
|
|
include described_class
|
2015-04-03 00:46:43 +00:00
|
|
|
|
2015-11-19 15:18:13 +00:00
|
|
|
describe '#project_from_ref' do
|
|
|
|
context 'when no project was referenced' do
|
|
|
|
it 'returns the project from context' do
|
|
|
|
project = double
|
2015-09-03 03:45:42 +00:00
|
|
|
|
2015-11-19 15:18:13 +00:00
|
|
|
allow(self).to receive(:context).and_return({ project: project })
|
2015-09-03 03:45:42 +00:00
|
|
|
|
2015-11-19 15:18:13 +00:00
|
|
|
expect(project_from_ref(nil)).to eq project
|
2015-04-17 10:34:51 +00:00
|
|
|
end
|
2015-11-19 15:18:13 +00:00
|
|
|
end
|
2015-04-17 10:34:51 +00:00
|
|
|
|
2015-11-19 15:18:13 +00:00
|
|
|
context 'when referenced project does not exist' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(project_from_ref('invalid/reference')).to be_nil
|
2015-04-14 20:04:37 +00:00
|
|
|
end
|
2015-11-19 15:18:13 +00:00
|
|
|
end
|
2015-04-03 00:46:43 +00:00
|
|
|
|
2015-11-19 15:18:13 +00:00
|
|
|
context 'when referenced project exists' do
|
|
|
|
it 'returns the referenced project' do
|
|
|
|
project2 = double('referenced project')
|
2015-04-03 00:46:43 +00:00
|
|
|
|
2015-11-19 15:18:13 +00:00
|
|
|
expect(Project).to receive(:find_with_namespace).
|
|
|
|
with('cross/reference').and_return(project2)
|
2015-04-14 20:04:37 +00:00
|
|
|
|
2015-11-19 15:18:13 +00:00
|
|
|
expect(project_from_ref('cross/reference')).to eq project2
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|