Commit 27b9eca4 authored by fjsanpedro's avatar fjsanpedro

Refactor Snippet#blobs method

parent 05ce22b8
......@@ -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
context 'when repository does not exist' 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
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