2015-04-03 00:46:43 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Banzai::CrossProjectReference do
|
2015-11-19 15:18:13 +00:00
|
|
|
include described_class
|
2015-04-03 00:46:43 +00:00
|
|
|
|
2017-12-01 09:21:05 +00:00
|
|
|
describe '#parent_from_ref' do
|
2015-11-19 15:18:13 +00:00
|
|
|
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
|
|
|
|
2017-12-01 09:21:05 +00:00
|
|
|
expect(parent_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
|
|
|
|
2018-03-30 17:27:03 +00: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 15:18:13 +00:00
|
|
|
context 'when referenced project does not exist' do
|
|
|
|
it 'returns nil' do
|
2017-12-01 09:21:05 +00:00
|
|
|
expect(parent_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
|
|
|
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(Project).to receive(:find_by_full_path)
|
|
|
|
.with('cross/reference').and_return(project2)
|
2015-04-14 20:04:37 +00:00
|
|
|
|
2017-12-01 09:21:05 +00:00
|
|
|
expect(parent_from_ref('cross/reference')).to eq project2
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|