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