Commit 9133e388 authored by Rubén Dávila's avatar Rubén Dávila

Update from last code review.

* Added new `#add_on?` method to License which returns `true` if add-on
  exists and has a quantity greater than 0
* Updated the specs related to License model.
parent 6c5d0064
......@@ -77,14 +77,15 @@ class License < ActiveRecord::Base
end
def add_ons
return {} unless self.license? && self.restricted?(:add_ons)
return {} unless license? && restricted?(:add_ons)
self.restrictions[:add_ons]
restrictions[:add_ons]
end
def add_on(code)
add_ons.slice(code).presence or nil
def add_on?(code)
add_ons[code].to_i > 0
end
private
def reset_current
......
......@@ -212,32 +212,54 @@ describe License do
end
describe 'reading add-ons' do
context "with add-ons" do
before do
gl_license.restrictions = { add_ons: { support: 1, custom_domain: 2 } }
end
describe '#add_ons' do
context "without add-ons" do
it 'returns an empty Hash' do
license = build_license_with_add_ons({})
it 'returns all available add-ons' do
expect(license.add_ons.keys).to include('support', 'custom_domain')
expect(license.add_ons).to eq({})
end
end
it 'returns a single addon if it exists' do
expect(license.add_on('support')).to eq({ 'support' => 1 })
end
context "with add-ons" do
it 'returns all available add-ons' do
license = build_license_with_add_ons({ 'support' => 1, 'custom-domain' => 2 })
it 'returns Nil if add-on does not exists' do
expect(license.add_on('unknown')).to be_nil
expect(license.add_ons.keys).to include('support', 'custom-domain')
end
it 'can return details about a single add-on' do
license = build_license_with_add_ons({ 'custom-domain' => 2 })
expect(license.add_ons['custom-domain']).to eq(2)
end
end
end
context "without add-ons" do
it 'returns an empty Hash' do
expect(license.add_ons).to eq({})
describe '#add_on?' do
it 'returns true if add-on exists and have a quantity greater than 0' do
license = build_license_with_add_ons({ 'support' => 1 })
expect(license.add_on?('support')).to eq(true)
end
it 'returns false if add-on exists but have a quantity of 0' do
license = build_license_with_add_ons({ 'support' => 0 })
expect(license.add_on?('support')).to eq(false)
end
it 'returns nil when asking for a single add-on' do
expect(license.add_on('support')).to be_nil
it 'returns false if add-on does not exists' do
license = build_license_with_add_ons({})
expect(license.add_on?('support')).to eq(false)
end
end
def build_license_with_add_ons(add_ons)
gl_license = build(:gitlab_license, restrictions: { add_ons: add_ons })
build(:license, data: gl_license.export)
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