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
|
|
|
|
2017-12-01 04:21:05 -05:00
|
|
|
describe '#parent_from_ref' do
|
2015-11-19 10:18:13 -05:00
|
|
|
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
|
|
|
|
2017-12-01 04:21:05 -05:00
|
|
|
expect(parent_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
|
|
|
|
2018-03-30 13:27:03 -04:00
|
|
|
context 'when no project was referenced in group context' do
|
|
|
|
it 'returns the group from context' do
|
|
|
|
group = double
|
|
|
|
|
|
|
|
allow(self).to receive(:context).and_return({ group: group })
|
|
|
|
|
|
|
|
expect(parent_from_ref(nil)).to eq group
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-19 10:18:13 -05:00
|
|
|
context 'when referenced project does not exist' do
|
|
|
|
it 'returns nil' do
|
2017-12-01 04:21:05 -05:00
|
|
|
expect(parent_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
|
|
|
|
2017-12-01 04:21:05 -05:00
|
|
|
expect(parent_from_ref('cross/reference')).to eq project2
|
2015-04-02 20:46:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|