Commit b1447617 authored by Reuben Pereira's avatar Reuben Pereira

Check application settings instead of Gitlab.com?

- Checking application settings is more extensible. It allows the same
  code to work in other SaaS offerings (like JH).
- It also makes it easier to test locally, since we can simply modify
  the application setting value in the local database, instead of
  modifying the Gitlab.com? method.
- See https://gitlab.com/gitlab-org/gitlab/-/issues/225101 for more
  details.
parent 32ad2cbf
......@@ -4,10 +4,12 @@ module GitlabSubscriptions
class UpcomingReconciliation < ApplicationRecord
belongs_to :namespace, inverse_of: :upcoming_reconciliation, optional: true
validates :namespace, uniqueness: true, presence: { if: proc { ::Gitlab.com? } }
# Validate presence of namespace_id if this is running on a GitLab instance
# that has paid namespaces.
validates :namespace, uniqueness: true, presence: { if: proc { ::Gitlab::CurrentSettings.should_check_namespace_plan? } }
def self.next(namespace_id = nil)
if ::Gitlab.com?
if ::Gitlab::CurrentSettings.should_check_namespace_plan?
return unless namespace_id
self.find_by(namespace_id: namespace_id)
......
......@@ -19,7 +19,7 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do
end
before do
allow(::Gitlab).to receive(:com?).and_return(true)
stub_application_setting(check_namespace_plan: true)
end
it 'returns true and reconciliation date' do
......@@ -51,9 +51,9 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do
end
end
context 'when not gitlab.com' do
context 'when instance does not have paid namespaces (ex: self managed instance)' do
it 'returns false and empty hash' do
allow(::Gitlab).to receive(:com?).and_return(false)
stub_application_setting(check_namespace_plan: false)
expect(helper.display_upcoming_reconciliation_alert?(namespace)).to eq(false)
expect(helper.upcoming_reconciliation_hash(namespace)).to eq({})
......@@ -119,9 +119,9 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do
end
end
context 'when gitlab.com' do
context 'when instance has paid namespaces (ex: gitlab.com)' do
it 'returns false and empty hash' do
allow(::Gitlab).to receive(:com?).and_return(true)
stub_application_setting(check_namespace_plan: true)
enable_admin_mode!(user)
expect(helper.display_upcoming_reconciliation_alert?).to eq(false)
......
......@@ -22,15 +22,15 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliation do
)
end
context 'when gitlab.com' do
context 'when instance has paid namespaces (ex: gitlab.com)' do
before do
allow(Gitlab).to receive(:com?).and_return(true)
stub_application_setting(check_namespace_plan: true)
end
it { is_expected.to validate_presence_of(:namespace) }
end
context 'when not gitlab.com' do
context 'when namespaces are not paid (ex: self managed instance)' do
it { is_expected.not_to validate_presence_of(:namespace) }
end
end
......@@ -78,13 +78,13 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliation do
end
end
context 'when SaaS' do
context 'when instance has paid namespaces (ex: gitlab.com)' do
let_it_be(:upcoming_reconciliation) { create(:upcoming_reconciliation, :saas) }
let(:namespace_id) { upcoming_reconciliation.namespace_id }
before do
allow(::Gitlab).to receive(:com?).and_return(true)
stub_application_setting(check_namespace_plan: true)
end
it 'returns row for given namespace' do
......
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