Commit e1ce8c0b authored by Etienne Baqué's avatar Etienne Baqué

Fixed user_cap_reached? method in Group

Updated rspec accordingly.
parent 769e0a7d
...@@ -476,9 +476,11 @@ module EE ...@@ -476,9 +476,11 @@ module EE
def user_cap_reached?(requested_hosted_plan = nil) def user_cap_reached?(requested_hosted_plan = nil)
return false unless ::Feature.enabled?(:saas_user_caps, self, default_enabled: :yaml) return false unless ::Feature.enabled?(:saas_user_caps, self, default_enabled: :yaml)
return false unless new_user_signups_cap
new_user_signups_cap <= billable_members_count(requested_hosted_plan) user_cap = root_ancestor.new_user_signups_cap
return false unless user_cap
user_cap <= billable_members_count(requested_hosted_plan)
end end
private private
......
...@@ -1492,12 +1492,6 @@ RSpec.describe Group do ...@@ -1492,12 +1492,6 @@ RSpec.describe Group do
end end
describe '#user_cap_reached?' do describe '#user_cap_reached?' do
let(:new_user_signups_cap) { nil }
before do
allow(group.namespace_settings).to receive(:new_user_signups_cap).and_return(new_user_signups_cap)
end
subject(:user_cap_reached_for_group?) { group.user_cap_reached? } subject(:user_cap_reached_for_group?) { group.user_cap_reached? }
context 'when the :saas_user_caps feature flag is not enabled' do context 'when the :saas_user_caps feature flag is not enabled' do
...@@ -1509,33 +1503,53 @@ RSpec.describe Group do ...@@ -1509,33 +1503,53 @@ RSpec.describe Group do
stub_feature_flags(saas_user_caps: true) stub_feature_flags(saas_user_caps: true)
end end
context 'when no user cap has been set' do let(:new_user_signups_cap) { nil }
it { is_expected.to be_falsey }
end
context 'when a user cap has been set' do
let(:new_user_signups_cap) { 100 }
shared_context 'returning the right value for user_cap_reached?' do
before do before do
allow(group).to receive(:billable_members_count).and_return(billable_members_count) root_group.namespace_settings.update!(new_user_signups_cap: new_user_signups_cap)
end end
context 'when this cap is higher than the number of billable members' do context 'when no user cap has been set to that root ancestor' do
let(:billable_members_count) { new_user_signups_cap - 10 }
it { is_expected.to be_falsey } it { is_expected.to be_falsey }
end end
context 'when this cap is the same as the number of billable members' do context 'when a user cap has been set to that root ancestor' do
let(:billable_members_count) { new_user_signups_cap } let(:new_user_signups_cap) { 100 }
before do
allow(group).to receive(:billable_members_count).and_return(billable_members_count)
end
context 'when this cap is higher than the number of billable members' do
let(:billable_members_count) { new_user_signups_cap - 10 }
it { is_expected.to be_falsey }
end
context 'when this cap is the same as the number of billable members' do
let(:billable_members_count) { new_user_signups_cap }
it { is_expected.to be_truthy }
end
it { is_expected.to be_truthy } context 'when this cap is lower than the number of billable members' do
let(:billable_members_count) { new_user_signups_cap + 10 }
it { is_expected.to be_truthy }
end
end end
end
context 'when this cap is lower than the number of billable members' do context 'when this group has no root ancestor' do
let(:billable_members_count) { new_user_signups_cap + 10 } it_behaves_like 'returning the right value for user_cap_reached?' do
let(:root_group) { group }
end
end
it { is_expected.to be_truthy } context 'when this group has a root ancestor' do
it_behaves_like 'returning the right value for user_cap_reached?' do
let(:root_group) { create(:group, children: [group]) }
end end
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