Commit 004ecae8 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'spec-fixes-plan-id' into 'master'

Remove plan from namespaces factory

See merge request gitlab-org/gitlab!28885
parents bd1739c5 33555bc7
......@@ -36,7 +36,6 @@ module EE
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 :with_plan, -> { where.not(plan_id: nil) }
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_shared_runners_minutes_exceeding_default_limit, -> do
......
......@@ -60,4 +60,21 @@ FactoryBot.define do
group: group)
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
......@@ -2,16 +2,6 @@
FactoryBot.modify 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
namespace_statistics factory: :namespace_statistics, shared_runners_seconds: 400.minutes.to_i
end
......
......@@ -370,37 +370,32 @@ describe 'Billing plan pages', :feature do
end
context 'on sub-group' do
let(:user2) { create(:user) }
let(:user3) { create(:user) }
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(:group) { create(:group_with_plan, plan: :bronze_plan) }
let(:plan) { bronze_plan }
let(:namespace) { group }
context 'on bronze' do
let(:plan) { bronze_plan }
let!(:group_member) { create(:group_member, :owner, group: group, user: user) }
let!(:subscription) do
create(:gitlab_subscription, namespace: namespace, hosted_plan: plan, seats: 15)
end
let(:subgroup1) { create(:group, parent: group) }
let!(:subgroup1_member) { create(:group_member, :owner, group: subgroup1) }
before do
visit page_path
end
let(:subgroup2) { create(:group, parent: subgroup1) }
let!(:subgroup2_member) { create(:group_member, :owner, group: subgroup2) }
it 'displays plan header' do
page.within('.billing-plan-header') do
expect(page).to have_content("#{subgroup2.full_name} is currently using the Bronze plan")
expect(page).to have_css('.billing-plan-logo .identicon')
expect(page.find('.btn-success')).to have_content('Manage plan')
end
let(:page_path) { group_billings_path(subgroup2) }
before do
visit page_path
end
expect(page).not_to have_css('.billing-plans')
it 'displays plan header' do
page.within('.billing-plan-header') do
expect(page).to have_content("#{subgroup2.full_name} is currently using the Bronze plan")
expect(page).to have_css('.billing-plan-logo .identicon')
expect(page.find('.btn-success')).to have_content('Manage plan')
end
expect(page).not_to have_css('.billing-plans')
end
end
......
......@@ -28,14 +28,12 @@ describe 'Group overview', :js do
before do
stub_licensed_features(security_dashboard: true)
enable_namespace_license_check!
create(:gitlab_subscription, hosted_plan: group.plan, namespace: group)
end
let(:user) { create(:user, group_view: :security_dashboard) }
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
visit group_path(group)
......@@ -54,7 +52,7 @@ describe 'Group overview', :js do
end
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
visit group_path(group)
......
......@@ -50,7 +50,10 @@ describe ProjectsFinder do
private
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
......
......@@ -39,13 +39,11 @@ describe GroupProjectsFinder do
end
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
stub_licensed_features(security_dashboard: true)
enable_namespace_license_check!
create(:gitlab_subscription, hosted_plan: group.plan, namespace: group)
end
it { is_expected.to contain_exactly(project_with_reports) }
......
......@@ -17,7 +17,7 @@ describe Gitlab::GroupPlansPreloader do
group1 = create(:group, name: 'group-1')
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(:group, name: 'group-3', parent: group1)
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
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(:pipeline) do
......
......@@ -214,53 +214,19 @@ describe Namespace do
end
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
let!(:namespace) { create :namespace, plan: namespace_plan }
let!(:namespace) { create(:namespace) }
context 'plan is nil' do
let(:namespace_plan) { nil }
it 'returns no namespace' do
expect(described_class.with_feature_available_in_plan(:group_project_templates)).to be_empty
end
end
context 'plan is set' do
let(:namespace_plan) { :bronze_plan }
it 'returns namespaces with plan' do
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])
end
......
......@@ -121,8 +121,8 @@ describe GitlabSubscription do
end
it 'always returns 1 seat' do
%w[bronze silver gold].each do |plan|
user_namespace.update!(plan: plan)
[bronze_plan, silver_plan, gold_plan].each do |plan|
gitlab_subscription.update!(hosted_plan: plan)
expect(gitlab_subscription.seats_in_use).to eq(1)
end
......
......@@ -302,13 +302,11 @@ describe API::Groups do
subject { get api("/groups/#{group.id}/projects", user), params: { with_security_reports: true } }
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
stub_licensed_features(security_dashboard: true)
enable_namespace_license_check!
create(:gitlab_subscription, hosted_plan: group.plan, namespace: group)
end
it "returns only projects with security reports" do
......
# frozen_string_literal: true
RSpec.shared_examples 'pushes wip limits to frontend' do
let(:plan_license) { :free_plan }
let(:group) { create(:group, plan: plan_license) }
let(:global_license) { create(:license) }
before do
allow(License).to receive(:current).and_return(global_license)
end
context 'self-hosted with correct license' do
let(:plan_license) { :bronze_plan }
before do
stub_licensed_features(wip_limits: true)
end
it 'is enabled for all groups if the license is correct' do
expect(subject).to receive(:push_frontend_feature_flag).at_least(:once)
......@@ -27,7 +21,7 @@ RSpec.shared_examples 'pushes wip limits to frontend' do
context 'for group with correct plan' do
before do
namespace = parent.is_a?(Group) ? parent : parent.namespace
namespace.plan = create(:bronze_plan)
create(:gitlab_subscription, namespace: namespace, hosted_plan: create(:bronze_plan))
end
it 'is enabled' do
......
......@@ -48,7 +48,8 @@ RSpec.shared_examples 'dashboard gold trial callout' do
end
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)
visit page_path
......
......@@ -98,12 +98,10 @@ describe 'layouts/nav/sidebar/_group' do
end
describe 'security dashboard tab' do
let(:group) { create(:group, plan: :gold_plan) }
let(:group) { create(:group_with_plan, plan: :gold_plan) }
before do
enable_namespace_license_check!
create(:gitlab_subscription, hosted_plan: group.plan, namespace: group)
end
context 'when security dashboard feature is enabled' do
......@@ -192,7 +190,7 @@ describe 'layouts/nav/sidebar/_group' do
end
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
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