Commit 2c3664a3 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '332592-fix-user-cap-reached' into 'master'

Fixed user_cap_reached? method in Group

See merge request gitlab-org/gitlab!66941
parents 1b348769 e1ce8c0b
......@@ -476,9 +476,11 @@ module EE
def user_cap_reached?(requested_hosted_plan = nil)
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
private
......
......@@ -1492,12 +1492,6 @@ RSpec.describe Group do
end
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? }
context 'when the :saas_user_caps feature flag is not enabled' do
......@@ -1509,33 +1503,53 @@ RSpec.describe Group do
stub_feature_flags(saas_user_caps: true)
end
context 'when no user cap has been set' do
it { is_expected.to be_falsey }
end
context 'when a user cap has been set' do
let(:new_user_signups_cap) { 100 }
let(:new_user_signups_cap) { nil }
shared_context 'returning the right value for user_cap_reached?' 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
context 'when this cap is higher than the number of billable members' do
let(:billable_members_count) { new_user_signups_cap - 10 }
context 'when no user cap has been set to that root ancestor' do
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 }
context 'when a user cap has been set to that root ancestor' do
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
context 'when this cap is lower than the number of billable members' do
let(:billable_members_count) { new_user_signups_cap + 10 }
context 'when this group has no root ancestor' do
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
......
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