Commit caa09e69 authored by Douwe Maan's avatar Douwe Maan

Add License unit test.

parent e7154898
...@@ -79,13 +79,6 @@ class License < ActiveRecord::Base ...@@ -79,13 +79,6 @@ class License < ActiveRecord::Base
else else
super super
end end
(license && license.respond_to?(method_name)) || super
end
def active_user_restriction_exceeded?
return false unless self.restricted?(:active_user_count)
User.active.count > self.restrictions[:active_user_count]
end end
private private
......
require "spec_helper"
describe License do
let(:gl_license) { Gitlab::License.new(issued_at: Date.today, licensee: { "Name" => "GitLab Test Env" }) }
let(:license) { License.new(data: gl_license.export) }
describe "Validation" do
describe "Valid license" do
context "when the license is provided" do
it "is valid" do
expect(license).to be_valid
end
end
context "when no license is provided" do
before do
license.data = nil
end
it "is invalid" do
expect(license).to_not be_valid
end
end
end
describe "Active user count" do
context "when there is no active user count restriction" do
it "is valid" do
expect(license).to be_valid
end
end
context "when the active user count restriction is exceeded" do
before do
gl_license.restrictions = { active_user_count: User.active.count - 1 }
end
it "is invalid" do
expect(license).to_not be_valid
end
end
context "when the active user count restriction is not exceeded" do
before do
gl_license.restrictions = { active_user_count: User.active.count + 1 }
end
it "is valid" do
expect(license).to be_valid
end
end
end
describe "Not expired" do
context "when the license doesn't expire" do
it "is valid" do
expect(license).to be_valid
end
end
context "when the license has expired" do
before do
gl_license.expires_at = Date.yesterday
end
it "is valid" do
expect(license).to_not be_valid
end
end
context "when the license has yet to expire" do
before do
gl_license.expires_at = Date.tomorrow
end
it "is valid" do
expect(license).to be_valid
end
end
end
end
describe "Class methods" do
let!(:license) { License.last }
before do
License.reset_current
allow(License).to receive(:last).and_return(license)
end
describe ".current" do
context "when there is no license" do
let!(:license) { nil }
it "returns nil" do
expect(License.current).to be_nil
end
end
context "when the license is invalid" do
before do
allow(license).to receive(:valid?).and_return(false)
end
it "returns nil" do
expect(License.current).to be_nil
end
end
context "when the license is valid" do
it "returns the license" do
expect(License.current)
end
end
end
describe ".block_changes?" do
context "when there is no current license" do
before do
allow(License).to receive(:current).and_return(nil)
end
it "returns true" do
expect(License.block_changes?).to be_truthy
end
end
context "when the current license is set to block changes" do
before do
allow(license).to receive(:block_changes?).and_return(true)
end
it "returns true" do
expect(License.block_changes?).to be_truthy
end
end
context "when the current license doesn't block changes" do
it "returns false" do
expect(License.block_changes?).to be_falsey
end
end
end
end
describe "#license" do
context "when no data is provided" do
before do
license.data = nil
end
it "returns nil" do
expect(license.license).to be_nil
end
end
context "when corrupt license data is provided" do
before do
license.data = "whatever"
end
it "returns nil" do
expect(license.license).to be_nil
end
end
context "when valid license data is provided" do
it "returns the license" do
expect(license.license).to_not be_nil
end
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