Commit 39f24f09 authored by Mark Chao's avatar Mark Chao Committed by Alper Akgun

Avoid GitlabSubscription generation outside SaaS

parent e5881afe
...@@ -179,13 +179,15 @@ module EE ...@@ -179,13 +179,15 @@ module EE
override :actual_plan override :actual_plan
def actual_plan def actual_plan
strong_memoize(:actual_plan) do strong_memoize(:actual_plan) do
next ::Plan.default unless ::Gitlab.com?
if parent_id if parent_id
root_ancestor.actual_plan root_ancestor.actual_plan
else else
subscription = find_or_create_subscription subscription = gitlab_subscription || generate_subscription
hosted_plan_for(subscription) hosted_plan_for(subscription) || ::Plan.free
end end
end || fallback_plan end
end end
def closest_gitlab_subscription def closest_gitlab_subscription
...@@ -444,14 +446,6 @@ module EE ...@@ -444,14 +446,6 @@ module EE
projects_query.with_shared_runners.any? projects_query.with_shared_runners.any?
end end
def fallback_plan
if ::Gitlab.com?
::Plan.free
else
::Plan.default
end
end
def validate_shared_runner_minutes_support def validate_shared_runner_minutes_support
return if root? return if root?
...@@ -487,13 +481,6 @@ module EE ...@@ -487,13 +481,6 @@ module EE
self.file_template_project_id = nil self.file_template_project_id = nil
end end
def find_or_create_subscription
# Hosted subscriptions are only available for root groups for now.
return if parent_id
gitlab_subscription || generate_subscription
end
def generate_subscription def generate_subscription
return unless persisted? return unless persisted?
return if ::Gitlab::Database.read_only? return if ::Gitlab::Database.read_only?
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Changes GL.com plan for group', :js do RSpec.describe 'Changes GL.com plan for group', :js, :saas do
include WaitForRequests include WaitForRequests
let!(:premium_plan) { create(:premium_plan) } let!(:premium_plan) { create(:premium_plan) }
......
...@@ -23,7 +23,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::AfterConfig do ...@@ -23,7 +23,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::AfterConfig do
project.add_developer(user) project.add_developer(user)
end end
describe 'credit card requirement' do describe 'credit card requirement', :saas do
context 'when user does not have credit card for pipelines in project' do context 'when user does not have credit card for pipelines in project' do
before do before do
allow(user) allow(user)
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Ci::Subscriptions::Project do RSpec.describe Ci::Subscriptions::Project do
let_it_be(:upstream_project) { create(:project, :public) } let_it_be_with_reload(:upstream_project) { create(:project, :public) }
let_it_be(:downstream_project) { create(:project) } let_it_be_with_reload(:downstream_project) { create(:project) }
describe 'Relations' do describe 'Relations' do
it { is_expected.to belong_to(:downstream_project).required } it { is_expected.to belong_to(:downstream_project).required }
......
...@@ -5,7 +5,7 @@ require 'spec_helper' ...@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Dast::ProfileSchedule, type: :model do RSpec.describe Dast::ProfileSchedule, type: :model do
let(:dast_profile_schedule) { create(:dast_profile_schedule, project: project) } let(:dast_profile_schedule) { create(:dast_profile_schedule, project: project) }
let_it_be(:project) { create(:project) } let_it_be_with_reload(:project) { create(:project) }
let_it_be(:inactive_dast_profile_schedule) { create(:dast_profile_schedule, active: false, project: project) } let_it_be(:inactive_dast_profile_schedule) { create(:dast_profile_schedule, active: false, project: project) }
subject { dast_profile_schedule } subject { dast_profile_schedule }
......
...@@ -735,8 +735,7 @@ RSpec.describe Namespace do ...@@ -735,8 +735,7 @@ RSpec.describe Namespace do
it 'generates a subscription and returns default plan' do it 'generates a subscription and returns default plan' do
expect(namespace.actual_plan).to eq(Plan.default) expect(namespace.actual_plan).to eq(Plan.default)
# This should be revisited after https://gitlab.com/gitlab-org/gitlab/-/issues/214434 expect(namespace.gitlab_subscription).to be_nil
expect(namespace.gitlab_subscription).to be_present
end end
end end
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Quota::Deployments do RSpec.describe Gitlab::Ci::Pipeline::Quota::Deployments do
let_it_be(:namespace) { create(:namespace) } let_it_be_with_refind(:namespace) { create(:namespace) }
let_it_be(:default_plan, reload: true) { create(:default_plan) } let_it_be_with_reload(:default_plan) { create(:default_plan) }
let_it_be(:project, reload: true) { create(:project, :repository, namespace: namespace) } let_it_be_with_reload(:project) { create(:project, :repository, namespace: namespace) }
let_it_be(:plan_limits) { create(:plan_limits, plan: default_plan) } let_it_be(:plan_limits) { create(:plan_limits, plan: default_plan) }
let(:pipeline) { build_stubbed(:ci_pipeline, project: project) } let(:pipeline) { build_stubbed(:ci_pipeline, project: project) }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Seed::Build do RSpec.describe Gitlab::Ci::Pipeline::Seed::Build do
let_it_be(:project) { create(:project, :repository) } let_it_be_with_reload(:project) { create(:project, :repository) }
let_it_be(:head_sha) { project.repository.head_commit.id } let_it_be(:head_sha) { project.repository.head_commit.id }
let(:pipeline) { build(:ci_empty_pipeline, project: project, sha: head_sha) } let(:pipeline) { build(:ci_empty_pipeline, project: project, sha: head_sha) }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Ci::PipelineSchedule do RSpec.describe Ci::PipelineSchedule do
let_it_be(:project) { create_default(:project) } let_it_be_with_reload(:project) { create_default(:project) }
subject { build(:ci_pipeline_schedule) } subject { build(:ci_pipeline_schedule) }
......
...@@ -32,8 +32,8 @@ RSpec.describe ProjectHook do ...@@ -32,8 +32,8 @@ RSpec.describe ProjectHook do
end end
describe '#rate_limit' do describe '#rate_limit' do
let_it_be(:hook) { create(:project_hook) }
let_it_be(:plan_limits) { create(:plan_limits, :default_plan, web_hook_calls: 100) } let_it_be(:plan_limits) { create(:plan_limits, :default_plan, web_hook_calls: 100) }
let_it_be(:hook) { create(:project_hook) }
it 'returns the default limit' do it 'returns the default limit' do
expect(hook.rate_limit).to be(100) expect(hook.rate_limit).to be(100)
......
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