Commit 05eae251 authored by Corinna Wiesner's avatar Corinna Wiesner

Change logic to find the current license

At the moment the last uploaded license is considered as the current
license. But when uploading a license which will start in the future it
is not supposed to be active right away. Therefore we will now find the
last uploaded license that has already started  and use it as the
current one.
parent aced436b
...@@ -267,11 +267,7 @@ class License < ApplicationRecord ...@@ -267,11 +267,7 @@ class License < ApplicationRecord
def load_license def load_license
return unless self.table_exists? return unless self.table_exists?
license = self.last self.order(id: :desc).limit(100).find { |license| license.valid? && license.started? }
return unless license && license.valid?
license
end end
def global_feature?(feature) def global_feature?(feature)
......
---
title: Change logic to find the current license
merge_request: 30296
author:
type: changed
...@@ -274,11 +274,8 @@ describe License do ...@@ -274,11 +274,8 @@ describe License do
end end
describe "Class methods" do describe "Class methods" do
let!(:license) { described_class.last }
before do before do
described_class.reset_current described_class.reset_current
allow(described_class).to receive(:last).and_return(license)
end end
describe '.features_for_plan' do describe '.features_for_plan' do
...@@ -343,45 +340,47 @@ describe License do ...@@ -343,45 +340,47 @@ describe License do
describe ".current" do describe ".current" do
context 'when licenses table does not exist' do context 'when licenses table does not exist' do
before do it 'returns nil' do
allow(described_class).to receive(:table_exists?).and_return(false) allow(described_class).to receive(:table_exists?).and_return(false)
end
it 'returns nil' do
expect(described_class.current).to be_nil expect(described_class.current).to be_nil
end end
end end
context "when there is no license" do context "when there is no license" do
let!(:license) { nil }
it "returns nil" do it "returns nil" do
allow(described_class).to receive(:order).and_return(double(limit: []))
expect(described_class.current).to be_nil expect(described_class.current).to be_nil
end end
end end
context "when the license is invalid" do context "when the license is invalid" do
before do it "returns nil" do
allow(described_class).to receive(:order).and_return(double(limit: [license]))
allow(license).to receive(:valid?).and_return(false) allow(license).to receive(:valid?).and_return(false)
end
it "returns nil" do
expect(described_class.current).to be_nil expect(described_class.current).to be_nil
end end
end end
context "when the license is valid" do context "when the license is valid" do
it "returns the license" do it "returns the license" do
expect(described_class.current).to be_present current_license = create_list(:license, 2).last
create(:license, data: create(:gitlab_license, starts_at: Date.current + 1.month).export)
expect(described_class.current).to eq(current_license)
end end
end end
end end
describe ".block_changes?" do describe ".block_changes?" do
before do
allow(License).to receive(:current).and_return(license)
end
context "when there is no current license" do context "when there is no current license" do
before do let(:license) { nil }
allow(described_class).to receive(:current).and_return(nil)
end
it "returns false" do it "returns false" do
expect(described_class.block_changes?).to be_falsey expect(described_class.block_changes?).to be_falsey
......
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