Commit 7d8b888e authored by Rubén Dávila's avatar Rubén Dávila

Apply suggestions from last code review!

parent c0fcf258
...@@ -6,7 +6,7 @@ class License < ApplicationRecord ...@@ -6,7 +6,7 @@ class License < ApplicationRecord
STARTER_PLAN = 'starter'.freeze STARTER_PLAN = 'starter'.freeze
PREMIUM_PLAN = 'premium'.freeze PREMIUM_PLAN = 'premium'.freeze
ULTIMATE_PLAN = 'ultimate'.freeze ULTIMATE_PLAN = 'ultimate'.freeze
ALLOWED_PERCENTAGE_OF_USERS_OVERAGE = 10 ALLOWED_PERCENTAGE_OF_USERS_OVERAGE = (10 / 100.0).freeze
EES_FEATURES = %i[ EES_FEATURES = %i[
audit_events audit_events
...@@ -563,23 +563,20 @@ class License < ApplicationRecord ...@@ -563,23 +563,20 @@ class License < ApplicationRecord
end end
end end
def real_restricted_user_count def restricted_user_count_with_threshold
if previous_user_count # overage should only be applied for new subscriptions not for renewals.
restricted_user_count return restricted_user_count if previous_user_count
else
percent = ALLOWED_PERCENTAGE_OF_USERS_OVERAGE / 100.0
(restricted_user_count * (1 + percent)).to_i (restricted_user_count * (1 + ALLOWED_PERCENTAGE_OF_USERS_OVERAGE)).to_i
end
end end
def check_users_limit def check_users_limit
return unless restricted_user_count return unless restricted_user_count
if previous_user_count && (prior_historical_max <= previous_user_count) if previous_user_count && (prior_historical_max <= previous_user_count)
return if real_restricted_user_count >= current_active_users_count return if restricted_user_count >= current_active_users_count
else else
return if real_restricted_user_count >= prior_historical_max return if restricted_user_count_with_threshold >= prior_historical_max
end end
user_count = prior_historical_max == 0 ? current_active_users_count : prior_historical_max user_count = prior_historical_max == 0 ? current_active_users_count : prior_historical_max
......
...@@ -28,6 +28,7 @@ RSpec.describe License do ...@@ -28,6 +28,7 @@ RSpec.describe License do
end end
describe '#check_users_limit' do describe '#check_users_limit' do
context 'for each plan' do
before do before do
create(:group_member, :guest) create(:group_member, :guest)
create(:group_member, :reporter) create(:group_member, :reporter)
...@@ -65,7 +66,7 @@ RSpec.describe License do ...@@ -65,7 +66,7 @@ RSpec.describe License do
end end
end end
describe 'threshold for users overage' do context 'threshold for users overage' do
let(:current_active_users_count) { 0 } let(:current_active_users_count) { 0 }
let(:new_license) do let(:new_license) do
gl_license = build( gl_license = build(
...@@ -109,13 +110,14 @@ RSpec.describe License do ...@@ -109,13 +110,14 @@ RSpec.describe License do
context 'when current active users count is under the threshold' do context 'when current active users count is under the threshold' do
let(:current_active_users_count) { 11 } let(:current_active_users_count) { 11 }
it 'accepts the license' do it 'does not accept the license' do
expect(new_license).not_to be_valid expect(new_license).not_to be_valid
end end
end end
end end
end end
end end
end
describe "Historical active user count" do describe "Historical active user count" do
let(:active_user_count) { described_class.current_active_users.count + 10 } let(:active_user_count) { described_class.current_active_users.count + 10 }
......
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