Commit d20cb5a7 authored by Robert Speicher's avatar Robert Speicher

Update specs to create Plans on-demand

parent 9c177d23
...@@ -77,7 +77,7 @@ describe Projects::Settings::IntegrationsController do ...@@ -77,7 +77,7 @@ describe Projects::Settings::IntegrationsController do
end end
context 'and namespace has a plan' do context 'and namespace has a plan' do
let(:namespace) { create(:group, :private, plan: Namespace::BRONZE_PLAN) } let(:namespace) { create(:group, :private, plan: :bronze_plan) }
it_behaves_like 'endpoint without disabled services' it_behaves_like 'endpoint without disabled services'
end end
......
...@@ -60,7 +60,7 @@ describe Projects::IssuesController do ...@@ -60,7 +60,7 @@ describe Projects::IssuesController do
context 'licensed by namespace' do context 'licensed by namespace' do
let(:globally_licensed) { true } let(:globally_licensed) { true }
let(:namespace) { create(:group, :private, plan: Namespace::BRONZE_PLAN) } let(:namespace) { create(:group, :private, plan: :bronze_plan) }
let(:project) { create(:project, namespace: namespace) } let(:project) { create(:project, namespace: namespace) }
before do before do
......
require 'spec_helper' require 'spec_helper'
describe EE::Gitlab::Ci::Pipeline::Quota::Activity do describe EE::Gitlab::Ci::Pipeline::Quota::Activity do
set(:namespace) { create(:namespace, plan: EE::Namespace::GOLD_PLAN) } set(:namespace) { create(:namespace, plan: :gold_plan) }
set(:project) { create(:project, namespace: namespace) } set(:project) { create(:project, namespace: namespace) }
let(:limit) { described_class.new(namespace, project) } let(:limit) { described_class.new(namespace, project) }
......
...@@ -15,7 +15,7 @@ describe Namespace do ...@@ -15,7 +15,7 @@ describe Namespace do
let!(:namespace) { create :namespace, plan: namespace_plan } let!(:namespace) { create :namespace, plan: namespace_plan }
context 'plan is set' do context 'plan is set' do
let(:namespace_plan) { EE::Namespace::BRONZE_PLAN } let(:namespace_plan) { :bronze_plan }
it 'returns namespaces with plan' do it 'returns namespaces with plan' do
expect(described_class.with_plan).to eq([namespace]) expect(described_class.with_plan).to eq([namespace])
...@@ -48,7 +48,7 @@ describe Namespace do ...@@ -48,7 +48,7 @@ describe Namespace do
context 'with a valid plan name' do context 'with a valid plan name' do
it 'is valid' do it 'is valid' do
group.plan = Namespace::BRONZE_PLAN group.plan = create(:bronze_plan)
expect(group).to be_valid expect(group).to be_valid
end end
...@@ -123,7 +123,7 @@ describe Namespace do ...@@ -123,7 +123,7 @@ describe Namespace do
end end
describe '#feature_available?' do describe '#feature_available?' do
let(:plan_license) { Namespace::BRONZE_PLAN } let(:plan_license) { :bronze_plan }
let(:group) { create(:group, plan: plan_license) } let(:group) { create(:group, plan: plan_license) }
let(:feature) { :service_desk } let(:feature) { :service_desk }
...@@ -155,7 +155,7 @@ describe Namespace do ...@@ -155,7 +155,7 @@ describe Namespace do
end end
context 'when feature available on the plan' do context 'when feature available on the plan' do
let(:plan_license) { Namespace::GOLD_PLAN } let(:plan_license) { :gold_plan }
context 'when feature available for current group' do context 'when feature available for current group' do
it 'returns true' do it 'returns true' do
...@@ -176,7 +176,7 @@ describe Namespace do ...@@ -176,7 +176,7 @@ describe Namespace do
context 'when feature not available in the plan' do context 'when feature not available in the plan' do
let(:feature) { :deploy_board } let(:feature) { :deploy_board }
let(:plan_license) { Namespace::BRONZE_PLAN } let(:plan_license) { :bronze_plan }
it 'returns false' do it 'returns false' do
is_expected.to be_falsy is_expected.to be_falsy
...@@ -194,8 +194,7 @@ describe Namespace do ...@@ -194,8 +194,7 @@ describe Namespace do
context 'when free plan has limit defined' do context 'when free plan has limit defined' do
before do before do
Plan.find_by(name: Namespace::FREE_PLAN) create(:free_plan, active_pipelines_limit: 40)
.update_column(:active_pipelines_limit, 40)
end end
it 'returns a free plan limits' do it 'returns a free plan limits' do
...@@ -205,7 +204,7 @@ describe Namespace do ...@@ -205,7 +204,7 @@ describe Namespace do
context 'when associated plan has no limit defined' do context 'when associated plan has no limit defined' do
before do before do
namespace.plan = Namespace::GOLD_PLAN namespace.plan = create(:gold_plan)
end end
it 'returns zero' do it 'returns zero' do
...@@ -215,7 +214,7 @@ describe Namespace do ...@@ -215,7 +214,7 @@ describe Namespace do
context 'when limit is defined' do context 'when limit is defined' do
before do before do
namespace.plan = Namespace::GOLD_PLAN namespace.plan = create(:gold_plan)
namespace.plan.update_column(:active_pipelines_limit, 10) namespace.plan.update_column(:active_pipelines_limit, 10)
end end
...@@ -234,8 +233,7 @@ describe Namespace do ...@@ -234,8 +233,7 @@ describe Namespace do
context 'when free plan has limit defined' do context 'when free plan has limit defined' do
before do before do
Plan.find_by(name: Namespace::FREE_PLAN) create(:free_plan, pipeline_size_limit: 40)
.update_column(:pipeline_size_limit, 40)
end end
it 'returns a free plan limits' do it 'returns a free plan limits' do
...@@ -245,7 +243,7 @@ describe Namespace do ...@@ -245,7 +243,7 @@ describe Namespace do
context 'when associated plan has no limits defined' do context 'when associated plan has no limits defined' do
before do before do
namespace.plan = Namespace::GOLD_PLAN namespace.plan = create(:gold_plan)
end end
it 'returns zero' do it 'returns zero' do
...@@ -255,7 +253,7 @@ describe Namespace do ...@@ -255,7 +253,7 @@ describe Namespace do
context 'when limit is defined' do context 'when limit is defined' do
before do before do
namespace.plan = Namespace::GOLD_PLAN namespace.plan = create(:gold_plan)
namespace.plan.update_column(:pipeline_size_limit, 15) namespace.plan.update_column(:pipeline_size_limit, 15)
end end
...@@ -482,7 +480,7 @@ describe Namespace do ...@@ -482,7 +480,7 @@ describe Namespace do
describe '#actual_plan' do describe '#actual_plan' do
context 'when namespace has a plan associated' do context 'when namespace has a plan associated' do
before do before do
namespace.plan = Namespace::GOLD_PLAN namespace.plan = create(:gold_plan)
end end
it 'returns an associated plan' do it 'returns an associated plan' do
...@@ -492,6 +490,10 @@ describe Namespace do ...@@ -492,6 +490,10 @@ describe Namespace do
end end
context 'when namespace does not have plan associated' do context 'when namespace does not have plan associated' do
before do
create(:free_plan)
end
it 'returns a free plan object' do it 'returns a free plan object' do
expect(namespace.plan).to be_nil expect(namespace.plan).to be_nil
expect(namespace.actual_plan.name).to eq 'free' expect(namespace.actual_plan.name).to eq 'free'
...@@ -502,7 +504,7 @@ describe Namespace do ...@@ -502,7 +504,7 @@ describe Namespace do
describe '#actual_plan_name' do describe '#actual_plan_name' do
context 'when namespace has a plan associated' do context 'when namespace has a plan associated' do
before do before do
namespace.plan = Namespace::GOLD_PLAN namespace.plan = create(:gold_plan)
end end
it 'returns an associated plan name' do it 'returns an associated plan name' do
......
...@@ -174,7 +174,7 @@ describe Project do ...@@ -174,7 +174,7 @@ describe Project do
context 'allowed by Plan License AND Global License' do context 'allowed by Plan License AND Global License' do
let(:allowed_on_global_license) { true } let(:allowed_on_global_license) { true }
let(:plan_license) { Plan.find_by(name: 'gold') } let(:plan_license) { create(:gold_plan) }
it 'returns true' do it 'returns true' do
is_expected.to eq(true) is_expected.to eq(true)
...@@ -183,7 +183,7 @@ describe Project do ...@@ -183,7 +183,7 @@ describe Project do
context 'not allowed by Plan License but project and namespace are public' do context 'not allowed by Plan License but project and namespace are public' do
let(:allowed_on_global_license) { true } let(:allowed_on_global_license) { true }
let(:plan_license) { Plan.find_by(name: 'bronze') } let(:plan_license) { create(:bronze_plan) }
it 'returns true' do it 'returns true' do
allow(namespace).to receive(:public?) { true } allow(namespace).to receive(:public?) { true }
...@@ -196,7 +196,7 @@ describe Project do ...@@ -196,7 +196,7 @@ describe Project do
unless License.plan_includes_feature?(License::STARTER_PLAN, feature_sym) unless License.plan_includes_feature?(License::STARTER_PLAN, feature_sym)
context 'not allowed by Plan License' do context 'not allowed by Plan License' do
let(:allowed_on_global_license) { true } let(:allowed_on_global_license) { true }
let(:plan_license) { Plan.find_by(name: 'bronze') } let(:plan_license) { create(:bronze_plan) }
it 'returns false' do it 'returns false' do
is_expected.to eq(false) is_expected.to eq(false)
...@@ -206,7 +206,7 @@ describe Project do ...@@ -206,7 +206,7 @@ describe Project do
context 'not allowed by Global License' do context 'not allowed by Global License' do
let(:allowed_on_global_license) { false } let(:allowed_on_global_license) { false }
let(:plan_license) { Plan.find_by(name: 'gold') } let(:plan_license) { create(:gold_plan) }
it 'returns false' do it 'returns false' do
is_expected.to eq(false) is_expected.to eq(false)
...@@ -679,7 +679,7 @@ describe Project do ...@@ -679,7 +679,7 @@ describe Project do
end end
context 'Service Desk available in namespace plan' do context 'Service Desk available in namespace plan' do
let(:namespace) { create(:namespace, plan: Namespace::SILVER_PLAN) } let(:namespace) { create(:namespace, plan: :silver_plan) }
it 'is enabled' do it 'is enabled' do
expect(project.service_desk_enabled?).to be_truthy expect(project.service_desk_enabled?).to be_truthy
...@@ -1163,7 +1163,7 @@ describe Project do ...@@ -1163,7 +1163,7 @@ describe Project do
end end
context 'and namespace has a plan' do context 'and namespace has a plan' do
let(:namespace) { create(:group, :private, plan: Namespace::BRONZE_PLAN) } let(:namespace) { create(:group, :private, plan: :bronze_plan) }
it_behaves_like 'project without disabled services' it_behaves_like 'project without disabled services'
end end
......
...@@ -96,7 +96,8 @@ describe Projects::CreateService, '#execute' do ...@@ -96,7 +96,8 @@ describe Projects::CreateService, '#execute' do
context 'when licensed on a namespace' do context 'when licensed on a namespace' do
it 'allows enabling mirrors' do it 'allows enabling mirrors' do
user.namespace.update!(plan: Plan.find_by(name: 'gold')) plan = create(:gold_plan)
user.namespace.update!(plan: plan)
project = create_project(user, opts) project = create_project(user, opts)
......
...@@ -28,7 +28,7 @@ FactoryGirl.define do ...@@ -28,7 +28,7 @@ FactoryGirl.define do
end end
before :create do |namespace, evaluator| before :create do |namespace, evaluator|
if evaluator.plan if evaluator.plan.present?
namespace.plan = create(evaluator.plan) namespace.plan = create(evaluator.plan)
end end
end end
......
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe 'Billing plan pages', :feature do describe 'Billing plan pages', :feature do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:bronze_plan) { Plan.find_by(name: 'bronze') } let(:bronze_plan) { create(:bronze_plan) }
let(:plans_data) do let(:plans_data) do
[ [
{ {
...@@ -141,9 +141,9 @@ describe 'Billing plan pages', :feature do ...@@ -141,9 +141,9 @@ describe 'Billing plan pages', :feature do
end end
context 'on sub-group', :nested_groups do context 'on sub-group', :nested_groups do
let(:group) { create(:group, plan: Namespace::BRONZE_PLAN) } let(:group) { create(:group, plan: :bronze_plan) }
let!(:group_member) { create(:group_member, :owner, group: group, user: user) } let!(:group_member) { create(:group_member, :owner, group: group, user: user) }
let(:subgroup1) { create(:group, parent: group, plan: Namespace::SILVER_PLAN) } let(:subgroup1) { create(:group, parent: group, plan: :silver_plan) }
let!(:subgroup1_member) { create(:group_member, :owner, group: subgroup1, user: user) } let!(:subgroup1_member) { create(:group_member, :owner, group: subgroup1, user: user) }
let(:subgroup2) { create(:group, parent: subgroup1) } let(:subgroup2) { create(:group, parent: subgroup1) }
let!(:subgroup2_member) { create(:group_member, :owner, group: subgroup2, user: user) } let!(:subgroup2_member) { create(:group_member, :owner, group: subgroup2, user: user) }
......
...@@ -30,8 +30,8 @@ feature 'Projects > Push Rules', :js do ...@@ -30,8 +30,8 @@ feature 'Projects > Push Rules', :js do
end end
context 'licensed' do context 'licensed' do
let(:bronze_plan) { Plan.find_by!(name: 'bronze') } let(:bronze_plan) { create(:bronze_plan) }
let(:gold_plan) { Plan.find_by!(name: 'gold') } let(:gold_plan) { create(:gold_plan) }
before do before do
stub_licensed_features(rule_attr => true) stub_licensed_features(rule_attr => true)
......
...@@ -165,7 +165,7 @@ eos ...@@ -165,7 +165,7 @@ eos
end end
context 'when namespace has a plan' do context 'when namespace has a plan' do
let(:namespace) { create(:group, :private, plan: Namespace::BRONZE_PLAN) } let(:namespace) { create(:group, :private, plan: :bronze_plan) }
it_behaves_like 'an enabled jenkins deprecated service' it_behaves_like 'an enabled jenkins deprecated service'
end end
......
...@@ -192,7 +192,7 @@ describe JenkinsService do ...@@ -192,7 +192,7 @@ describe JenkinsService do
end end
context 'when namespace has a plan' do context 'when namespace has a plan' do
let(:namespace) { create(:group, :private, plan: Namespace::BRONZE_PLAN) } let(:namespace) { create(:group, :private, plan: :bronze_plan) }
it 'adds default web hook headers to the request' do it 'adds default web hook headers to the request' do
jenkins_service.execute(push_sample_data) jenkins_service.execute(push_sample_data)
......
...@@ -169,7 +169,7 @@ describe PushRule do ...@@ -169,7 +169,7 @@ describe PushRule do
end end
context 'with GL.com plans' do context 'with GL.com plans' do
let(:group) { create(:group, plan: Plan.find_by!(name: gl_plan)) } let(:group) { create(:group, plan: plan) }
let(:project) { create(:project, namespace: group) } let(:project) { create(:project, namespace: group) }
let(:push_rule) { create(:push_rule, project: project) } let(:push_rule) { create(:push_rule, project: project) }
...@@ -179,19 +179,19 @@ describe PushRule do ...@@ -179,19 +179,19 @@ describe PushRule do
end end
context 'with a Bronze plan' do context 'with a Bronze plan' do
let(:gl_plan) { ::EE::Namespace::BRONZE_PLAN } let(:plan) { :bronze_plan }
it_behaves_like 'an unavailable push_rule' it_behaves_like 'an unavailable push_rule'
end end
context 'with a Silver plan' do context 'with a Silver plan' do
let(:gl_plan) { ::EE::Namespace::SILVER_PLAN } let(:plan) { :silver_plan }
it_behaves_like 'an available push_rule' it_behaves_like 'an available push_rule'
end end
context 'with a Gold plan' do context 'with a Gold plan' do
let(:gl_plan) { ::EE::Namespace::GOLD_PLAN } let(:plan) { :gold_plan }
it_behaves_like 'an available push_rule' it_behaves_like 'an available push_rule'
end end
......
...@@ -95,6 +95,10 @@ describe API::Namespaces do ...@@ -95,6 +95,10 @@ describe API::Namespaces do
end end
describe 'PUT /namespaces/:id' do describe 'PUT /namespaces/:id' do
before do
create(:silver_plan)
end
context 'when authenticated as admin' do context 'when authenticated as admin' do
it 'updates namespace using full_path' do it 'updates namespace using full_path' do
put api("/namespaces/#{group1.full_path}", admin), plan: 'silver', shared_runners_minutes_limit: 9001 put api("/namespaces/#{group1.full_path}", admin), plan: 'silver', shared_runners_minutes_limit: 9001
......
...@@ -75,7 +75,7 @@ describe API::V3::Github do ...@@ -75,7 +75,7 @@ describe API::V3::Github do
end end
it 'filters unlicensed namespace projects' do it 'filters unlicensed namespace projects' do
silver_plan = Plan.find_by!(name: 'silver') silver_plan = create(:silver_plan)
licensed_project = create(:project, :empty_repo) licensed_project = create(:project, :empty_repo)
licensed_project.add_reporter(user) licensed_project.add_reporter(user)
licensed_project.namespace.update!(plan_id: silver_plan.id) licensed_project.namespace.update!(plan_id: silver_plan.id)
......
...@@ -60,7 +60,7 @@ describe UpdateAllMirrorsWorker do ...@@ -60,7 +60,7 @@ describe UpdateAllMirrorsWorker do
context 'licensed' do context 'licensed' do
def scheduled_mirror(at:, licensed:) def scheduled_mirror(at:, licensed:)
namespace = create(:group, :public, plan: (Namespace::BRONZE_PLAN if licensed)) namespace = create(:group, :public, plan: (:bronze_plan if licensed))
project = create(:project, :public, :mirror, namespace: namespace) project = create(:project, :public, :mirror, namespace: namespace)
project.mirror_data.update!(next_execution_timestamp: at) project.mirror_data.update!(next_execution_timestamp: at)
......
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