Commit 6bd3550e authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Create with_plan namespace scope

parent 08b1302d
......@@ -21,6 +21,8 @@ module EE
prepended do
has_one :namespace_statistics, dependent: :destroy
scope :with_plan, -> { where.not(plan: [nil, '']) }
delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset,
to: :namespace_statistics, allow_nil: true
......@@ -58,7 +60,7 @@ module EE
def plans
@ancestors_plans ||=
if parent_id
ancestors.where.not(plan: [nil, '']).reorder(nil).pluck('DISTINCT plan') + [plan]
ancestors.with_plan.reorder(nil).pluck('DISTINCT plan') + [plan]
else
[plan]
end
......
......@@ -10,6 +10,38 @@ describe Namespace, models: true do
it { is_expected.to delegate_method(:shared_runners_seconds_last_reset).to(:namespace_statistics) }
it { is_expected.to validate_inclusion_of(:plan).in_array(Namespace::EE_PLANS.keys).allow_blank }
context 'scopes' do
describe '.with_plan' do
let!(:namespace) { create :namespace, plan: namespace_plan }
context 'plan is set' do
let(:namespace_plan) { EE::Namespace::BRONZE_PLAN }
it 'returns namespaces with plan' do
expect(described_class.with_plan).to eq([namespace])
end
end
context 'plan is not set' do
context 'plan is empty string' do
let(:namespace_plan) { '' }
it 'returns no namespace' do
expect(described_class.with_plan).to be_empty
end
end
context 'plan is nil' do
let(:namespace_plan) { nil }
it 'returns no namespace' do
expect(described_class.with_plan).to be_empty
end
end
end
end
end
describe '#feature_available?' do
let(:group) { create(:group, plan: plan_license) }
......
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