debian-mirror-gitlab/spec/lib/gitlab/url_builder_spec.rb

190 lines
6 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe Gitlab::UrlBuilder do
2016-06-02 11:05:42 +05:30
describe '.build' do
context 'when passing a Commit' do
it 'returns a proper URL' do
commit = build_stubbed(:commit)
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
url = described_class.build(commit)
2020-03-13 15:44:24 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{commit.project.full_path}/-/commit/#{commit.id}"
2016-06-02 11:05:42 +05:30
end
2015-04-26 12:48:37 +05:30
end
2020-04-08 14:13:33 +05:30
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-06-02 11:05:42 +05:30
context 'when passing an Issue' do
it 'returns a proper URL' do
issue = build_stubbed(:issue, iid: 42)
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
url = described_class.build(issue)
2020-04-08 14:13:33 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.full_path}/-/issues/#{issue.iid}"
2016-06-02 11:05:42 +05:30
end
2015-04-26 12:48:37 +05:30
end
2018-11-08 19:23:39 +05:30
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-09-04 21:01:54 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{milestone.project.full_path}/-/milestones/#{milestone.iid}"
2018-11-08 19:23:39 +05:30
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-06-02 11:05:42 +05:30
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-04-26 12:48:37 +05:30
2020-03-13 15:44:24 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}"
2016-06-02 11:05:42 +05:30
end
2015-04-26 12:48:37 +05:30
end
2020-01-01 13:55:28 +05:30
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-06-02 11:05:42 +05:30
context 'when passing a Note' do
context 'on a Commit' do
it 'returns a proper URL' do
note = build_stubbed(:note_on_commit)
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
url = described_class.build(note)
2015-04-26 12:48:37 +05:30
2020-03-13 15:44:24 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}"
2016-06-02 11:05:42 +05:30
end
end
2015-04-26 12:48:37 +05:30
2016-08-24 12:49:21 +05:30
context 'on a Commit Diff' do
2016-06-02 11:05:42 +05:30
it 'returns a proper URL' do
2016-08-24 12:49:21 +05:30
note = build_stubbed(:diff_note_on_commit)
2016-06-02 11:05:42 +05:30
url = described_class.build(note)
2020-03-13 15:44:24 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}"
2016-06-02 11:05:42 +05:30
end
end
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
context 'on an Issue' do
it 'returns a proper URL' do
issue = create(:issue, iid: 42)
note = build_stubbed(:note_on_issue, noteable: issue)
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
url = described_class.build(note)
2020-04-08 14:13:33 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.full_path}/-/issues/#{issue.iid}#note_#{note.id}"
2016-06-02 11:05:42 +05:30
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-03-13 15:44:24 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}#note_#{note.id}"
2016-06-02 11:05:42 +05:30
end
end
2016-08-24 12:49:21 +05:30
context 'on a MergeRequest Diff' do
2016-06-02 11:05:42 +05:30
it 'returns a proper URL' do
merge_request = create(:merge_request, iid: 42)
2016-08-24 12:49:21 +05:30
note = build_stubbed(:diff_note_on_merge_request, noteable: merge_request)
2016-06-02 11:05:42 +05:30
url = described_class.build(note)
2020-03-13 15:44:24 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}#note_#{note.id}"
2016-06-02 11:05:42 +05:30
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-09-10 17:25:29 +05:30
expect(url).to eq "#{Settings.gitlab['url']}/#{project_snippet.project.full_path}/snippets/#{note.noteable_id}#note_#{note.id}"
end
end
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}"
2016-06-02 11:05:42 +05:30
end
end
context 'on another object' do
it 'returns a proper URL' do
2017-09-10 17:25:29 +05:30
project = build_stubbed(:project)
2016-06-02 11:05:42 +05:30
2017-09-10 17:25:29 +05:30
expect { described_class.build(project) }
2020-04-08 14:13:33 +05:30
.to raise_error(NotImplementedError, "No URL builder defined for #{project.inspect}")
2016-06-02 11:05:42 +05:30
end
end
2015-04-26 12:48:37 +05:30
end
2016-06-02 11:05:42 +05:30
context 'when passing a WikiPage' do
it 'returns a proper URL' do
wiki_page = build(:wiki_page)
url = described_class.build(wiki_page)
2015-04-26 12:48:37 +05:30
2016-06-02 11:05:42 +05:30
expect(url).to eq "#{Gitlab.config.gitlab.url}#{wiki_page.wiki.wiki_base_path}/#{wiki_page.slug}"
end
2014-09-02 18:07:02 +05:30
end
end
end