Commit 33555bc7 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Remove plan from namespaces factory

This column is not used anymore and setting this causes incorrect tests.
parent 4dc3a316
...@@ -36,7 +36,6 @@ module EE ...@@ -36,7 +36,6 @@ module EE
scope :include_gitlab_subscription, -> { includes(:gitlab_subscription) } scope :include_gitlab_subscription, -> { includes(:gitlab_subscription) }
scope :join_gitlab_subscription, -> { joins("LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id") } scope :join_gitlab_subscription, -> { joins("LEFT OUTER JOIN gitlab_subscriptions ON gitlab_subscriptions.namespace_id=namespaces.id") }
scope :with_plan, -> { where.not(plan_id: nil) }
scope :with_shared_runners_minutes_limit, -> { where("namespaces.shared_runners_minutes_limit > 0") } scope :with_shared_runners_minutes_limit, -> { where("namespaces.shared_runners_minutes_limit > 0") }
scope :with_extra_shared_runners_minutes_limit, -> { where("namespaces.extra_shared_runners_minutes_limit > 0") } scope :with_extra_shared_runners_minutes_limit, -> { where("namespaces.extra_shared_runners_minutes_limit > 0") }
scope :with_shared_runners_minutes_exceeding_default_limit, -> do scope :with_shared_runners_minutes_exceeding_default_limit, -> do
......
...@@ -60,4 +60,21 @@ FactoryBot.define do ...@@ -60,4 +60,21 @@ FactoryBot.define do
group: group) group: group)
end end
end end
factory :group_with_plan, parent: :group do
transient do
plan { :default_plan }
trial_ends_on { nil }
end
after(:create) do |group, evaluator|
if evaluator.plan
create(:gitlab_subscription,
namespace: group,
hosted_plan: create(evaluator.plan),
trial: evaluator.trial_ends_on.present?,
trial_ends_on: evaluator.trial_ends_on)
end
end
end
end end
...@@ -2,16 +2,6 @@ ...@@ -2,16 +2,6 @@
FactoryBot.modify do FactoryBot.modify do
factory :namespace do factory :namespace do
transient do
plan { nil }
end
before(:create) do |namespace, evaluator|
if evaluator.plan.present?
namespace.plan = create(evaluator.plan)
end
end
trait :with_build_minutes do trait :with_build_minutes do
namespace_statistics factory: :namespace_statistics, shared_runners_seconds: 400.minutes.to_i namespace_statistics factory: :namespace_statistics, shared_runners_seconds: 400.minutes.to_i
end end
......
...@@ -370,23 +370,19 @@ describe 'Billing plan pages', :feature do ...@@ -370,23 +370,19 @@ describe 'Billing plan pages', :feature do
end end
context 'on sub-group' do context 'on sub-group' do
let(:user2) { create(:user) } let(:group) { create(:group_with_plan, plan: :bronze_plan) }
let(:user3) { create(:user) } let(:plan) { bronze_plan }
let(:group) { create(:group, plan: :bronze_plan) }
let!(:group_member) { create(:group_member, :owner, group: group, user: user) }
let(:subgroup1) { create(:group, parent: group, plan: :silver_plan) }
let!(:subgroup1_member) { create(:group_member, :owner, group: subgroup1, user: user2) }
let(:subgroup2) { create(:group, parent: subgroup1) }
let!(:subgroup2_member) { create(:group_member, :owner, group: subgroup2, user: user3) }
let(:page_path) { group_billings_path(subgroup2) }
let(:namespace) { group } let(:namespace) { group }
context 'on bronze' do let!(:group_member) { create(:group_member, :owner, group: group, user: user) }
let(:plan) { bronze_plan }
let!(:subscription) do let(:subgroup1) { create(:group, parent: group) }
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15) let!(:subgroup1_member) { create(:group_member, :owner, group: subgroup1) }
end
let(:subgroup2) { create(:group, parent: subgroup1) }
let!(:subgroup2_member) { create(:group_member, :owner, group: subgroup2) }
let(:page_path) { group_billings_path(subgroup2) }
before do before do
visit page_path visit page_path
...@@ -402,7 +398,6 @@ describe 'Billing plan pages', :feature do ...@@ -402,7 +398,6 @@ describe 'Billing plan pages', :feature do
expect(page).not_to have_css('.billing-plans') expect(page).not_to have_css('.billing-plans')
end end
end end
end
context 'with unexpected JSON' do context 'with unexpected JSON' do
let(:plan) { free_plan } let(:plan) { free_plan }
......
...@@ -28,14 +28,12 @@ describe 'Group overview', :js do ...@@ -28,14 +28,12 @@ describe 'Group overview', :js do
before do before do
stub_licensed_features(security_dashboard: true) stub_licensed_features(security_dashboard: true)
enable_namespace_license_check! enable_namespace_license_check!
create(:gitlab_subscription, hosted_plan: group.plan, namespace: group)
end end
let(:user) { create(:user, group_view: :security_dashboard) } let(:user) { create(:user, group_view: :security_dashboard) }
context 'and Security Dashboard feature is available for a group' do context 'and Security Dashboard feature is available for a group' do
let(:group) { create(:group, plan: :gold_plan) } let(:group) { create(:group_with_plan, plan: :gold_plan) }
it 'displays the Security Dashboard view' do it 'displays the Security Dashboard view' do
visit group_path(group) visit group_path(group)
...@@ -54,7 +52,7 @@ describe 'Group overview', :js do ...@@ -54,7 +52,7 @@ describe 'Group overview', :js do
end end
context 'and Security Dashboard feature is not available for a group' do context 'and Security Dashboard feature is not available for a group' do
let(:group) { create(:group, plan: :bronze_plan) } let(:group) { create(:group_with_plan, plan: :bronze_plan) }
it 'displays the "Security Dashboard unavailable" empty state' do it 'displays the "Security Dashboard unavailable" empty state' do
visit group_path(group) visit group_path(group)
......
...@@ -50,7 +50,10 @@ describe ProjectsFinder do ...@@ -50,7 +50,10 @@ describe ProjectsFinder do
private private
def create_project(plan) def create_project(plan)
create(:project, :public, namespace: create(:namespace, plan: plan)) namespace = create(:namespace_with_plan, plan: plan)
namespace.update(plan: namespace.gitlab_subscription&.hosted_plan)
create(:project, :public, namespace: namespace)
end end
end end
end end
......
...@@ -39,13 +39,11 @@ describe GroupProjectsFinder do ...@@ -39,13 +39,11 @@ describe GroupProjectsFinder do
end end
context 'when security dashboard is enabled for a group' do context 'when security dashboard is enabled for a group' do
let(:group) { create(:group, plan: :gold_plan) } # overriding group from 'GroupProjectsFinder context' let(:group) { create(:group_with_plan, plan: :gold_plan) } # overriding group from 'GroupProjectsFinder context'
before do before do
stub_licensed_features(security_dashboard: true) stub_licensed_features(security_dashboard: true)
enable_namespace_license_check! enable_namespace_license_check!
create(:gitlab_subscription, hosted_plan: group.plan, namespace: group)
end end
it { is_expected.to contain_exactly(project_with_reports) } it { is_expected.to contain_exactly(project_with_reports) }
......
...@@ -17,7 +17,7 @@ describe Gitlab::GroupPlansPreloader do ...@@ -17,7 +17,7 @@ describe Gitlab::GroupPlansPreloader do
group1 = create(:group, name: 'group-1') group1 = create(:group, name: 'group-1')
create(:gitlab_subscription, namespace: group1, hosted_plan_id: plan1.id) create(:gitlab_subscription, namespace: group1, hosted_plan_id: plan1.id)
group2 = create(:group, name: 'group-2', plan_id: plan2.id) group2 = create(:group, name: 'group-2')
create(:gitlab_subscription, namespace: group2, hosted_plan_id: plan2.id) create(:gitlab_subscription, namespace: group2, hosted_plan_id: plan2.id)
create(:group, name: 'group-3', parent: group1) create(:group, name: 'group-3', parent: group1)
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
describe Ci::Build do describe Ci::Build do
let_it_be(:group) { create(:group, plan: :bronze_plan) } let_it_be(:group) { create(:group_with_plan, plan: :bronze_plan) }
let(:project) { create(:project, :repository, group: group) } let(:project) { create(:project, :repository, group: group) }
let(:pipeline) do let(:pipeline) do
......
...@@ -214,53 +214,19 @@ describe Namespace do ...@@ -214,53 +214,19 @@ describe Namespace do
end end
context 'scopes' do context 'scopes' do
describe '.with_plan' do
let!(:namespace) { create :namespace, plan: namespace_plan }
context 'plan is set' do
let(:namespace_plan) { :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
describe '.with_feature_available_in_plan' do describe '.with_feature_available_in_plan' do
let!(:namespace) { create :namespace, plan: namespace_plan } let!(:namespace) { create(:namespace) }
context 'plan is nil' do context 'plan is nil' do
let(:namespace_plan) { nil }
it 'returns no namespace' do it 'returns no namespace' do
expect(described_class.with_feature_available_in_plan(:group_project_templates)).to be_empty expect(described_class.with_feature_available_in_plan(:group_project_templates)).to be_empty
end end
end end
context 'plan is set' do context 'plan is set' do
let(:namespace_plan) { :bronze_plan }
it 'returns namespaces with plan' do it 'returns namespaces with plan' do
create(:gitlab_subscription, :bronze, namespace: namespace) create(:gitlab_subscription, :bronze, namespace: namespace)
create(:gitlab_subscription, :free, namespace: create(:namespace)) create(:namespace_with_plan, plan: :free_plan)
expect(described_class.with_feature_available_in_plan(:audit_events)).to eq([namespace]) expect(described_class.with_feature_available_in_plan(:audit_events)).to eq([namespace])
end end
......
...@@ -121,8 +121,8 @@ describe GitlabSubscription do ...@@ -121,8 +121,8 @@ describe GitlabSubscription do
end end
it 'always returns 1 seat' do it 'always returns 1 seat' do
%w[bronze silver gold].each do |plan| [bronze_plan, silver_plan, gold_plan].each do |plan|
user_namespace.update!(plan: plan) gitlab_subscription.update!(hosted_plan: plan)
expect(gitlab_subscription.seats_in_use).to eq(1) expect(gitlab_subscription.seats_in_use).to eq(1)
end end
......
...@@ -302,13 +302,11 @@ describe API::Groups do ...@@ -302,13 +302,11 @@ describe API::Groups do
subject { get api("/groups/#{group.id}/projects", user), params: { with_security_reports: true } } subject { get api("/groups/#{group.id}/projects", user), params: { with_security_reports: true } }
context 'when security dashboard is enabled for a group' do context 'when security dashboard is enabled for a group' do
let(:group) { create(:group, plan: :gold_plan) } # overriding group from parent context let(:group) { create(:group_with_plan, plan: :gold_plan) } # overriding group from parent context
before do before do
stub_licensed_features(security_dashboard: true) stub_licensed_features(security_dashboard: true)
enable_namespace_license_check! enable_namespace_license_check!
create(:gitlab_subscription, hosted_plan: group.plan, namespace: group)
end end
it "returns only projects with security reports" do it "returns only projects with security reports" do
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'pushes wip limits to frontend' do RSpec.shared_examples 'pushes wip limits to frontend' do
let(:plan_license) { :free_plan } context 'self-hosted with correct license' do
let(:group) { create(:group, plan: plan_license) }
let(:global_license) { create(:license) }
before do before do
allow(License).to receive(:current).and_return(global_license) stub_licensed_features(wip_limits: true)
end end
context 'self-hosted with correct license' do
let(:plan_license) { :bronze_plan }
it 'is enabled for all groups if the license is correct' do it 'is enabled for all groups if the license is correct' do
expect(subject).to receive(:push_frontend_feature_flag).at_least(:once) expect(subject).to receive(:push_frontend_feature_flag).at_least(:once)
...@@ -27,7 +21,7 @@ RSpec.shared_examples 'pushes wip limits to frontend' do ...@@ -27,7 +21,7 @@ RSpec.shared_examples 'pushes wip limits to frontend' do
context 'for group with correct plan' do context 'for group with correct plan' do
before do before do
namespace = parent.is_a?(Group) ? parent : parent.namespace namespace = parent.is_a?(Group) ? parent : parent.namespace
namespace.plan = create(:bronze_plan) create(:gitlab_subscription, namespace: namespace, hosted_plan: create(:bronze_plan))
end end
it 'is enabled' do it 'is enabled' do
......
...@@ -48,7 +48,8 @@ RSpec.shared_examples 'dashboard gold trial callout' do ...@@ -48,7 +48,8 @@ RSpec.shared_examples 'dashboard gold trial callout' do
end end
it 'hides promotion callout if a gold plan is active', :js do it 'hides promotion callout if a gold plan is active', :js do
group = create(:group, name: 'gold group', plan: :gold_plan) group = create(:group_with_plan, name: 'gold group', plan: :gold_plan)
group.update(plan: group.gitlab_subscription.hosted_plan)
group.add_owner(user) group.add_owner(user)
visit page_path visit page_path
......
...@@ -98,12 +98,10 @@ describe 'layouts/nav/sidebar/_group' do ...@@ -98,12 +98,10 @@ describe 'layouts/nav/sidebar/_group' do
end end
describe 'security dashboard tab' do describe 'security dashboard tab' do
let(:group) { create(:group, plan: :gold_plan) } let(:group) { create(:group_with_plan, plan: :gold_plan) }
before do before do
enable_namespace_license_check! enable_namespace_license_check!
create(:gitlab_subscription, hosted_plan: group.plan, namespace: group)
end end
context 'when security dashboard feature is enabled' do context 'when security dashboard feature is enabled' do
...@@ -192,7 +190,7 @@ describe 'layouts/nav/sidebar/_group' do ...@@ -192,7 +190,7 @@ describe 'layouts/nav/sidebar/_group' do
end end
context 'when security dashboard feature is disabled' do context 'when security dashboard feature is disabled' do
let(:group) { create(:group, plan: :bronze_plan) } let(:group) { create(:group_with_plan, plan: :bronze_plan) }
it 'is not visible' do it 'is not visible' do
render render
......
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