Commit 572bb643 authored by Markus Koller's avatar Markus Koller

Merge branch 'fj-refactor-snippet-method' into 'master'

Refactor Snippet#blobs method

See merge request gitlab-org/gitlab!48029
parents 73857291 27b9eca4
......@@ -213,7 +213,8 @@ class Snippet < ApplicationRecord
def blobs
return [] unless repository_exists?
repository.ls_files(default_branch).map { |file| Blob.lazy(repository, default_branch, file) }
branch = default_branch
list_files(branch).map { |file| Blob.lazy(repository, branch, file) }
end
def hook_attrs
......
......@@ -481,17 +481,9 @@ RSpec.describe Snippet do
end
describe '#blobs' do
let(:snippet) { create(:snippet) }
it 'returns a blob representing the snippet data' do
blob = snippet.blob
expect(blob).to be_a(Blob)
expect(blob.path).to eq(snippet.file_name)
expect(blob.data).to eq(snippet.content)
end
context 'when repository does not exist' do
let(:snippet) { create(:snippet) }
it 'returns empty array' do
expect(snippet.blobs).to be_empty
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