summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-03-29 13:13:10 +0000
committerStan Hu <stanhu@gmail.com>2019-03-29 13:13:10 +0000
commita9d9907a8e44c849835d08efbd25f29349749c72 (patch)
treee862e164750a608fd35433f8774b838fb3d37e06
parent62461f77b83de4508176bf0086008bbc2eb0a07b (diff)
parent43afcd03332b03ef6b51ac8bc67e8f121d71cc8c (diff)
downloadgitlab-ce-a9d9907a8e44c849835d08efbd25f29349749c72.tar.gz
Merge branch '59462-applicatonsettings-not-tolerant-of-missing-db-columns' into 'master'
Use a Gitlab::FakeApplicationSettings when migrations are pending Closes #59462 See merge request gitlab-org/gitlab-ce!26601
-rw-r--r--lib/gitlab/current_settings.rb2
-rw-r--r--spec/lib/gitlab/current_settings_spec.rb15
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb
index 552aad83dd4..469a7fd9f7b 100644
--- a/lib/gitlab/current_settings.rb
+++ b/lib/gitlab/current_settings.rb
@@ -47,7 +47,7 @@ module Gitlab
# defaults for missing columns.
if ActiveRecord::Migrator.needs_migration?
db_attributes = current_settings&.attributes || {}
- ::ApplicationSetting.build_from_defaults(db_attributes)
+ fake_application_settings(db_attributes)
elsif current_settings.present?
current_settings
else
diff --git a/spec/lib/gitlab/current_settings_spec.rb b/spec/lib/gitlab/current_settings_spec.rb
index 17d5eae24f5..909dbffa38f 100644
--- a/spec/lib/gitlab/current_settings_spec.rb
+++ b/spec/lib/gitlab/current_settings_spec.rb
@@ -115,9 +115,8 @@ describe Gitlab::CurrentSettings do
shared_examples 'a non-persisted ApplicationSetting object' do
let(:current_settings) { described_class.current_application_settings }
- it 'returns a non-persisted ApplicationSetting object' do
- expect(current_settings).to be_a(ApplicationSetting)
- expect(current_settings).not_to be_persisted
+ it 'returns a FakeApplicationSettings object' do
+ expect(current_settings).to be_a(Gitlab::FakeApplicationSettings)
end
it 'uses the default value from ApplicationSetting.defaults' do
@@ -146,6 +145,16 @@ describe Gitlab::CurrentSettings do
it 'uses the value from the DB attribute if present and not overridden by an accessor' do
expect(current_settings.home_page_url).to eq(db_settings.home_page_url)
end
+
+ context 'when a new column is used before being migrated' do
+ before do
+ allow(ApplicationSetting).to receive(:defaults).and_return({ foo: 'bar' })
+ end
+
+ it 'uses the default value if present' do
+ expect(current_settings.foo).to eq('bar')
+ end
+ end
end
end