Commit 144c54e2 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '335636-fj-fix-snippet-route-helper-when-ref-is-not-passed' into 'master'

Fix snippet url helper when repository is not present

See merge request gitlab-org/gitlab!66149
parents 014c5c85 e702e4c9
...@@ -49,7 +49,7 @@ module Routing ...@@ -49,7 +49,7 @@ module Routing
def gitlab_raw_snippet_blob_url(snippet, path, ref = nil, **options) def gitlab_raw_snippet_blob_url(snippet, path, ref = nil, **options)
params = { params = {
snippet_id: snippet, snippet_id: snippet,
ref: ref || snippet.repository.root_ref, ref: ref || snippet.default_branch,
path: path path: path
} }
......
...@@ -239,8 +239,9 @@ RSpec.describe GitlabRoutingHelper do ...@@ -239,8 +239,9 @@ RSpec.describe GitlabRoutingHelper do
let(:blob) { snippet.blobs.first } let(:blob) { snippet.blobs.first }
let(:ref) { 'snippet-test-ref' } let(:ref) { 'snippet-test-ref' }
let(:args) { {} } let(:args) { {} }
let(:path) { blob.path }
subject { gitlab_raw_snippet_blob_url(snippet, blob.path, ref, **args) } subject { gitlab_raw_snippet_blob_url(snippet, path, ref, **args) }
it_behaves_like 'snippet blob raw url' it_behaves_like 'snippet blob raw url'
...@@ -248,7 +249,7 @@ RSpec.describe GitlabRoutingHelper do ...@@ -248,7 +249,7 @@ RSpec.describe GitlabRoutingHelper do
let(:args) { { inline: true } } let(:args) { { inline: true } }
let(:snippet) { personal_snippet } let(:snippet) { personal_snippet }
it { expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}?inline=true") } it { expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{ref}/#{path}?inline=true") }
end end
context 'without a ref' do context 'without a ref' do
...@@ -257,7 +258,17 @@ RSpec.describe GitlabRoutingHelper do ...@@ -257,7 +258,17 @@ RSpec.describe GitlabRoutingHelper do
let(:expected_ref) { snippet.repository.root_ref } let(:expected_ref) { snippet.repository.root_ref }
it 'uses the root ref' do it 'uses the root ref' do
expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{expected_ref}/#{blob.path}") expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{expected_ref}/#{path}")
end
context 'when snippet does not have a repository' do
let(:snippet) { create(:personal_snippet) }
let(:path) { 'example' }
let(:expected_ref) { Gitlab::DefaultBranch.value }
it 'uses the instance deafult branch' do
expect(subject).to eq("http://test.host/-/snippets/#{snippet.id}/raw/#{expected_ref}/#{path}")
end
end end
end end
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