Commit 534c70ea authored by Douwe Maan's avatar Douwe Maan

Merge branch '2482-allow-no-namespace-plan' into 'master'

Allow saving no plan on namespaces

Closes #2482

See merge request !1993
parents ede460d3 0d940787
...@@ -21,10 +21,12 @@ module EE ...@@ -21,10 +21,12 @@ module EE
prepended do prepended do
has_one :namespace_statistics, dependent: :destroy 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, delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset,
to: :namespace_statistics, allow_nil: true to: :namespace_statistics, allow_nil: true
validates :plan, inclusion: { in: EE_PLANS.keys }, allow_nil: true validates :plan, inclusion: { in: EE_PLANS.keys }, allow_blank: true
end end
# Checks features (i.e. https://about.gitlab.com/products/) availabily # Checks features (i.e. https://about.gitlab.com/products/) availabily
...@@ -58,7 +60,7 @@ module EE ...@@ -58,7 +60,7 @@ module EE
def plans def plans
@ancestors_plans ||= @ancestors_plans ||=
if parent_id if parent_id
ancestors.where.not(plan: nil).reorder(nil).pluck('DISTINCT plan') + [plan] ancestors.with_plan.reorder(nil).pluck('DISTINCT plan') + [plan]
else else
[plan] [plan]
end end
......
.form-group .form-group
= f.label :plan, class: 'control-label' = f.label :plan, class: 'control-label'
.col-sm-10 .col-sm-10
= f.select :plan, options_for_select(Namespace::EE_PLANS.keys.map { |plan| [plan.titleize, plan] }, f.object.plan), {}, class: 'form-control' = f.select :plan, options_for_select(Namespace::EE_PLANS.keys.map { |plan| [plan.titleize, plan] }, f.object.plan),
{ include_blank: 'No plan' },
class: 'form-control'
...@@ -8,7 +8,39 @@ describe Namespace, models: true do ...@@ -8,7 +8,39 @@ describe Namespace, models: true do
it { is_expected.to delegate_method(:shared_runners_minutes).to(:namespace_statistics) } it { is_expected.to delegate_method(:shared_runners_minutes).to(:namespace_statistics) }
it { is_expected.to delegate_method(:shared_runners_seconds).to(:namespace_statistics) } it { is_expected.to delegate_method(:shared_runners_seconds).to(:namespace_statistics) }
it { is_expected.to delegate_method(:shared_runners_seconds_last_reset).to(:namespace_statistics) } 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_nil } 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 describe '#feature_available?' do
let(:group) { create(:group, plan: plan_license) } 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