Commit 539ad4bc authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'do-not-generate-subscription-from-namespace-plan-id' into 'master'

Do not generate subscriptions from plan_id

See merge request gitlab-org/gitlab!28453
parents 487dfcce 7dc7d5a8
...@@ -444,7 +444,7 @@ module EE ...@@ -444,7 +444,7 @@ module EE
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.read_only?
create_gitlab_subscription( create_gitlab_subscription(
plan_code: plan&.name, plan_code: Plan::FREE,
trial: trial_active?, trial: trial_active?,
start_date: created_at, start_date: created_at,
seats: 0 seats: 0
......
...@@ -31,3 +31,22 @@ FactoryBot.modify do ...@@ -31,3 +31,22 @@ FactoryBot.modify do
end end
end end
end end
FactoryBot.define do
factory :namespace_with_plan, parent: :namespace do
transient do
plan { :default_plan }
trial_ends_on { nil }
end
after(:create) do |namespace, evaluator|
if evaluator.plan
create(:gitlab_subscription,
namespace: namespace,
hosted_plan: create(evaluator.plan),
trial: evaluator.trial_ends_on.present?,
trial_ends_on: evaluator.trial_ends_on)
end
end
end
end
...@@ -425,7 +425,6 @@ describe 'Billing plan pages', :feature do ...@@ -425,7 +425,6 @@ describe 'Billing plan pages', :feature do
end end
before do before do
expect_any_instance_of(EE::Namespace).to receive(:plan).at_least(:once).and_return(nil)
visit profile_billings_path visit profile_billings_path
end end
......
...@@ -224,7 +224,6 @@ describe EE::UserCalloutsHelper do ...@@ -224,7 +224,6 @@ describe EE::UserCalloutsHelper do
let_it_be(:silver_plan) { create(:silver_plan) } let_it_be(:silver_plan) { create(:silver_plan) }
let_it_be(:gold_plan) { create(:gold_plan) } let_it_be(:gold_plan) { create(:gold_plan) }
let(:user) { namespace.owner } let(:user) { namespace.owner }
let(:gitlab_subscription) { create(:gitlab_subscription, namespace: namespace) }
where(:never_had_trial?, :show_gold_trial?, :gold_plan?, :free_plan?, :should_render?) do where(:never_had_trial?, :show_gold_trial?, :gold_plan?, :free_plan?, :should_render?) do
true | true | false | false | true true | true | false | false | true
...@@ -248,12 +247,13 @@ describe EE::UserCalloutsHelper do ...@@ -248,12 +247,13 @@ describe EE::UserCalloutsHelper do
with_them do with_them do
before do before do
allow(helper).to receive(:show_gold_trial?) { show_gold_trial? } allow(helper).to receive(:show_gold_trial?) { show_gold_trial? }
namespace.update(plan: gold_plan) if gold_plan?
namespace.update(plan: silver_plan) if !gold_plan? && !free_plan?
unless never_had_trial? if !never_had_trial?
namespace.update(plan: free_plan) create(:gitlab_subscription, namespace: namespace, hosted_plan: free_plan, trial_ends_on: Date.yesterday)
namespace.create_gitlab_subscription(trial_ends_on: Date.yesterday) elsif gold_plan?
create(:gitlab_subscription, namespace: namespace, hosted_plan: gold_plan)
elsif !free_plan?
create(:gitlab_subscription, namespace: namespace, hosted_plan: silver_plan)
end end
end end
......
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
describe Namespace do describe Namespace do
shared_examples 'plan helper' do |namespace_plan| shared_examples 'plan helper' do |namespace_plan|
let(:namespace) { create(:namespace, plan: "#{plan_name}_plan") } let(:namespace) { create(:namespace_with_plan, plan: "#{plan_name}_plan") }
subject { namespace.public_send("#{namespace_plan}_plan?") } subject { namespace.public_send("#{namespace_plan}_plan?") }
...@@ -151,7 +151,7 @@ describe Namespace do ...@@ -151,7 +151,7 @@ describe Namespace do
end end
describe '#actual_plan_name' do describe '#actual_plan_name' do
let(:namespace) { create(:namespace, plan: :gold_plan) } let(:namespace) { create(:namespace) }
subject { namespace.actual_plan_name } subject { namespace.actual_plan_name }
...@@ -170,7 +170,7 @@ describe Namespace do ...@@ -170,7 +170,7 @@ describe Namespace do
end end
context 'when namespace is not persisted' do context 'when namespace is not persisted' do
let(:namespace) { build(:namespace, plan: :gold_plan) } let(:namespace) { build(:namespace) }
it 'returns free plan' do it 'returns free plan' do
is_expected.to eq('free') is_expected.to eq('free')
...@@ -182,8 +182,8 @@ describe Namespace do ...@@ -182,8 +182,8 @@ describe Namespace do
end end
context 'when DB is not read-only' do context 'when DB is not read-only' do
it 'returns gold plan' do it 'returns free plan' do
is_expected.to eq('gold') is_expected.to eq('free')
end end
it 'creates a gitlab_subscription' do it 'creates a gitlab_subscription' do
......
...@@ -715,17 +715,6 @@ describe Namespace do ...@@ -715,17 +715,6 @@ describe Namespace do
end end
describe '#actual_plan' do describe '#actual_plan' do
context 'when namespace has a plan associated' do
before do
namespace.update_attribute(:plan, gold_plan)
end
it 'generates a subscription with that plan code' do
expect(namespace.actual_plan).to eq(gold_plan)
expect(namespace.gitlab_subscription).to be_present
end
end
context 'when namespace has a subscription associated' do context 'when namespace has a subscription associated' do
before do before do
create(:gitlab_subscription, namespace: namespace, hosted_plan: gold_plan) create(:gitlab_subscription, namespace: namespace, hosted_plan: gold_plan)
......
...@@ -121,7 +121,6 @@ describe API::Namespaces do ...@@ -121,7 +121,6 @@ describe API::Namespaces do
aggregate_failures do aggregate_failures do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['plan']).to eq('silver')
expect(json_response['shared_runners_minutes_limit']).to eq(9001) expect(json_response['shared_runners_minutes_limit']).to eq(9001)
end end
end end
...@@ -130,7 +129,6 @@ describe API::Namespaces do ...@@ -130,7 +129,6 @@ describe API::Namespaces do
put api("/namespaces/#{group1.id}", admin), params: { plan: 'silver', shared_runners_minutes_limit: 9001 } put api("/namespaces/#{group1.id}", admin), params: { plan: 'silver', shared_runners_minutes_limit: 9001 }
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['plan']).to eq('silver')
expect(json_response['shared_runners_minutes_limit']).to eq(9001) expect(json_response['shared_runners_minutes_limit']).to eq(9001)
end end
end end
......
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