BigW Consortium Gitlab

url_builder_spec.rb 3.89 KB
Newer Older
1 2
require 'spec_helper'

Douwe Maan committed
3
describe Gitlab::UrlBuilder, lib: true do
4 5 6 7
  describe '.build' do
    context 'when passing a Commit' do
      it 'returns a proper URL' do
        commit = build_stubbed(:commit)
8

9 10 11 12
        url = described_class.build(commit)

        expect(url).to eq "#{Settings.gitlab['url']}/#{commit.project.path_with_namespace}/commit/#{commit.id}"
      end
13
    end
14

15 16 17
    context 'when passing an Issue' do
      it 'returns a proper URL' do
        issue = build_stubbed(:issue, iid: 42)
18

19 20 21 22
        url = described_class.build(issue)

        expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.path_with_namespace}/issues/#{issue.iid}"
      end
23 24
    end

25 26 27 28 29
    context 'when passing a MergeRequest' do
      it 'returns a proper URL' do
        merge_request = build_stubbed(:merge_request, iid: 42)

        url = described_class.build(merge_request)
30

31 32
        expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.path_with_namespace}/merge_requests/#{merge_request.iid}"
      end
33 34
    end

35 36 37 38
    context 'when passing a Note' do
      context 'on a Commit' do
        it 'returns a proper URL' do
          note = build_stubbed(:note_on_commit)
39

40
          url = described_class.build(note)
41

42 43 44
          expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.path_with_namespace}/commit/#{note.commit_id}#note_#{note.id}"
        end
      end
45

Douwe Maan committed
46
      context 'on a Commit Diff' do
47
        it 'returns a proper URL' do
Douwe Maan committed
48
          note = build_stubbed(:diff_note_on_commit)
49

50
          url = described_class.build(note)
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
          expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.path_with_namespace}/commit/#{note.commit_id}#note_#{note.id}"
        end
      end

      context 'on an Issue' do
        it 'returns a proper URL' do
          issue = create(:issue, iid: 42)
          note = build_stubbed(:note_on_issue, noteable: issue)

          url = described_class.build(note)

          expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.path_with_namespace}/issues/#{issue.iid}#note_#{note.id}"
        end
      end

      context 'on a MergeRequest' do
        it 'returns a proper URL' do
          merge_request = create(:merge_request, iid: 42)
          note = build_stubbed(:note_on_merge_request, noteable: merge_request)

          url = described_class.build(note)

          expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.path_with_namespace}/merge_requests/#{merge_request.iid}#note_#{note.id}"
        end
      end

Douwe Maan committed
78
      context 'on a MergeRequest Diff' do
79 80
        it 'returns a proper URL' do
          merge_request = create(:merge_request, iid: 42)
Douwe Maan committed
81
          note = build_stubbed(:diff_note_on_merge_request, noteable: merge_request)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

          url = described_class.build(note)

          expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.path_with_namespace}/merge_requests/#{merge_request.iid}#note_#{note.id}"
        end
      end

      context 'on a ProjectSnippet' do
        it 'returns a proper URL' do
          project_snippet = create(:project_snippet)
          note = build_stubbed(:note_on_project_snippet, noteable: project_snippet)

          url = described_class.build(note)

          expect(url).to eq "#{Settings.gitlab['url']}/#{project_snippet.project.path_with_namespace}/snippets/#{note.noteable_id}#note_#{note.id}"
        end
      end
99

100 101
      context 'on another object' do
        it 'returns a proper URL' do
102
          project = build_stubbed(:empty_project)
103

104 105 106 107
          expect { described_class.build(project) }.
            to raise_error(NotImplementedError, 'No URL builder defined for Project')
        end
      end
108
    end
Sebastian Klier committed
109 110 111 112 113 114

    context 'when passing a WikiPage' do
      it 'returns a proper URL' do
        wiki_page = build(:wiki_page)
        url = described_class.build(wiki_page)

115
        expect(url).to eq "#{Gitlab.config.gitlab.url}#{wiki_page.wiki.wiki_base_path}/#{wiki_page.slug}"
Sebastian Klier committed
116 117
      end
    end
118
  end
119
end