2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe GitlabRoutingHelper do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { build_stubbed(:project) }
|
2017-07-31 12:33:57 -04:00
|
|
|
let(:group) { build_stubbed(:group) }
|
|
|
|
|
2016-06-02 12:05:06 -04:00
|
|
|
describe 'Project URL helpers' do
|
|
|
|
describe '#project_member_path' do
|
|
|
|
let(:project_member) { create(:project_member) }
|
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
it { expect(project_member_path(project_member)).to eq project_project_member_path(project_member.source, project_member) }
|
2016-06-02 12:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#request_access_project_members_path' do
|
2017-06-29 13:06:35 -04:00
|
|
|
it { expect(request_access_project_members_path(project)).to eq request_access_project_project_members_path(project) }
|
2016-06-02 12:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#leave_project_members_path' do
|
2017-06-29 13:06:35 -04:00
|
|
|
it { expect(leave_project_members_path(project)).to eq leave_project_project_members_path(project) }
|
2016-06-02 12:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#approve_access_request_project_member_path' do
|
|
|
|
let(:project_member) { create(:project_member) }
|
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
it { expect(approve_access_request_project_member_path(project_member)).to eq approve_access_request_project_project_member_path(project_member.source, project_member) }
|
2016-06-02 12:05:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resend_invite_project_member_path' do
|
|
|
|
let(:project_member) { create(:project_member) }
|
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
it { expect(resend_invite_project_member_path(project_member)).to eq resend_invite_project_project_member_path(project_member.source, project_member) }
|
2016-06-02 12:05:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Group URL helpers' do
|
|
|
|
describe '#group_members_url' do
|
|
|
|
it { expect(group_members_url(group)).to eq group_group_members_url(group) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#group_member_path' do
|
|
|
|
let(:group_member) { create(:group_member) }
|
|
|
|
|
|
|
|
it { expect(group_member_path(group_member)).to eq group_group_member_path(group_member.source, group_member) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#request_access_group_members_path' do
|
|
|
|
it { expect(request_access_group_members_path(group)).to eq request_access_group_group_members_path(group) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#leave_group_members_path' do
|
|
|
|
it { expect(leave_group_members_path(group)).to eq leave_group_group_members_path(group) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#approve_access_request_group_member_path' do
|
|
|
|
let(:group_member) { create(:group_member) }
|
|
|
|
|
|
|
|
it { expect(approve_access_request_group_member_path(group_member)).to eq approve_access_request_group_group_member_path(group_member.source, group_member) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#resend_invite_group_member_path' do
|
|
|
|
let(:group_member) { create(:group_member) }
|
|
|
|
|
|
|
|
it { expect(resend_invite_group_member_path(group_member)).to eq resend_invite_group_group_member_path(group_member.source, group_member) }
|
|
|
|
end
|
|
|
|
end
|
2017-11-01 13:35:14 -04:00
|
|
|
|
|
|
|
describe '#preview_markdown_path' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
it 'returns group preview markdown path for a group parent' do
|
|
|
|
group = create(:group)
|
|
|
|
|
|
|
|
expect(preview_markdown_path(group)).to eq("/groups/#{group.path}/preview_markdown")
|
|
|
|
end
|
|
|
|
|
2019-10-29 08:06:40 -04:00
|
|
|
it 'returns group preview markdown path for a group parent with args' do
|
|
|
|
group = create(:group)
|
|
|
|
|
|
|
|
expect(preview_markdown_path(group, { type_id: 5 })).to eq("/groups/#{group.path}/preview_markdown?type_id=5")
|
|
|
|
end
|
|
|
|
|
2017-11-01 13:35:14 -04:00
|
|
|
it 'returns project preview markdown path for a project parent' do
|
|
|
|
expect(preview_markdown_path(project)).to eq("/#{project.full_path}/preview_markdown")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns snippet preview markdown path for a personal snippet' do
|
|
|
|
@snippet = create(:personal_snippet)
|
|
|
|
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(preview_markdown_path(nil)).to eq("/-/snippets/preview_markdown")
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns project preview markdown path for a project snippet' do
|
|
|
|
@snippet = create(:project_snippet, project: project)
|
|
|
|
|
|
|
|
expect(preview_markdown_path(project)).to eq("/#{project.full_path}/preview_markdown")
|
|
|
|
end
|
|
|
|
end
|
2018-04-20 12:03:47 -04:00
|
|
|
|
|
|
|
describe '#edit_milestone_path' do
|
|
|
|
it 'returns group milestone edit path when given entity parent is a Group' do
|
|
|
|
group = create(:group)
|
|
|
|
milestone = create(:milestone, group: group)
|
|
|
|
|
|
|
|
expect(edit_milestone_path(milestone)).to eq("/groups/#{group.path}/-/milestones/#{milestone.iid}/edit")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns project milestone edit path when given entity parent is not a Group' do
|
|
|
|
milestone = create(:milestone, group: nil)
|
|
|
|
|
2019-05-29 06:45:27 -04:00
|
|
|
expect(edit_milestone_path(milestone)).to eq("/#{milestone.project.full_path}/-/milestones/#{milestone.iid}/edit")
|
2018-04-20 12:03:47 -04:00
|
|
|
end
|
|
|
|
end
|
2019-11-28 10:06:57 -05:00
|
|
|
|
2019-12-25 13:07:46 -05:00
|
|
|
context 'artifacts' do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:job) { create(:ci_build, project: project, name: 'test:job', artifacts_expire_at: 1.hour.from_now) }
|
|
|
|
|
|
|
|
describe '#fast_download_project_job_artifacts_path' do
|
|
|
|
it 'matches the Rails download path' do
|
|
|
|
expect(fast_download_project_job_artifacts_path(project, job)).to eq(download_project_job_artifacts_path(project, job))
|
|
|
|
end
|
2020-06-04 08:08:21 -04:00
|
|
|
|
|
|
|
context 'when given parameters' do
|
|
|
|
it 'adds them to the path' do
|
|
|
|
expect(
|
|
|
|
fast_download_project_job_artifacts_path(project, job, file_type: :dast)
|
|
|
|
).to eq(
|
|
|
|
download_project_job_artifacts_path(project, job, file_type: :dast)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2019-12-25 13:07:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#fast_keep_project_job_artifacts_path' do
|
|
|
|
it 'matches the Rails keep path' do
|
|
|
|
expect(fast_keep_project_job_artifacts_path(project, job)).to eq(keep_project_job_artifacts_path(project, job))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#fast_browse_project_job_artifacts_path' do
|
|
|
|
it 'matches the Rails browse path' do
|
|
|
|
expect(fast_browse_project_job_artifacts_path(project, job)).to eq(browse_project_job_artifacts_path(project, job))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-28 10:06:57 -05:00
|
|
|
context 'snippets' do
|
2020-07-01 11:08:45 -04:00
|
|
|
let_it_be(:personal_snippet) { create(:personal_snippet, :repository) }
|
|
|
|
let_it_be(:project_snippet) { create(:project_snippet, :repository) }
|
2019-11-28 10:06:57 -05:00
|
|
|
let_it_be(:note) { create(:note_on_personal_snippet, noteable: personal_snippet) }
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_snippet_path' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the personal snippet path' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_snippet_path(personal_snippet)).to eq("/-/snippets/#{personal_snippet.id}")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the project snippet path' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_snippet_path(project_snippet)).to eq("/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_snippet_url' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the personal snippet url' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_snippet_url(personal_snippet)).to eq("http://test.host/-/snippets/#{personal_snippet.id}")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the project snippet url' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_snippet_url(project_snippet)).to eq("http://test.host/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_raw_snippet_path' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the raw personal snippet path' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_raw_snippet_path(personal_snippet)).to eq("/-/snippets/#{personal_snippet.id}/raw")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the raw project snippet path' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_raw_snippet_path(project_snippet)).to eq("/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}/raw")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-06 14:09:13 -04:00
|
|
|
describe '#gitlab_raw_snippet_blob_path' do
|
2020-07-22 05:09:38 -04:00
|
|
|
let(:snippet) { personal_snippet }
|
|
|
|
let(:blob) { snippet.blobs.first }
|
2020-07-06 14:09:13 -04:00
|
|
|
let(:ref) { 'test-ref' }
|
2020-07-22 05:09:38 -04:00
|
|
|
let(:args) { {} }
|
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
subject { gitlab_raw_snippet_blob_path(snippet, blob.path, ref, **args) }
|
2020-07-22 05:09:38 -04:00
|
|
|
|
|
|
|
it_behaves_like 'snippet blob raw path'
|
|
|
|
|
|
|
|
context 'when an argument is set' do
|
|
|
|
let(:args) { { inline: true } }
|
2020-07-06 14:09:13 -04:00
|
|
|
|
2020-07-22 05:09:38 -04:00
|
|
|
it { expect(subject).to eq("/-/snippets/#{personal_snippet.id}/raw/#{ref}/#{blob.path}?inline=true") }
|
2020-07-06 14:09:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a ref' do
|
2020-07-22 05:09:38 -04:00
|
|
|
let(:ref) { nil }
|
|
|
|
let(:expected_ref) { blob.repository.root_ref }
|
2020-07-06 14:09:13 -04:00
|
|
|
|
|
|
|
it 'uses the root ref' do
|
2020-07-22 05:09:38 -04:00
|
|
|
expect(subject).to eq("/-/snippets/#{personal_snippet.id}/raw/#{expected_ref}/#{blob.path}")
|
2020-07-06 14:09:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-23 11:09:28 -04:00
|
|
|
describe '#gitlab_raw_snippet_url' do
|
|
|
|
it 'returns the raw personal snippet url' do
|
|
|
|
expect(gitlab_raw_snippet_url(personal_snippet)).to eq("http://test.host/-/snippets/#{personal_snippet.id}/raw")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the raw project snippet url' do
|
|
|
|
expect(gitlab_raw_snippet_url(project_snippet)).to eq("http://test.host/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}/raw")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-01 11:08:45 -04:00
|
|
|
describe '#gitlab_raw_snippet_blob_url' do
|
|
|
|
let(:blob) { snippet.blobs.first }
|
|
|
|
let(:ref) { 'snippet-test-ref' }
|
2020-07-22 05:09:38 -04:00
|
|
|
let(:args) { {} }
|
|
|
|
|
2020-09-28 08:10:02 -04:00
|
|
|
subject { gitlab_raw_snippet_blob_url(snippet, blob.path, ref, **args) }
|
2020-07-01 11:08:45 -04:00
|
|
|
|
2020-08-18 08:10:16 -04:00
|
|
|
it_behaves_like 'snippet blob raw url'
|
2020-07-22 05:09:38 -04:00
|
|
|
|
|
|
|
context 'when an argument is set' do
|
|
|
|
let(:args) { { inline: true } }
|
|
|
|
let(:snippet) { personal_snippet }
|
|
|
|
|
|
|
|
it { expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}?inline=true") }
|
2020-07-01 11:08:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'without a ref' do
|
|
|
|
let(:snippet) { personal_snippet }
|
2020-07-22 05:09:38 -04:00
|
|
|
let(:ref) { nil }
|
|
|
|
let(:expected_ref) { snippet.repository.root_ref }
|
2020-07-01 11:08:45 -04:00
|
|
|
|
|
|
|
it 'uses the root ref' do
|
2020-07-22 05:09:38 -04:00
|
|
|
expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{expected_ref}/#{blob.path}")
|
2020-07-01 11:08:45 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-22 05:09:38 -04:00
|
|
|
describe '#gitlab_raw_snippet_url' do
|
|
|
|
it 'returns the raw personal snippet url' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_raw_snippet_url(personal_snippet)).to eq("http://test.host/-/snippets/#{personal_snippet.id}/raw")
|
2020-07-22 05:09:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the raw project snippet url' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_raw_snippet_url(project_snippet)).to eq("http://test.host/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}/raw")
|
2020-07-22 05:09:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_snippet_notes_path' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the notes path for the personal snippet' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_snippet_notes_path(personal_snippet)).to eq("/-/snippets/#{personal_snippet.id}/notes")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_snippet_notes_url' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the notes url for the personal snippet' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_snippet_notes_url(personal_snippet)).to eq("http://test.host/-/snippets/#{personal_snippet.id}/notes")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_snippet_note_path' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the note path for the personal snippet' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_snippet_note_path(personal_snippet, note)).to eq("/-/snippets/#{personal_snippet.id}/notes/#{note.id}")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_snippet_note_url' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the note url for the personal snippet' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_snippet_note_url(personal_snippet, note)).to eq("http://test.host/-/snippets/#{personal_snippet.id}/notes/#{note.id}")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_toggle_award_emoji_snippet_note_path' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the note award emoji path for the personal snippet' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_toggle_award_emoji_snippet_note_path(personal_snippet, note)).to eq("/-/snippets/#{personal_snippet.id}/notes/#{note.id}/toggle_award_emoji")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_toggle_award_emoji_snippet_note_url' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the note award emoji url for the personal snippet' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_toggle_award_emoji_snippet_note_url(personal_snippet, note)).to eq("http://test.host/-/snippets/#{personal_snippet.id}/notes/#{note.id}/toggle_award_emoji")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_toggle_award_emoji_snippet_path' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the award emoji path for the personal snippet' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_toggle_award_emoji_snippet_path(personal_snippet)).to eq("/-/snippets/#{personal_snippet.id}/toggle_award_emoji")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-10 16:08:01 -05:00
|
|
|
describe '#gitlab_toggle_award_emoji_snippet_url' do
|
2019-11-28 10:06:57 -05:00
|
|
|
it 'returns the award url for the personal snippet' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_toggle_award_emoji_snippet_url(personal_snippet)).to eq("http://test.host/-/snippets/#{personal_snippet.id}/toggle_award_emoji")
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
|
|
|
end
|
2020-06-16 11:08:32 -04:00
|
|
|
|
|
|
|
describe '#gitlab_dashboard_snippets_path' do
|
|
|
|
it 'returns the personal snippets dashboard path' do
|
|
|
|
expect(gitlab_dashboard_snippets_path(personal_snippet)).to eq("/dashboard/snippets")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the project snippets dashboard path' do
|
2020-07-23 11:09:28 -04:00
|
|
|
expect(gitlab_dashboard_snippets_path(project_snippet)).to eq("/#{project_snippet.project.full_path}/-/snippets")
|
2020-06-16 11:08:32 -04:00
|
|
|
end
|
|
|
|
end
|
2019-11-28 10:06:57 -05:00
|
|
|
end
|
2020-06-03 20:08:17 -04:00
|
|
|
|
|
|
|
context 'wikis' do
|
|
|
|
let(:wiki) { create(:project_wiki) }
|
|
|
|
|
|
|
|
describe '#wiki_page_path' do
|
|
|
|
it 'returns the url for the wiki page' do
|
|
|
|
expect(wiki_page_path(wiki, 'page')).to eq("/#{wiki.project.full_path}/-/wikis/page")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-11-06 19:08:58 -05:00
|
|
|
|
|
|
|
context 'releases' do
|
|
|
|
let(:release) { create(:release) }
|
|
|
|
|
|
|
|
describe '#release_url' do
|
|
|
|
it 'returns the url for the release page' do
|
|
|
|
expect(release_url(release)).to eq("http://test.host/#{release.project.full_path}/-/releases/#{release.tag}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-02 13:11:20 -05:00
|
|
|
|
|
|
|
context 'GraphQL ETag paths' do
|
|
|
|
context 'with pipelines' do
|
|
|
|
let(:pipeline) { double(id: 5) }
|
|
|
|
|
|
|
|
it 'returns an ETag path for pipelines' do
|
|
|
|
expect(graphql_etag_pipeline_path(pipeline)).to eq('/api/graphql:pipelines/id/5')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-02 12:05:06 -04:00
|
|
|
end
|