Commit fb76e31e authored by Mike Kozono's avatar Mike Kozono Committed by Francisco Javier López

Geo: Fix single-file snippets

Until snippet repo replication is released, this will maintain existing
behavior on Geo secondaries.
parent 2e1b16f4
...@@ -48,6 +48,8 @@ class SnippetBlobPresenter < BlobPresenter ...@@ -48,6 +48,8 @@ class SnippetBlobPresenter < BlobPresenter
end end
def snippet_blob_raw_route(only_path: false) def snippet_blob_raw_route(only_path: false)
return gitlab_raw_snippet_url(snippet, only_path: only_path) unless snippet.repository_exists?
gitlab_raw_snippet_blob_url(snippet, blob.path, only_path: only_path) gitlab_raw_snippet_blob_url(snippet, blob.path, only_path: only_path)
end end
end end
---
title: 'Geo: Fix single-file snippets on Geo secondaries'
merge_request: 44532
author:
type: fixed
...@@ -125,24 +125,70 @@ RSpec.describe SnippetBlobPresenter do ...@@ -125,24 +125,70 @@ RSpec.describe SnippetBlobPresenter do
let_it_be(:personal_snippet) { create(:personal_snippet, :repository, author: user) } let_it_be(:personal_snippet) { create(:personal_snippet, :repository, author: user) }
let_it_be(:project_snippet) { create(:project_snippet, :repository, project: project, author: user) } let_it_be(:project_snippet) { create(:project_snippet, :repository, project: project, author: user) }
let(:blob) { snippet.blobs.first }
before do before do
project.add_developer(user) project.add_developer(user)
end end
describe '#raw_path' do describe '#raw_path' do
subject { described_class.new(snippet.blobs.first, current_user: user).raw_path } subject { described_class.new(blob, current_user: user).raw_path }
it_behaves_like 'snippet blob raw path' it_behaves_like 'snippet blob raw path'
context 'with a snippet without a repository' do
let(:personal_snippet) { build(:personal_snippet, author: user, id: 1) }
let(:project_snippet) { build(:project_snippet, project: project, author: user, id: 1) }
let(:blob) { snippet.blob }
context 'with ProjectSnippet' do
let(:snippet) { project_snippet }
it 'returns the raw project snippet path' do
expect(subject).to eq("/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}/raw")
end
end
context 'with PersonalSnippet' do
let(:snippet) { personal_snippet }
it 'returns the raw personal snippet path' do
expect(subject).to eq("/-/snippets/#{personal_snippet.id}/raw")
end
end
end
end end
describe '#raw_url' do describe '#raw_url' do
subject { described_class.new(snippet.blobs.first, current_user: user).raw_url } subject { described_class.new(blob, current_user: user).raw_url }
before do before do
stub_default_url_options(host: 'test.host') stub_default_url_options(host: 'test.host')
end end
it_behaves_like 'snippet blob raw url' it_behaves_like 'snippet blob raw url'
context 'with a snippet without a repository' do
let(:personal_snippet) { build(:personal_snippet, author: user, id: 1) }
let(:project_snippet) { build(:project_snippet, project: project, author: user, id: 1) }
let(:blob) { snippet.blob }
context 'with ProjectSnippet' do
let(:snippet) { project_snippet }
it 'returns the raw project snippet url' do
expect(subject).to eq("http://test.host/#{project_snippet.project.full_path}/-/snippets/#{project_snippet.id}/raw")
end
end
context 'with PersonalSnippet' do
let(:snippet) { personal_snippet }
it 'returns the raw personal snippet url' do
expect(subject).to eq("http://test.host/-/snippets/#{personal_snippet.id}/raw")
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