Commit b4b7cf5a authored by Robert Speicher's avatar Robert Speicher

Merge branch 'dm-fix-repository-without-readme' into 'master'

Fix displaying a repository without a readme

Closes #32122

See merge request !11312
parents e7b53dd6 9f4fa4cd
...@@ -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