Commit 7aa5fbdb authored by James Lopez's avatar James Lopez

Merge branch 'rp/use-check-namespace-plan' into 'master'

Check application settings instead of Gitlab.com?

See merge request gitlab-org/gitlab!64176
parents 44b8cb95 b1447617
...@@ -4,10 +4,12 @@ module GitlabSubscriptions ...@@ -4,10 +4,12 @@ module GitlabSubscriptions
class UpcomingReconciliation < ApplicationRecord class UpcomingReconciliation < ApplicationRecord
belongs_to :namespace, inverse_of: :upcoming_reconciliation, optional: true 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) def self.next(namespace_id = nil)
if ::Gitlab.com? if ::Gitlab::CurrentSettings.should_check_namespace_plan?
return unless namespace_id return unless namespace_id
self.find_by(namespace_id: namespace_id) self.find_by(namespace_id: namespace_id)
......
...@@ -19,7 +19,7 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do ...@@ -19,7 +19,7 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do
end end
before do before do
allow(::Gitlab).to receive(:com?).and_return(true) stub_application_setting(check_namespace_plan: true)
end end
it 'returns true and reconciliation date' do it 'returns true and reconciliation date' do
...@@ -51,9 +51,9 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do ...@@ -51,9 +51,9 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do
end end
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 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.display_upcoming_reconciliation_alert?(namespace)).to eq(false)
expect(helper.upcoming_reconciliation_hash(namespace)).to eq({}) expect(helper.upcoming_reconciliation_hash(namespace)).to eq({})
...@@ -119,9 +119,9 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do ...@@ -119,9 +119,9 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliationHelper do
end end
end end
context 'when gitlab.com' do context 'when instance has paid namespaces (ex: gitlab.com)' do
it 'returns false and empty hash' 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) enable_admin_mode!(user)
expect(helper.display_upcoming_reconciliation_alert?).to eq(false) expect(helper.display_upcoming_reconciliation_alert?).to eq(false)
......
...@@ -22,15 +22,15 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliation do ...@@ -22,15 +22,15 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliation do
) )
end end
context 'when gitlab.com' do context 'when instance has paid namespaces (ex: gitlab.com)' do
before do before do
allow(Gitlab).to receive(:com?).and_return(true) stub_application_setting(check_namespace_plan: true)
end end
it { is_expected.to validate_presence_of(:namespace) } it { is_expected.to validate_presence_of(:namespace) }
end 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) } it { is_expected.not_to validate_presence_of(:namespace) }
end end
end end
...@@ -78,13 +78,13 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliation do ...@@ -78,13 +78,13 @@ RSpec.describe GitlabSubscriptions::UpcomingReconciliation do
end end
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_it_be(:upcoming_reconciliation) { create(:upcoming_reconciliation, :saas) }
let(:namespace_id) { upcoming_reconciliation.namespace_id } let(:namespace_id) { upcoming_reconciliation.namespace_id }
before do before do
allow(::Gitlab).to receive(:com?).and_return(true) stub_application_setting(check_namespace_plan: true)
end end
it 'returns row for given namespace' do 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