Commit a9d9907a authored by Stan Hu's avatar Stan Hu

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
parents 62461f77 43afcd03
...@@ -47,7 +47,7 @@ module Gitlab ...@@ -47,7 +47,7 @@ module Gitlab
# defaults for missing columns. # defaults for missing columns.
if ActiveRecord::Migrator.needs_migration? if ActiveRecord::Migrator.needs_migration?
db_attributes = current_settings&.attributes || {} db_attributes = current_settings&.attributes || {}
::ApplicationSetting.build_from_defaults(db_attributes) fake_application_settings(db_attributes)
elsif current_settings.present? elsif current_settings.present?
current_settings current_settings
else else
......
...@@ -115,9 +115,8 @@ describe Gitlab::CurrentSettings do ...@@ -115,9 +115,8 @@ describe Gitlab::CurrentSettings do
shared_examples 'a non-persisted ApplicationSetting object' do shared_examples 'a non-persisted ApplicationSetting object' do
let(:current_settings) { described_class.current_application_settings } let(:current_settings) { described_class.current_application_settings }
it 'returns a non-persisted ApplicationSetting object' do it 'returns a FakeApplicationSettings object' do
expect(current_settings).to be_a(ApplicationSetting) expect(current_settings).to be_a(Gitlab::FakeApplicationSettings)
expect(current_settings).not_to be_persisted
end end
it 'uses the default value from ApplicationSetting.defaults' do it 'uses the default value from ApplicationSetting.defaults' do
...@@ -146,6 +145,16 @@ describe Gitlab::CurrentSettings 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 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) expect(current_settings.home_page_url).to eq(db_settings.home_page_url)
end 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
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