Use a Gitlab::FakeApplicationSettings when migrations are pending

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2019-03-26 15:33:56 +01:00
parent 81fe9e9b2e
commit 90718774e1
No known key found for this signature in database
GPG key ID: 98DFFD1C0C62B70B
2 changed files with 12 additions and 3 deletions

View file

@ -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

View file

@ -116,8 +116,7 @@ describe Gitlab::CurrentSettings 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
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