2015-04-02 20:46:43 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Banzai::CrossProjectReference do
|
2015-11-19 10:18:13 -05:00
|
|
|
include described_class
|
2015-04-02 20:46:43 -04:00
|
|
|
|
2015-11-19 10:18:13 -05:00
|
|
|
describe '#project_from_ref' do
|
|
|
|
context 'when no project was referenced' do
|
|
|
|
it 'returns the project from context' do
|
|
|
|
project = double
|
2015-09-02 23:45:42 -04:00
|
|
|
|
2015-11-19 10:18:13 -05:00
|
|
|
allow(self).to receive(:context).and_return({ project: project })
|
2015-09-02 23:45:42 -04:00
|
|
|
|
2015-11-19 10:18:13 -05:00
|
|
|
expect(project_from_ref(nil)).to eq project
|
2015-04-17 06:34:51 -04:00
|
|
|
end
|
2015-11-19 10:18:13 -05:00
|
|
|
end
|
2015-04-17 06:34:51 -04:00
|
|
|
|
2015-11-19 10:18:13 -05: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 16:04:37 -04:00
|
|
|
end
|
2015-11-19 10:18:13 -05:00
|
|
|
end
|
2015-04-02 20:46:43 -04:00
|
|
|
|
2015-11-19 10:18:13 -05:00
|
|
|
context 'when referenced project exists' do
|
|
|
|
it 'returns the referenced project' do
|
|
|
|
project2 = double('referenced project')
|
2015-04-02 20:46:43 -04:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(Project).to receive(:find_by_full_path)
|
|
|
|
.with('cross/reference').and_return(project2)
|
2015-04-14 16:04:37 -04:00
|
|
|
|
2015-11-19 10:18:13 -05:00
|
|
|
expect(project_from_ref('cross/reference')).to eq project2
|
2015-04-02 20:46:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|