BigW Consortium Gitlab

Commit 9f4fa4cd by Douwe Maan

Fix displaying a repository without a readme

parent e65d9326
...@@ -517,8 +517,8 @@ class Repository ...@@ -517,8 +517,8 @@ class Repository
cache_method :avatar cache_method :avatar
def readme def readme
if head = tree(:head) if readme = tree(:head)&.readme
ReadmeBlob.new(head.readme, self) ReadmeBlob.new(readme, self)
end end
end end
......
...@@ -1659,18 +1659,28 @@ describe Repository, models: true do ...@@ -1659,18 +1659,28 @@ describe Repository, models: true do
describe '#readme', caching: true do describe '#readme', caching: true do
context 'with a non-existing repository' do context 'with a non-existing repository' do
it 'returns nil' 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 expect(repository.readme).to be_nil
end end
end end
context 'with an existing repository' do context 'with an existing repository' do
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 it 'returns the README' do
expect(repository.readme).to be_an_instance_of(ReadmeBlob) expect(repository.readme).to be_an_instance_of(ReadmeBlob)
end end
end end
end end
end
describe '#expire_statistics_caches' do describe '#expire_statistics_caches' do
it 'expires the caches' do it 'expires the caches' do
......
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