Skip to content
Snippets Groups Projects
Commit 9f4fa4cd authored by Douwe Maan's avatar Douwe Maan
Browse files

Fix displaying a repository without a readme

parent e65d9326
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -517,8 +517,8 @@ class Repository
cache_method :avatar
 
def readme
if head = tree(:head)
ReadmeBlob.new(head.readme, self)
if readme = tree(:head)&.readme
ReadmeBlob.new(readme, self)
end
end
 
Loading
Loading
Loading
Loading
@@ -1659,15 +1659,25 @@ describe Repository, models: true do
describe '#readme', caching: true do
context 'with a non-existing repository' do
it 'returns nil' do
expect(repository).to receive(:tree).with(:head).and_return(nil)
allow(repository).to receive(:tree).with(:head).and_return(nil)
 
expect(repository.readme).to be_nil
end
end
 
context 'with an existing repository' do
it 'returns the README' do
expect(repository.readme).to be_an_instance_of(ReadmeBlob)
context 'when no README exists' do
it 'returns nil' do
allow_any_instance_of(Tree).to receive(:readme).and_return(nil)
expect(repository.readme).to be_nil
end
end
context 'when a README exists' do
it 'returns the README' do
expect(repository.readme).to be_an_instance_of(ReadmeBlob)
end
end
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment