Commit 9376a5a0 authored by Ruben Davila's avatar Ruben Davila

Only block changes when a regular license has expired

parent ddd47d9e
......@@ -157,7 +157,10 @@ class License < ActiveRecord::Base
end
def block_changes?
!current || current.block_changes?
return false if current.nil?
return false if License&.current&.trial?
current.block_changes?
end
def load_license
......
FactoryGirl.define do
factory :gitlab_license, class: "Gitlab::License" do
trait :trial do
restrictions do
{ trial: true }
end
end
trait :expired do
expires_at { 3.weeks.ago.to_date }
end
starts_at { Date.today - 1.month }
expires_at { Date.today + 11.months }
block_changes_at { expires_at + 2.weeks }
notify_users_at { expires_at }
notify_admins_at { expires_at }
licensee do
{ "Name" => generate(:name) }
end
restrictions do
{
add_ons: {
......@@ -13,21 +28,23 @@ FactoryGirl.define do
}
}
end
notify_users_at { |l| l.expires_at }
notify_admins_at { |l| l.expires_at }
trait :trial do
restrictions do
{ trial: true }
end
end
end
factory :license do
data { build(:gitlab_license).export }
end
transient do
expired false
trial false
end
data do
attrs = [:gitlab_license]
attrs << :trial if trial
attrs << :expired if expired
build(*attrs).export
end
factory :trial_license, class: License do
data { build(:gitlab_license, :trial).export }
# Disable validations when creating an expired license key
to_create {|instance| instance.save(validate: !expired) }
end
end
......@@ -292,8 +292,24 @@ describe License do
allow(described_class).to receive(:current).and_return(nil)
end
it "returns true" do
expect(described_class.block_changes?).to be_truthy
it "returns false" do
expect(described_class.block_changes?).to eq(false)
end
end
context 'with an expired trial license' do
let!(:license) { create(:license, trial: true) }
it 'returns false' do
expect(described_class.block_changes?).to eq(false)
end
end
context 'with an expired normal license' do
let!(:license) { create(:license, expired: true) }
it 'returns true' do
expect(described_class.block_changes?).to eq(true)
end
end
......
......@@ -6,7 +6,7 @@ describe HistoricalDataWorker do
describe '#perform' do
context 'with a trial license' do
before do
FactoryGirl.create(:trial_license)
FactoryGirl.create(:license, trial: true)
end
it 'does not track historical data' do
......
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