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
def load_license
return unless self.table_exists?
license = self.last
return unless license && license.valid?
license
self.order(id: :desc).limit(100).find { |license| license.valid? && license.started? }
end
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
end
describe "Class methods" do
let!(:license) { described_class.last }
before do
described_class.reset_current
allow(described_class).to receive(:last).and_return(license)
end
describe '.features_for_plan' do
......@@ -343,45 +340,47 @@ describe License do
describe ".current" 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)
end
it 'returns nil' do
expect(described_class.current).to be_nil
end
end
context "when there is no license" do
let!(:license) { nil }
it "returns nil" do
allow(described_class).to receive(:order).and_return(double(limit: []))
expect(described_class.current).to be_nil
end
end
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)
end
it "returns nil" do
expect(described_class.current).to be_nil
end
end
context "when the license is valid" 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
describe ".block_changes?" do
before do
allow(License).to receive(:current).and_return(license)
end
context "when there is no current license" do
before do
allow(described_class).to receive(:current).and_return(nil)
end
let(:license) { nil }
it "returns false" do
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