2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-06-13 06:34:15 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Gitlab::UrlBuilder do
|
2016-04-13 05:25:42 -04:00
|
|
|
describe '.build' do
|
|
|
|
context 'when passing a Commit' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
commit = build_stubbed(:commit)
|
2015-02-24 01:50:40 -05:00
|
|
|
|
2016-04-13 05:25:42 -04:00
|
|
|
url = described_class.build(commit)
|
|
|
|
|
2020-02-05 16:09:02 -05:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{commit.project.full_path}/-/commit/#{commit.id}"
|
2016-04-13 05:25:42 -04:00
|
|
|
end
|
2015-02-24 01:50:40 -05:00
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2020-03-03 13:08:16 -05:00
|
|
|
context 'when passing a batch loaded Commit' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
commit = BatchLoader.for(:commit).batch do |batch, loader|
|
|
|
|
batch.each { |commit| loader.call(:commit, build_stubbed(:commit)) }
|
|
|
|
end
|
|
|
|
|
|
|
|
url = described_class.build(commit)
|
|
|
|
|
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{commit.project.full_path}/-/commit/#{commit.id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-13 05:25:42 -04:00
|
|
|
context 'when passing an Issue' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
issue = build_stubbed(:issue, iid: 42)
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2016-04-13 05:25:42 -04:00
|
|
|
url = described_class.build(issue)
|
|
|
|
|
2020-03-02 10:08:01 -05:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.full_path}/-/issues/#{issue.iid}"
|
2016-04-13 05:25:42 -04:00
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
2018-06-12 18:40:16 -04:00
|
|
|
context 'when passing a Milestone' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project, :public, namespace: group) }
|
|
|
|
|
|
|
|
context 'belonging to a project' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
milestone = create(:milestone, project: project)
|
|
|
|
|
|
|
|
url = described_class.build(milestone)
|
|
|
|
|
2019-05-29 06:45:27 -04:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{milestone.project.full_path}/-/milestones/#{milestone.iid}"
|
2018-06-12 18:40:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'belonging to a group' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
milestone = create(:milestone, group: group)
|
|
|
|
|
|
|
|
url = described_class.build(milestone)
|
|
|
|
|
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/groups/#{milestone.group.full_path}/-/milestones/#{milestone.iid}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-13 05:25:42 -04:00
|
|
|
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)
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2020-01-20 19:08:46 -05:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}"
|
2016-04-13 05:25:42 -04:00
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
|
|
|
|
2019-11-28 10:06:57 -05:00
|
|
|
context 'when passing a ProjectSnippet' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
project_snippet = create(:project_snippet)
|
|
|
|
|
|
|
|
url = described_class.build(project_snippet)
|
|
|
|
|
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when passing a PersonalSnippet' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
personal_snippet = create(:personal_snippet)
|
|
|
|
|
|
|
|
url = described_class.build(personal_snippet)
|
|
|
|
|
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/snippets/#{personal_snippet.id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-13 05:25:42 -04:00
|
|
|
context 'when passing a Note' do
|
|
|
|
context 'on a Commit' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
note = build_stubbed(:note_on_commit)
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2016-04-13 05:25:42 -04:00
|
|
|
url = described_class.build(note)
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2020-02-05 16:09:02 -05:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}"
|
2016-04-13 05:25:42 -04:00
|
|
|
end
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2016-06-20 13:20:39 -04:00
|
|
|
context 'on a Commit Diff' do
|
2016-04-13 05:25:42 -04:00
|
|
|
it 'returns a proper URL' do
|
2016-06-20 13:20:39 -04:00
|
|
|
note = build_stubbed(:diff_note_on_commit)
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2016-04-13 05:25:42 -04:00
|
|
|
url = described_class.build(note)
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2020-02-05 16:09:02 -05:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}"
|
2016-04-13 05:25:42 -04:00
|
|
|
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)
|
|
|
|
|
2020-03-02 10:08:01 -05:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.full_path}/-/issues/#{issue.iid}#note_#{note.id}"
|
2016-04-13 05:25:42 -04:00
|
|
|
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)
|
|
|
|
|
2020-01-20 19:08:46 -05:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}#note_#{note.id}"
|
2016-04-13 05:25:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-20 13:20:39 -04:00
|
|
|
context 'on a MergeRequest Diff' do
|
2016-04-13 05:25:42 -04:00
|
|
|
it 'returns a proper URL' do
|
|
|
|
merge_request = create(:merge_request, iid: 42)
|
2016-06-20 13:20:39 -04:00
|
|
|
note = build_stubbed(:diff_note_on_merge_request, noteable: merge_request)
|
2016-04-13 05:25:42 -04:00
|
|
|
|
|
|
|
url = described_class.build(note)
|
|
|
|
|
2020-01-20 19:08:46 -05:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}#note_#{note.id}"
|
2016-04-13 05:25:42 -04:00
|
|
|
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)
|
|
|
|
|
2017-07-20 05:34:09 -04:00
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/#{project_snippet.project.full_path}/snippets/#{note.noteable_id}#note_#{note.id}"
|
2016-04-13 05:25:42 -04:00
|
|
|
end
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2017-06-07 14:33:50 -04:00
|
|
|
context 'on a PersonalSnippet' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
personal_snippet = create(:personal_snippet)
|
|
|
|
note = build_stubbed(:note_on_personal_snippet, noteable: personal_snippet)
|
|
|
|
|
|
|
|
url = described_class.build(note)
|
|
|
|
|
|
|
|
expect(url).to eq "#{Settings.gitlab['url']}/snippets/#{note.noteable_id}#note_#{note.id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-13 05:25:42 -04:00
|
|
|
context 'on another object' do
|
|
|
|
it 'returns a proper URL' do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = build_stubbed(:project)
|
2015-03-05 13:38:23 -05:00
|
|
|
|
2017-06-21 09:48:12 -04:00
|
|
|
expect { described_class.build(project) }
|
2020-03-03 13:08:16 -05:00
|
|
|
.to raise_error(NotImplementedError, "No URL builder defined for #{project.inspect}")
|
2016-04-13 05:25:42 -04:00
|
|
|
end
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
2016-04-15 00:47:09 -04:00
|
|
|
|
|
|
|
context 'when passing a WikiPage' do
|
|
|
|
it 'returns a proper URL' do
|
|
|
|
wiki_page = build(:wiki_page)
|
|
|
|
url = described_class.build(wiki_page)
|
|
|
|
|
2019-10-31 17:06:28 -04:00
|
|
|
expect(url).to eq "#{Gitlab.config.gitlab.url}#{wiki_page.wiki.wiki_base_path}/#{wiki_page.slug}"
|
2016-04-15 00:47:09 -04:00
|
|
|
end
|
|
|
|
end
|
2015-03-05 13:38:23 -05:00
|
|
|
end
|
2014-06-13 06:34:15 -04:00
|
|
|
end
|