BigW Consortium Gitlab

cross_project_reference_spec.rb 920 Bytes
Newer Older
Robert Speicher committed
1 2
require 'spec_helper'

3
describe Banzai::CrossProjectReference, lib: true do
4
  include described_class
Robert Speicher committed
5

6 7 8 9
  describe '#project_from_ref' do
    context 'when no project was referenced' do
      it 'returns the project from context' do
        project = double
10

11
        allow(self).to receive(:context).and_return({ project: project })
12

13
        expect(project_from_ref(nil)).to eq project
14
      end
15
    end
16

17 18 19
    context 'when referenced project does not exist' do
      it 'returns nil' do
        expect(project_from_ref('invalid/reference')).to be_nil
20
      end
21
    end
Robert Speicher committed
22

23 24 25
    context 'when referenced project exists' do
      it 'returns the referenced project' do
        project2 = double('referenced project')
Robert Speicher committed
26

27 28
        expect(Project).to receive(:find_with_namespace).
          with('cross/reference').and_return(project2)
29

30
        expect(project_from_ref('cross/reference')).to eq project2
Robert Speicher committed
31 32 33 34
      end
    end
  end
end