summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-05-11 15:38:30 -0500
committerDouwe Maan <douwe@selenight.nl>2017-05-11 15:38:30 -0500
commit9f4fa4cdc7e32f63d7afcd608f1af86dbc4ae477 (patch)
tree7150b39a8fbdbac26ddb1674d39061fd732fd1cd
parente65d9326fcaecafbbfdc423f1c9e51f584d03463 (diff)
downloadgitlab-ce-9f4fa4cdc7e32f63d7afcd608f1af86dbc4ae477.tar.gz
Fix displaying a repository without a readmedm-fix-repository-without-readme
-rw-r--r--app/models/repository.rb4
-rw-r--r--spec/models/repository_spec.rb16
2 files changed, 15 insertions, 5 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 11163ec77e9..b1563bfba8b 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -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
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 00a9f2abeb9..61b748429d7 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -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