2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.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
|