Commit 2720e7d8 authored by Igor Drozdov's avatar Igor Drozdov

Repository#license returns nil when license_key unrecognized

parent 54293337
...@@ -627,7 +627,12 @@ class Repository ...@@ -627,7 +627,12 @@ class Repository
def license def license
return unless license_key return unless license_key
Licensee::License.new(license_key) licensee_object = Licensee::License.new(license_key)
return if licensee_object.name.blank?
licensee_object
rescue Licensee::InvalidLicense
end end
memoize_method :license memoize_method :license
......
...@@ -1308,6 +1308,12 @@ RSpec.describe Repository do ...@@ -1308,6 +1308,12 @@ RSpec.describe Repository do
expect(repository.license).to be_nil expect(repository.license).to be_nil
end end
it 'returns nil when license_key is not recognized' do
expect(repository).to receive(:license_key).twice.and_return('not-recognized')
expect(repository.license).to be_nil
end
it 'returns other when the content is not recognizable' do it 'returns other when the content is not recognizable' do
license = Licensee::License.new('other') license = Licensee::License.new('other')
repository.create_file(user, 'LICENSE', 'Gitlab B.V.', repository.create_file(user, 'LICENSE', 'Gitlab B.V.',
......
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