Commit f27a8757 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'license_app_40' into 'master'

Add ability to read available add-ons on License.



See merge request !300
parents 6b3b0711 9133e388
......@@ -76,6 +76,16 @@ class License < ActiveRecord::Base
end
end
def add_ons
return {} unless license? && restricted?(:add_ons)
restrictions[:add_ons]
end
def add_on?(code)
add_ons[code].to_i > 0
end
private
def reset_current
......
......@@ -210,4 +210,56 @@ describe License do
end
end
end
describe 'reading add-ons' do
describe '#add_ons' do
context "without add-ons" do
it 'returns an empty Hash' do
license = build_license_with_add_ons({})
expect(license.add_ons).to eq({})
end
end
context "with add-ons" do
it 'returns all available add-ons' do
license = build_license_with_add_ons({ 'support' => 1, 'custom-domain' => 2 })
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
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 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