summaryrefslogtreecommitdiff
path: root/spec/models/repository_spec.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-02-14 12:53:53 -0800
committerStan Hu <stanhu@gmail.com>2018-02-14 12:53:53 -0800
commit35b3a0b967399d0b4340325d067592c166f208e5 (patch)
treef15bdfa166b0ea22cdf48063b1a2468d9b74c6c5 /spec/models/repository_spec.rb
parentdd633bc1888453a07474d045eca91a9e66302ce0 (diff)
downloadgitlab-ce-35b3a0b967399d0b4340325d067592c166f208e5.tar.gz
Fix Error 500s loading repositories with no master branch
We removed the exception handling for Rugged errors in !16770, which revealed that the licensee gem attempts to retrieve a license file via Rugged in `refs/heads/master` by default. If that branch did not exist, a Rugged::ReferenceError would be thrown. There were two issues: 1. Not every project uses `master` as the default branch. This change uses the head commit to identify the license. 2. Removing the exception handling caused repositories to fail loading. We can safely catch and ignore any Rugged error because this means we weren't able to load a license file. Closes #43268
Diffstat (limited to 'spec/models/repository_spec.rb')
-rw-r--r--spec/models/repository_spec.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index a6d48e369ac..1b5b746b340 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -873,6 +873,19 @@ describe Repository do
expect(repository.license_key).to be_nil
end
+ it 'returns nil when the commit SHA does not exist' do
+ allow(repository.head_commit).to receive(:sha).and_return('1' * 40)
+
+ expect(repository.license_key).to be_nil
+ end
+
+ it 'returns the license key even when master does not exist' do
+ repository.rm_branch(user, 'master')
+ project.change_head('test')
+
+ expect(repository.license_key).to eq('mit')
+ end
+
it 'returns the license key' do
repository.create_file(user, 'LICENSE',
Licensee::License.new('mit').content,