Commit ed4ce92b authored by Stan Hu's avatar Stan Hu

Merge branch 'fj-fix-snippets-routes' into 'master'

Fix bug with snippet refactored routes

See merge request gitlab-org/gitlab!21267
parents 961b92e5 05040d8c
......@@ -7,7 +7,7 @@ module AwardEmojiHelper
if awardable.is_a?(Note)
# We render a list of notes very frequently and calling the specific method is a lot faster than the generic one (4.5x)
if awardable.for_personal_snippet?
toggle_award_emoji_snippet_note_path(awardable.noteable, awardable)
gitlab_toggle_award_emoji_snippet_note_path(awardable.noteable, awardable)
else
toggle_award_emoji_project_note_path(@project, awardable.id)
end
......
......@@ -141,7 +141,7 @@ module BlobHelper
if @build && @entry
raw_project_job_artifacts_url(@project, @build, path: @entry.path, **kwargs)
elsif @snippet
raw_snippet_url(@snippet)
gitlab_raw_snippet_url(@snippet)
elsif @blob
project_raw_url(@project, @id, **kwargs)
end
......
......@@ -194,88 +194,84 @@ module GitlabRoutingHelper
take_ownership_project_pipeline_schedule_path(project, schedule, *args)
end
def snippet_path(snippet, *args)
if snippet.type == "ProjectSnippet"
application_url_helpers.project_snippet_path(snippet.project, snippet, *args)
def gitlab_snippet_path(snippet, *args)
if snippet.is_a?(ProjectSnippet)
project_snippet_path(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_path(snippet, *new_args)
snippet_path(snippet, *new_args)
end
end
def snippet_url(snippet, *args)
if snippet.type == "ProjectSnippet"
application_url_helpers.project_snippet_url(snippet.project, snippet, *args)
def gitlab_snippet_url(snippet, *args)
if snippet.is_a?(ProjectSnippet)
project_snippet_url(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_url(snippet, *new_args)
snippet_url(snippet, *new_args)
end
end
def raw_snippet_path(snippet, *args)
if snippet.type == "ProjectSnippet"
application_url_helpers.raw_project_snippet_path(snippet.project, snippet, *args)
def gitlab_raw_snippet_path(snippet, *args)
if snippet.is_a?(ProjectSnippet)
raw_project_snippet_path(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.raw_snippet_path(snippet, *new_args)
raw_snippet_path(snippet, *new_args)
end
end
def raw_snippet_url(snippet, *args)
if snippet.type == "ProjectSnippet"
application_url_helpers.raw_project_snippet_url(snippet.project, snippet, *args)
def gitlab_raw_snippet_url(snippet, *args)
if snippet.is_a?(ProjectSnippet)
raw_project_snippet_url(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.raw_snippet_url(snippet, *new_args)
raw_snippet_url(snippet, *new_args)
end
end
def snippet_notes_path(snippet, *args)
def gitlab_snippet_notes_path(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_notes_path(snippet, *new_args)
snippet_notes_path(snippet, *new_args)
end
def snippet_notes_url(snippet, *args)
def gitlab_snippet_notes_url(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_notes_url(snippet, *new_args)
snippet_notes_url(snippet, *new_args)
end
def snippet_note_path(snippet, note, *args)
def gitlab_snippet_note_path(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_note_path(snippet, note, *new_args)
snippet_note_path(snippet, note, *new_args)
end
def snippet_note_url(snippet, note, *args)
def gitlab_snippet_note_url(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_note_url(snippet, note, *new_args)
snippet_note_url(snippet, note, *new_args)
end
def toggle_award_emoji_snippet_note_path(snippet, note, *args)
def gitlab_toggle_award_emoji_snippet_note_path(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.toggle_award_emoji_snippet_note_path(snippet, note, *new_args)
toggle_award_emoji_snippet_note_path(snippet, note, *new_args)
end
def toggle_award_emoji_snippet_note_url(snippet, note, *args)
def gitlab_toggle_award_emoji_snippet_note_url(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.toggle_award_emoji_snippet_note_url(snippet, note, *new_args)
toggle_award_emoji_snippet_note_url(snippet, note, *new_args)
end
def toggle_award_emoji_snippet_path(snippet, *args)
def gitlab_toggle_award_emoji_snippet_path(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.toggle_award_emoji_snippet_path(snippet, *new_args)
toggle_award_emoji_snippet_path(snippet, *new_args)
end
def toggle_award_emoji_snippet_url(snippet, *args)
def gitlab_toggle_award_emoji_snippet_url(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.toggle_award_emoji_snippet_url(snippet, *new_args)
toggle_award_emoji_snippet_url(snippet, *new_args)
end
private
def application_url_helpers
Gitlab::Routing.url_helpers
end
def snippet_query_params(snippet, *args)
opts = case args.last
when Hash
......
......@@ -95,7 +95,7 @@ module NotesHelper
def notes_url(params = {})
if @snippet.is_a?(PersonalSnippet)
snippet_notes_path(@snippet, params)
gitlab_snippet_notes_path(@snippet, params)
else
params.merge!(target_id: @noteable.id, target_type: @noteable.class.name.underscore)
......@@ -105,7 +105,7 @@ module NotesHelper
def note_url(note, project = @project)
if note.noteable.is_a?(PersonalSnippet)
snippet_note_path(note.noteable, note)
gitlab_snippet_note_path(note.noteable, note)
else
project_note_path(project, note)
end
......@@ -126,7 +126,7 @@ module NotesHelper
def new_form_url
return unless @snippet.is_a?(PersonalSnippet)
snippet_notes_path(@snippet)
gitlab_snippet_notes_path(@snippet)
end
def can_create_note?
......
......@@ -13,7 +13,7 @@ module SnippetsHelper
def download_raw_snippet_button(snippet)
link_to(icon('download'),
raw_snippet_path(snippet, inline: false),
gitlab_raw_snippet_path(snippet, inline: false),
target: '_blank',
rel: 'noopener noreferrer',
class: "btn btn-sm has-tooltip",
......@@ -109,7 +109,7 @@ module SnippetsHelper
end
def snippet_embed_tag(snippet)
content_tag(:script, nil, src: snippet_url(snippet, format: :js))
content_tag(:script, nil, src: gitlab_snippet_url(snippet, format: :js))
end
def snippet_badge(snippet)
......@@ -134,7 +134,7 @@ module SnippetsHelper
return if blob.empty? || blob.binary? || blob.stored_externally?
link_to(external_snippet_icon('doc-code'),
raw_snippet_url(@snippet),
gitlab_raw_snippet_url(@snippet),
class: 'btn',
target: '_blank',
rel: 'noopener noreferrer',
......@@ -143,7 +143,7 @@ module SnippetsHelper
def embedded_snippet_download_button
link_to(external_snippet_icon('download'),
raw_snippet_url(@snippet, inline: false),
gitlab_raw_snippet_url(@snippet, inline: false),
class: 'btn',
target: '_blank',
title: 'Download',
......
......@@ -38,7 +38,7 @@ module Emails
setup_note_mail(note_id, recipient_id)
@snippet = @note.noteable
@target_url = snippet_url(@note.noteable)
@target_url = gitlab_snippet_url(@note.noteable)
mail_answer_note_thread(@snippet, @note, note_thread_options(recipient_id, reason))
end
......
- snippet_blob = chunk_snippet(snippet_blob, @search_term)
- snippet = snippet_blob[:snippet_object]
- snippet_chunks = snippet_blob[:snippet_chunks]
- snippet_path = snippet_path(snippet)
- snippet_path = gitlab_snippet_path(snippet)
.search-result-row
%span
......
.search-result-row
%h4.snippet-title.term
= link_to snippet_path(snippet_title) do
= link_to gitlab_snippet_path(snippet_title) do
= truncate(snippet_title.title, length: 60)
= snippet_badge(snippet_title)
%span.cgray.monospace.tiny.float-right.term
......
......@@ -5,7 +5,7 @@
= image_tag avatar_icon_for_user(snippet.author), class: "avatar s40 d-none d-sm-block", alt: ''
.title
= link_to snippet_path(snippet) do
= link_to gitlab_snippet_path(snippet) do
= snippet.title
- if snippet.file_name.present?
%span.snippet-filename.d-none.d-sm-inline-block.ml-2
......@@ -14,7 +14,7 @@
%ul.controls
%li
= link_to snippet_path(snippet, anchor: 'notes'), class: ('no-comments' if notes_count.zero?) do
= link_to gitlab_snippet_path(snippet, anchor: 'notes'), class: ('no-comments' if notes_count.zero?) do
= icon('comments')
= notes_count
%li
......
......@@ -5,7 +5,7 @@
= link_to edit_snippet_path(@snippet), class: "btn btn-grouped" do
= _("Edit")
- if can?(current_user, :admin_personal_snippet, @snippet)
= link_to snippet_path(@snippet), method: :delete, data: { confirm: _("Are you sure?") }, class: "btn btn-grouped btn-inverted btn-remove", title: _('Delete Snippet') do
= link_to gitlab_snippet_path(@snippet), method: :delete, data: { confirm: _("Are you sure?") }, class: "btn btn-grouped btn-inverted btn-remove", title: _('Delete Snippet') do
= _("Delete")
- if can?(current_user, :create_personal_snippet)
= link_to new_snippet_path, class: "btn btn-grouped btn-success btn-inverted", title: _("New snippet") do
......@@ -24,7 +24,7 @@
= _("New snippet")
- if can?(current_user, :admin_personal_snippet, @snippet)
%li
= link_to snippet_path(@snippet), method: :delete, data: { confirm: _("Are you sure?") }, title: _('Delete Snippet') do
= link_to gitlab_snippet_path(@snippet), method: :delete, data: { confirm: _("Are you sure?") }, title: _('Delete Snippet') do
= _("Delete")
- if can?(current_user, :update_personal_snippet, @snippet)
%li
......
......@@ -3,4 +3,4 @@
%h3.page-title
= _("Edit Snippet")
%hr
= render 'shared/snippets/form', url: snippet_path(@snippet)
= render 'shared/snippets/form', url: gitlab_snippet_path(@snippet)
---
title: Rename snippet refactored routes
merge_request: 21267
author:
type: fixed
......@@ -25,7 +25,7 @@ module Gitlab
when WikiPage
wiki_page_url
when Snippet
opts[:raw].present? ? raw_snippet_url(object) : snippet_url(object)
opts[:raw].present? ? gitlab_raw_snippet_url(object) : gitlab_snippet_url(object)
when Milestone
milestone_url(object)
when ::Ci::Build
......@@ -65,7 +65,7 @@ module Gitlab
merge_request_url(object.noteable, anchor: dom_id(object))
elsif object.for_snippet?
snippet_url(object.noteable, anchor: dom_id(object))
gitlab_snippet_url(object.noteable, anchor: dom_id(object))
end
end
......
......@@ -28,7 +28,7 @@ describe 'Projects > Snippets > User views snippets' do
end
it 'shows snippets' do
expect(page).to have_content(project_snippet.title)
expect(page).to have_link(project_snippet.title, href: project_snippet_path(project, project_snippet))
expect(page).not_to have_content(snippet.title)
end
end
......@@ -14,9 +14,9 @@ describe 'User Snippets' do
end
it 'View all of my snippets' do
expect(page).to have_content(public_snippet.title)
expect(page).to have_content(internal_snippet.title)
expect(page).to have_content(private_snippet.title)
expect(page).to have_link(public_snippet.title, href: snippet_path(public_snippet))
expect(page).to have_link(internal_snippet.title, href: snippet_path(internal_snippet))
expect(page).to have_link(private_snippet.title, href: snippet_path(private_snippet))
end
it 'View my public snippets' do
......
......@@ -118,91 +118,91 @@ describe GitlabRoutingHelper do
let_it_be(:project_snippet) { create(:project_snippet) }
let_it_be(:note) { create(:note_on_personal_snippet, noteable: personal_snippet) }
describe '#snippet_path' do
describe '#gitlab_snippet_path' do
it 'returns the personal snippet path' do
expect(snippet_path(personal_snippet)).to eq("/snippets/#{personal_snippet.id}")
expect(gitlab_snippet_path(personal_snippet)).to eq("/snippets/#{personal_snippet.id}")
end
it 'returns the project snippet path' do
expect(snippet_path(project_snippet)).to eq("/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}")
expect(gitlab_snippet_path(project_snippet)).to eq("/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}")
end
end
describe '#snippet_url' do
describe '#gitlab_snippet_url' do
it 'returns the personal snippet url' do
expect(snippet_url(personal_snippet)).to eq("#{Settings.gitlab['url']}/snippets/#{personal_snippet.id}")
expect(gitlab_snippet_url(personal_snippet)).to eq("http://test.host/snippets/#{personal_snippet.id}")
end
it 'returns the project snippet url' do
expect(snippet_url(project_snippet)).to eq("#{Settings.gitlab['url']}/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}")
expect(gitlab_snippet_url(project_snippet)).to eq("http://test.host/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}")
end
end
describe '#raw_snippet_path' do
describe '#gitlab_raw_snippet_path' do
it 'returns the raw personal snippet path' do
expect(raw_snippet_path(personal_snippet)).to eq("/snippets/#{personal_snippet.id}/raw")
expect(gitlab_raw_snippet_path(personal_snippet)).to eq("/snippets/#{personal_snippet.id}/raw")
end
it 'returns the raw project snippet path' do
expect(raw_snippet_path(project_snippet)).to eq("/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}/raw")
expect(gitlab_raw_snippet_path(project_snippet)).to eq("/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}/raw")
end
end
describe '#raw_snippet_url' do
describe '#gitlab_raw_snippet_url' do
it 'returns the raw personal snippet url' do
expect(raw_snippet_url(personal_snippet)).to eq("#{Settings.gitlab['url']}/snippets/#{personal_snippet.id}/raw")
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(raw_snippet_url(project_snippet)).to eq("#{Settings.gitlab['url']}/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}/raw")
expect(gitlab_raw_snippet_url(project_snippet)).to eq("http://test.host/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}/raw")
end
end
describe '#snippet_notes_path' do
describe '#gitlab_snippet_notes_path' do
it 'returns the notes path for the personal snippet' do
expect(snippet_notes_path(personal_snippet)).to eq("/snippets/#{personal_snippet.id}/notes")
expect(gitlab_snippet_notes_path(personal_snippet)).to eq("/snippets/#{personal_snippet.id}/notes")
end
end
describe '#snippet_notes_url' do
describe '#gitlab_snippet_notes_url' do
it 'returns the notes url for the personal snippet' do
expect(snippet_notes_url(personal_snippet)).to eq("#{Settings.gitlab['url']}/snippets/#{personal_snippet.id}/notes")
expect(gitlab_snippet_notes_url(personal_snippet)).to eq("http://test.host/snippets/#{personal_snippet.id}/notes")
end
end
describe '#snippet_note_path' do
describe '#gitlab_snippet_note_path' do
it 'returns the note path for the personal snippet' do
expect(snippet_note_path(personal_snippet, note)).to eq("/snippets/#{personal_snippet.id}/notes/#{note.id}")
expect(gitlab_snippet_note_path(personal_snippet, note)).to eq("/snippets/#{personal_snippet.id}/notes/#{note.id}")
end
end
describe '#snippet_note_url' do
describe '#gitlab_snippet_note_url' do
it 'returns the note url for the personal snippet' do
expect(snippet_note_url(personal_snippet, note)).to eq("#{Settings.gitlab['url']}/snippets/#{personal_snippet.id}/notes/#{note.id}")
expect(gitlab_snippet_note_url(personal_snippet, note)).to eq("http://test.host/snippets/#{personal_snippet.id}/notes/#{note.id}")
end
end
describe '#toggle_award_emoji_snippet_note_path' do
describe '#gitlab_toggle_award_emoji_snippet_note_path' do
it 'returns the note award emoji path for the personal snippet' do
expect(toggle_award_emoji_snippet_note_path(personal_snippet, note)).to eq("/snippets/#{personal_snippet.id}/notes/#{note.id}/toggle_award_emoji")
expect(gitlab_toggle_award_emoji_snippet_note_path(personal_snippet, note)).to eq("/snippets/#{personal_snippet.id}/notes/#{note.id}/toggle_award_emoji")
end
end
describe '#toggle_award_emoji_snippet_note_url' do
describe '#gitlab_toggle_award_emoji_snippet_note_url' do
it 'returns the note award emoji url for the personal snippet' do
expect(toggle_award_emoji_snippet_note_url(personal_snippet, note)).to eq("#{Settings.gitlab['url']}/snippets/#{personal_snippet.id}/notes/#{note.id}/toggle_award_emoji")
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")
end
end
describe '#toggle_award_emoji_snippet_path' do
describe '#gitlab_toggle_award_emoji_snippet_path' do
it 'returns the award emoji path for the personal snippet' do
expect(toggle_award_emoji_snippet_path(personal_snippet)).to eq("/snippets/#{personal_snippet.id}/toggle_award_emoji")
expect(gitlab_toggle_award_emoji_snippet_path(personal_snippet)).to eq("/snippets/#{personal_snippet.id}/toggle_award_emoji")
end
end
describe '#toggle_award_emoji_snippet_url' do
describe '#gitlab_toggle_award_emoji_snippet_url' do
it 'returns the award url for the personal snippet' do
expect(toggle_award_emoji_snippet_url(personal_snippet)).to eq("#{Settings.gitlab['url']}/snippets/#{personal_snippet.id}/toggle_award_emoji")
expect(gitlab_toggle_award_emoji_snippet_url(personal_snippet)).to eq("http://test.host/snippets/#{personal_snippet.id}/toggle_award_emoji")
end
end
end
......
......@@ -14,13 +14,13 @@ describe SnippetsHelper do
it 'returns view raw button of embedded snippets for personal snippets' do
@snippet = create(:personal_snippet, :public)
expect(subject).to eq(download_link("#{Settings.gitlab['url']}/snippets/#{@snippet.id}/raw"))
expect(subject).to eq(download_link("http://test.host/snippets/#{@snippet.id}/raw"))
end
it 'returns view raw button of embedded snippets for project snippets' do
@snippet = create(:project_snippet, :public)
expect(subject).to eq(download_link("#{Settings.gitlab['url']}/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw"))
expect(subject).to eq(download_link("http://test.host/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw"))
end
def download_link(url)
......@@ -34,13 +34,13 @@ describe SnippetsHelper do
it 'returns download button of embedded snippets for personal snippets' do
@snippet = create(:personal_snippet, :public)
expect(subject).to eq(download_link("#{Settings.gitlab['url']}/snippets/#{@snippet.id}/raw"))
expect(subject).to eq(download_link("http://test.host/snippets/#{@snippet.id}/raw"))
end
it 'returns download button of embedded snippets for project snippets' do
@snippet = create(:project_snippet, :public)
expect(subject).to eq(download_link("#{Settings.gitlab['url']}/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw"))
expect(subject).to eq(download_link("http://test.host/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw"))
end
def download_link(url)
......@@ -56,7 +56,7 @@ describe SnippetsHelper do
context 'public' do
it 'returns a script tag with the snippet full url' do
expect(subject).to eq(script_embed("#{Settings.gitlab['url']}/snippets/#{snippet.id}"))
expect(subject).to eq(script_embed("http://test.host/snippets/#{snippet.id}"))
end
end
end
......@@ -65,7 +65,7 @@ describe SnippetsHelper do
let(:snippet) { public_project_snippet }
it 'returns a script tag with the snippet full url' do
expect(subject).to eq(script_embed("#{Settings.gitlab['url']}/#{snippet.project.path_with_namespace}/snippets/#{snippet.id}"))
expect(subject).to eq(script_embed("http://test.host/#{snippet.project.path_with_namespace}/snippets/#{snippet.id}"))
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment