BigW Consortium Gitlab

Commit 9f4fa4cd by Douwe Maan

Fix displaying a repository without a readme

parent e65d9326
......@@ -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
......
......@@ -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
......
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