Commit c5cd1219 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'fj-overwrite-snippet-route-helpers' into 'master'

Refactor snippet route helpers

See merge request gitlab-org/gitlab!20478
parents 98a698ee 1e8eee9f
...@@ -141,7 +141,7 @@ module BlobHelper ...@@ -141,7 +141,7 @@ module BlobHelper
if @build && @entry if @build && @entry
raw_project_job_artifacts_url(@project, @build, path: @entry.path, **kwargs) raw_project_job_artifacts_url(@project, @build, path: @entry.path, **kwargs)
elsif @snippet elsif @snippet
reliable_raw_snippet_url(@snippet) raw_snippet_url(@snippet)
elsif @blob elsif @blob
project_raw_url(@project, @id, **kwargs) project_raw_url(@project, @id, **kwargs)
end end
......
...@@ -193,6 +193,101 @@ module GitlabRoutingHelper ...@@ -193,6 +193,101 @@ module GitlabRoutingHelper
project = schedule.project project = schedule.project
take_ownership_project_pipeline_schedule_path(project, schedule, *args) take_ownership_project_pipeline_schedule_path(project, schedule, *args)
end end
def snippet_path(snippet, *args)
if snippet.is_a?(ProjectSnippet)
application_url_helpers.project_snippet_path(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_path(snippet, *new_args)
end
end
def snippet_url(snippet, *args)
if snippet.is_a?(ProjectSnippet)
application_url_helpers.project_snippet_url(snippet.project, snippet, *args)
else
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_url(snippet, *new_args)
end
end
def raw_snippet_path(snippet, *args)
if snippet.is_a?(ProjectSnippet)
application_url_helpers.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)
end
end
def raw_snippet_url(snippet, *args)
if snippet.is_a?(ProjectSnippet)
application_url_helpers.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)
end
end
def snippet_notes_path(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_notes_path(snippet, *new_args)
end
def snippet_notes_url(snippet, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_notes_url(snippet, *new_args)
end
def snippet_note_path(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_note_path(snippet, note, *new_args)
end
def snippet_note_url(snippet, note, *args)
new_args = snippet_query_params(snippet, *args)
application_url_helpers.snippet_note_url(snippet, note, *new_args)
end
def 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)
end
def 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)
end
def 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)
end
def 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)
end
private
def application_url_helpers
Gitlab::Routing.url_helpers
end
def snippet_query_params(snippet, *args)
opts = case args.last
when Hash
args.pop
when ActionController::Parameters
args.pop.to_h
else
{}
end
args << opts
end
end end
GitlabRoutingHelper.include_if_ee('EE::GitlabRoutingHelper') GitlabRoutingHelper.include_if_ee('EE::GitlabRoutingHelper')
...@@ -11,33 +11,9 @@ module SnippetsHelper ...@@ -11,33 +11,9 @@ module SnippetsHelper
end end
end end
def reliable_snippet_path(snippet, opts = {})
reliable_snippet_url(snippet, opts.merge(only_path: true))
end
def reliable_raw_snippet_path(snippet, opts = {})
reliable_raw_snippet_url(snippet, opts.merge(only_path: true))
end
def reliable_snippet_url(snippet, opts = {})
if snippet.project_id?
project_snippet_url(snippet.project, snippet, nil, opts)
else
snippet_url(snippet, nil, opts)
end
end
def reliable_raw_snippet_url(snippet, opts = {})
if snippet.project_id?
raw_project_snippet_url(snippet.project, snippet, nil, opts)
else
raw_snippet_url(snippet, nil, opts)
end
end
def download_raw_snippet_button(snippet) def download_raw_snippet_button(snippet)
link_to(icon('download'), link_to(icon('download'),
reliable_raw_snippet_path(snippet, inline: false), raw_snippet_path(snippet, inline: false),
target: '_blank', target: '_blank',
rel: 'noopener noreferrer', rel: 'noopener noreferrer',
class: "btn btn-sm has-tooltip", class: "btn btn-sm has-tooltip",
...@@ -133,7 +109,7 @@ module SnippetsHelper ...@@ -133,7 +109,7 @@ module SnippetsHelper
end end
def snippet_embed_tag(snippet) def snippet_embed_tag(snippet)
content_tag(:script, nil, src: reliable_snippet_url(snippet, format: :js, only_path: false)) content_tag(:script, nil, src: snippet_url(snippet, format: :js))
end end
def snippet_badge(snippet) def snippet_badge(snippet)
...@@ -158,7 +134,7 @@ module SnippetsHelper ...@@ -158,7 +134,7 @@ module SnippetsHelper
return if blob.empty? || blob.binary? || blob.stored_externally? return if blob.empty? || blob.binary? || blob.stored_externally?
link_to(external_snippet_icon('doc-code'), link_to(external_snippet_icon('doc-code'),
reliable_raw_snippet_url(@snippet), raw_snippet_url(@snippet),
class: 'btn', class: 'btn',
target: '_blank', target: '_blank',
rel: 'noopener noreferrer', rel: 'noopener noreferrer',
...@@ -167,7 +143,7 @@ module SnippetsHelper ...@@ -167,7 +143,7 @@ module SnippetsHelper
def embedded_snippet_download_button def embedded_snippet_download_button
link_to(external_snippet_icon('download'), link_to(external_snippet_icon('download'),
reliable_raw_snippet_url(@snippet, inline: false), raw_snippet_url(@snippet, inline: false),
class: 'btn', class: 'btn',
target: '_blank', target: '_blank',
title: 'Download', title: 'Download',
......
- snippet_blob = chunk_snippet(snippet_blob, @search_term) - snippet_blob = chunk_snippet(snippet_blob, @search_term)
- snippet = snippet_blob[:snippet_object] - snippet = snippet_blob[:snippet_object]
- snippet_chunks = snippet_blob[:snippet_chunks] - snippet_chunks = snippet_blob[:snippet_chunks]
- snippet_path = reliable_snippet_path(snippet) - snippet_path = snippet_path(snippet)
.search-result-row .search-result-row
%span %span
......
.search-result-row .search-result-row
%h4.snippet-title.term %h4.snippet-title.term
= link_to reliable_snippet_path(snippet_title) do = link_to snippet_path(snippet_title) do
= truncate(snippet_title.title, length: 60) = truncate(snippet_title.title, length: 60)
= snippet_badge(snippet_title) = snippet_badge(snippet_title)
%span.cgray.monospace.tiny.float-right.term %span.cgray.monospace.tiny.float-right.term
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
= image_tag avatar_icon_for_user(snippet.author), class: "avatar s40 d-none d-sm-block", alt: '' = image_tag avatar_icon_for_user(snippet.author), class: "avatar s40 d-none d-sm-block", alt: ''
.title .title
= link_to reliable_snippet_path(snippet) do = link_to snippet_path(snippet) do
= snippet.title = snippet.title
- if snippet.file_name.present? - if snippet.file_name.present?
%span.snippet-filename.d-none.d-sm-inline-block.ml-2 %span.snippet-filename.d-none.d-sm-inline-block.ml-2
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
%ul.controls %ul.controls
%li %li
= link_to reliable_snippet_path(snippet, anchor: 'notes'), class: ('no-comments' if notes_count.zero?) do = link_to snippet_path(snippet, anchor: 'notes'), class: ('no-comments' if notes_count.zero?) do
= icon('comments') = icon('comments')
= notes_count = notes_count
%li %li
......
...@@ -532,7 +532,7 @@ module API ...@@ -532,7 +532,7 @@ module API
class PersonalSnippet < Snippet class PersonalSnippet < Snippet
expose :raw_url do |snippet| expose :raw_url do |snippet|
Gitlab::UrlBuilder.build(snippet) + "/raw" Gitlab::UrlBuilder.build(snippet, raw: true)
end end
end end
......
...@@ -6,10 +6,10 @@ module Gitlab ...@@ -6,10 +6,10 @@ module Gitlab
include GitlabRoutingHelper include GitlabRoutingHelper
include ActionView::RecordIdentifier include ActionView::RecordIdentifier
attr_reader :object attr_reader :object, :opts
def self.build(object) def self.build(object, opts = {})
new(object).url new(object, opts).url
end end
def url def url
...@@ -24,10 +24,8 @@ module Gitlab ...@@ -24,10 +24,8 @@ module Gitlab
note_url note_url
when WikiPage when WikiPage
wiki_page_url wiki_page_url
when ProjectSnippet
project_snippet_url(object.project, object)
when Snippet when Snippet
snippet_url(object) opts[:raw].present? ? raw_snippet_url(object) : snippet_url(object)
when Milestone when Milestone
milestone_url(object) milestone_url(object)
when ::Ci::Build when ::Ci::Build
...@@ -41,8 +39,9 @@ module Gitlab ...@@ -41,8 +39,9 @@ module Gitlab
private private
def initialize(object) def initialize(object, opts = {})
@object = object @object = object
@opts = opts
end end
def commit_url(opts = {}) def commit_url(opts = {})
...@@ -66,13 +65,7 @@ module Gitlab ...@@ -66,13 +65,7 @@ module Gitlab
merge_request_url(object.noteable, anchor: dom_id(object)) merge_request_url(object.noteable, anchor: dom_id(object))
elsif object.for_snippet? elsif object.for_snippet?
snippet = object.noteable snippet_url(object.noteable, anchor: dom_id(object))
if snippet.is_a?(PersonalSnippet)
snippet_url(snippet, anchor: dom_id(object))
else
project_snippet_url(snippet.project, snippet, anchor: dom_id(object))
end
end end
end end
......
...@@ -4,59 +4,69 @@ require 'spec_helper' ...@@ -4,59 +4,69 @@ require 'spec_helper'
describe AwardEmojiHelper do describe AwardEmojiHelper do
describe '.toggle_award_url' do describe '.toggle_award_url' do
subject { helper.toggle_award_url(awardable) }
context 'note on personal snippet' do context 'note on personal snippet' do
let(:note) { create(:note_on_personal_snippet) } let(:snippet) { create(:personal_snippet) }
let(:note) { create(:note_on_personal_snippet, noteable: snippet) }
let(:awardable) { note }
subject { helper.toggle_award_url(note) }
it 'returns correct url' do it 'returns correct url' do
expected_url = "/snippets/#{note.noteable.id}/notes/#{note.id}/toggle_award_emoji" expected_url = "/snippets/#{note.noteable.id}/notes/#{note.id}/toggle_award_emoji"
expect(helper.toggle_award_url(note)).to eq(expected_url) expect(subject).to eq(expected_url)
end end
end end
context 'note on project item' do context 'note on project item' do
let(:note) { create(:note_on_project_snippet) } let(:note) { create(:note_on_project_snippet) }
let(:awardable) { note }
it 'returns correct url' do it 'returns correct url' do
@project = note.noteable.project @project = note.noteable.project
expected_url = "/#{@project.namespace.path}/#{@project.path}/notes/#{note.id}/toggle_award_emoji" expected_url = "/#{@project.namespace.path}/#{@project.path}/notes/#{note.id}/toggle_award_emoji"
expect(helper.toggle_award_url(note)).to eq(expected_url) expect(subject).to eq(expected_url)
end end
end end
context 'personal snippet' do context 'personal snippet' do
let(:snippet) { create(:personal_snippet) } let(:snippet) { create(:personal_snippet) }
let(:awardable) { snippet }
it 'returns correct url' do it 'returns correct url' do
expected_url = "/snippets/#{snippet.id}/toggle_award_emoji" expected_url = "/snippets/#{snippet.id}/toggle_award_emoji"
expect(helper.toggle_award_url(snippet)).to eq(expected_url) expect(subject).to eq(expected_url)
end end
end end
context 'merge request' do context 'merge request' do
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
let(:awardable) { merge_request }
it 'returns correct url' do it 'returns correct url' do
@project = merge_request.project @project = merge_request.project
expected_url = "/#{@project.namespace.path}/#{@project.path}/merge_requests/#{merge_request.iid}/toggle_award_emoji" expected_url = "/#{@project.namespace.path}/#{@project.path}/merge_requests/#{merge_request.iid}/toggle_award_emoji"
expect(helper.toggle_award_url(merge_request)).to eq(expected_url) expect(subject).to eq(expected_url)
end end
end end
context 'issue' do context 'issue' do
let(:issue) { create(:issue) } let(:issue) { create(:issue) }
let(:awardable) { issue }
it 'returns correct url' do it 'returns correct url' do
@project = issue.project @project = issue.project
expected_url = "/#{@project.namespace.path}/#{@project.path}/issues/#{issue.iid}/toggle_award_emoji" expected_url = "/#{@project.namespace.path}/#{@project.path}/issues/#{issue.iid}/toggle_award_emoji"
expect(helper.toggle_award_url(issue)).to eq(expected_url) expect(subject).to eq(expected_url)
end end
end end
end end
......
...@@ -112,4 +112,98 @@ describe GitlabRoutingHelper do ...@@ -112,4 +112,98 @@ describe GitlabRoutingHelper do
expect(edit_milestone_path(milestone)).to eq("/#{milestone.project.full_path}/-/milestones/#{milestone.iid}/edit") expect(edit_milestone_path(milestone)).to eq("/#{milestone.project.full_path}/-/milestones/#{milestone.iid}/edit")
end end
end end
context 'snippets' do
let_it_be(:personal_snippet) { create(:personal_snippet) }
let_it_be(:project_snippet) { create(:project_snippet) }
let_it_be(:note) { create(:note_on_personal_snippet, noteable: personal_snippet) }
describe '#snippet_path' do
it 'returns the personal snippet path' do
expect(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}")
end
end
describe '#snippet_url' do
it 'returns the personal snippet url' do
expect(snippet_url(personal_snippet)).to eq("#{Settings.gitlab['url']}/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}")
end
end
describe '#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")
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")
end
end
describe '#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")
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")
end
end
describe '#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")
end
end
describe '#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")
end
end
describe '#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}")
end
end
describe '#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}")
end
end
describe '#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")
end
end
describe '#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")
end
end
describe '#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")
end
end
describe '#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")
end
end
end
end end
...@@ -9,107 +9,18 @@ describe SnippetsHelper do ...@@ -9,107 +9,18 @@ describe SnippetsHelper do
let_it_be(:public_personal_snippet) { create(:personal_snippet, :public) } let_it_be(:public_personal_snippet) { create(:personal_snippet, :public) }
let_it_be(:public_project_snippet) { create(:project_snippet, :public) } let_it_be(:public_project_snippet) { create(:project_snippet, :public) }
describe '#reliable_snippet_path' do
subject { reliable_snippet_path(snippet) }
context 'personal snippets' do
let(:snippet) { public_personal_snippet }
context 'public' do
it 'returns a full path' do
expect(subject).to eq("/snippets/#{snippet.id}")
end
end
end
context 'project snippets' do
let(:snippet) { public_project_snippet }
it 'returns a full path' do
expect(subject).to eq("/#{snippet.project.full_path}/snippets/#{snippet.id}")
end
end
end
describe '#reliable_snippet_url' do
subject { reliable_snippet_url(snippet) }
context 'personal snippets' do
let(:snippet) { public_personal_snippet }
context 'public' do
it 'returns a full url' do
expect(subject).to eq("http://test.host/snippets/#{snippet.id}")
end
end
end
context 'project snippets' do
let(:snippet) { public_project_snippet }
it 'returns a full url' do
expect(subject).to eq("http://test.host/#{snippet.project.full_path}/snippets/#{snippet.id}")
end
end
end
describe '#reliable_raw_snippet_path' do
subject { reliable_raw_snippet_path(snippet) }
context 'personal snippets' do
let(:snippet) { public_personal_snippet }
context 'public' do
it 'returns a full path' do
expect(subject).to eq("/snippets/#{snippet.id}/raw")
end
end
end
context 'project snippets' do
let(:snippet) { public_project_snippet }
it 'returns a full path' do
expect(subject).to eq("/#{snippet.project.full_path}/snippets/#{snippet.id}/raw")
end
end
end
describe '#reliable_raw_snippet_url' do
subject { reliable_raw_snippet_url(snippet) }
context 'personal snippets' do
let(:snippet) { public_personal_snippet }
context 'public' do
it 'returns a full url' do
expect(subject).to eq("http://test.host/snippets/#{snippet.id}/raw")
end
end
end
context 'project snippets' do
let(:snippet) { public_project_snippet }
it 'returns a full url' do
expect(subject).to eq("http://test.host/#{snippet.project.full_path}/snippets/#{snippet.id}/raw")
end
end
end
describe '#embedded_raw_snippet_button' do describe '#embedded_raw_snippet_button' do
subject { embedded_raw_snippet_button.to_s } subject { embedded_raw_snippet_button.to_s }
it 'returns view raw button of embedded snippets for personal snippets' do it 'returns view raw button of embedded snippets for personal snippets' do
@snippet = create(:personal_snippet, :public) @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 end
it 'returns view raw button of embedded snippets for project snippets' do it 'returns view raw button of embedded snippets for project snippets' do
@snippet = create(:project_snippet, :public) @snippet = create(:project_snippet, :public)
expect(subject).to eq(download_link("http://test.host/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw")) expect(subject).to eq(download_link("#{Settings.gitlab['url']}/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw"))
end end
def download_link(url) def download_link(url)
...@@ -123,13 +34,13 @@ describe SnippetsHelper do ...@@ -123,13 +34,13 @@ describe SnippetsHelper do
it 'returns download button of embedded snippets for personal snippets' do it 'returns download button of embedded snippets for personal snippets' do
@snippet = create(:personal_snippet, :public) @snippet = create(:personal_snippet, :public)
expect(subject).to eq(download_link("http://test.host/snippets/#{@snippet.id}/raw")) expect(subject).to eq(download_link("#{Settings.gitlab['url']}/snippets/#{@snippet.id}/raw"))
end end
it 'returns download button of embedded snippets for project snippets' do it 'returns download button of embedded snippets for project snippets' do
@snippet = create(:project_snippet, :public) @snippet = create(:project_snippet, :public)
expect(subject).to eq(download_link("http://test.host/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw")) expect(subject).to eq(download_link("#{Settings.gitlab['url']}/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw"))
end end
def download_link(url) def download_link(url)
...@@ -145,7 +56,7 @@ describe SnippetsHelper do ...@@ -145,7 +56,7 @@ describe SnippetsHelper do
context 'public' do context 'public' do
it 'returns a script tag with the snippet full url' do it 'returns a script tag with the snippet full url' do
expect(subject).to eq(script_embed("http://test.host/snippets/#{snippet.id}")) expect(subject).to eq(script_embed("#{Settings.gitlab['url']}/snippets/#{snippet.id}"))
end end
end end
end end
...@@ -154,7 +65,7 @@ describe SnippetsHelper do ...@@ -154,7 +65,7 @@ describe SnippetsHelper do
let(:snippet) { public_project_snippet } let(:snippet) { public_project_snippet }
it 'returns a script tag with the snippet full url' do it 'returns a script tag with the snippet full url' do
expect(subject).to eq(script_embed("http://test.host/#{snippet.project.path_with_namespace}/snippets/#{snippet.id}")) expect(subject).to eq(script_embed("#{Settings.gitlab['url']}/#{snippet.project.path_with_namespace}/snippets/#{snippet.id}"))
end end
end end
......
...@@ -59,6 +59,26 @@ describe Gitlab::UrlBuilder do ...@@ -59,6 +59,26 @@ describe Gitlab::UrlBuilder do
end end
end end
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
context 'when passing a Note' do context 'when passing a Note' do
context 'on a Commit' do context 'on a Commit' do
it 'returns a proper URL' do it 'returns a proper URL' do
......
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