summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/markdown/cross_project_reference_spec.rb
blob: 8d4f9e403a603bfe37c1f6d22fa3df75f0e13dcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'spec_helper'

module Gitlab::Markdown
  describe CrossProjectReference do
    include described_class

    describe '#project_from_ref' do
      context 'when no project was referenced' do
        it 'returns the project from context' do
          project = double

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

          expect(project_from_ref(nil)).to eq project
        end
      end

      context 'when referenced project does not exist' do
        it 'returns nil' do
          expect(project_from_ref('invalid/reference')).to be_nil
        end
      end

      context 'when referenced project exists' do
        it 'returns the referenced project' do
          project2 = double('referenced project')

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

          expect(project_from_ref('cross/reference')).to eq project2
        end
      end
    end
  end
end