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
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