BigW Consortium Gitlab

url_builder_spec.rb 3.03 KB
Newer Older
1 2 3 4 5 6 7
require 'spec_helper'

describe Gitlab::UrlBuilder do
  describe 'When asking for an issue' do
    it 'returns the issue url' do
      issue = create(:issue)
      url = Gitlab::UrlBuilder.new(:issue).build(issue.id)
Vinnie Okada committed
8
      expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.path_with_namespace}/issues/#{issue.iid}"
9 10
    end
  end
11 12 13 14 15

  describe 'When asking for an merge request' do
    it 'returns the merge request url' do
      merge_request = create(:merge_request)
      url = Gitlab::UrlBuilder.new(:merge_request).build(merge_request.id)
16
      expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.path_with_namespace}/merge_requests/#{merge_request.iid}"
17 18
    end
  end
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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

  describe 'When asking for a note on commit' do
    let(:note) { create(:note_on_commit) }
    let(:url) { Gitlab::UrlBuilder.new(:note).build(note.id) }

    it 'returns the note url' do
      expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.path_with_namespace}/commit/#{note.commit_id}#note_#{note.id}"
    end
  end

  describe 'When asking for a note on commit diff' do
    let(:note) { create(:note_on_commit_diff) }
    let(:url) { Gitlab::UrlBuilder.new(:note).build(note.id) }

    it 'returns the note url' do
      expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.path_with_namespace}/commit/#{note.commit_id}#note_#{note.id}"
    end
  end

  describe 'When asking for a note on issue' do
    let(:issue) { create(:issue) }
    let(:note) { create(:note_on_issue, noteable_id: issue.id) }
    let(:url) { Gitlab::UrlBuilder.new(:note).build(note.id) }

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

  describe 'When asking for a note on merge request' do
    let(:merge_request) { create(:merge_request) }
    let(:note) { create(:note_on_merge_request, noteable_id: merge_request.id) }
    let(:url) { Gitlab::UrlBuilder.new(:note).build(note.id) }

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

  describe 'When asking for a note on merge request diff' do
    let(:merge_request) { create(:merge_request) }
    let(:note) { create(:note_on_merge_request_diff, noteable_id: merge_request.id) }
    let(:url) { Gitlab::UrlBuilder.new(:note).build(note.id) }

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

  describe 'When asking for a note on project snippet' do
    let(:snippet) { create(:project_snippet) }
    let(:note) { create(:note_on_project_snippet, noteable_id: snippet.id) }
    let(:url) { Gitlab::UrlBuilder.new(:note).build(note.id) }

    it 'returns the note url' do
      expect(url).to eq "#{Settings.gitlab['url']}/#{snippet.project.path_with_namespace}/snippets/#{note.noteable_id}#note_#{note.id}"
    end
  end
77
end