Commit ef28cf48 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'sh-fix-current-settings' into 'master'

Fix encrypted application settings not working with pending migrations

Closes #197988

See merge request gitlab-org/gitlab!24736
parents 867496ea b0c8bcd1
---
title: Fix application settings not working with pending migrations
merge_request:
author:
type: fixed
...@@ -50,7 +50,7 @@ module Gitlab ...@@ -50,7 +50,7 @@ module Gitlab
# need to be added to the application settings. To prevent Rake tasks # need to be added to the application settings. To prevent Rake tasks
# and other callers from failing, use any loaded settings and return # and other callers from failing, use any loaded settings and return
# defaults for missing columns. # defaults for missing columns.
if ActiveRecord::Base.connection.migration_context.needs_migration? if Gitlab::Runtime.rake? && ActiveRecord::Base.connection.migration_context.needs_migration?
db_attributes = current_settings&.attributes || {} db_attributes = current_settings&.attributes || {}
fake_application_settings(db_attributes) fake_application_settings(db_attributes)
elsif current_settings.present? elsif current_settings.present?
......
...@@ -120,17 +120,13 @@ describe Gitlab::CurrentSettings do ...@@ -120,17 +120,13 @@ describe Gitlab::CurrentSettings do
end end
context 'with pending migrations' do context 'with pending migrations' do
let(:current_settings) { described_class.current_application_settings }
before do before do
expect_any_instance_of(ActiveRecord::MigrationContext).to receive(:needs_migration?).and_return(true) allow(Gitlab::Runtime).to receive(:rake?).and_return(false)
end end
shared_examples 'a non-persisted ApplicationSetting object' do shared_examples 'a non-persisted ApplicationSetting object' do
let(:current_settings) { described_class.current_application_settings }
it 'returns a FakeApplicationSettings object' do
expect(current_settings).to be_a(Gitlab::FakeApplicationSettings)
end
it 'uses the default value from ApplicationSetting.defaults' do it 'uses the default value from ApplicationSetting.defaults' do
expect(current_settings.signup_enabled).to eq(ApplicationSetting.defaults[:signup_enabled]) expect(current_settings.signup_enabled).to eq(ApplicationSetting.defaults[:signup_enabled])
end end
...@@ -144,18 +140,16 @@ describe Gitlab::CurrentSettings do ...@@ -144,18 +140,16 @@ describe Gitlab::CurrentSettings do
end end
end end
context 'with no ApplicationSetting DB record' do context 'in a Rake task' do
it_behaves_like 'a non-persisted ApplicationSetting object' before do
end allow(Gitlab::Runtime).to receive(:rake?).and_return(true)
expect_any_instance_of(ActiveRecord::MigrationContext).to receive(:needs_migration?).and_return(true)
context 'with an existing ApplicationSetting DB record' do end
let!(:db_settings) { ApplicationSetting.build_from_defaults(home_page_url: 'http://mydomain.com').save! && ApplicationSetting.last }
let(:current_settings) { described_class.current_application_settings }
it_behaves_like 'a non-persisted ApplicationSetting object' it_behaves_like 'a non-persisted ApplicationSetting object'
it 'uses the value from the DB attribute if present and not overridden by an accessor' do it 'returns a FakeApplicationSettings object' do
expect(current_settings.home_page_url).to eq(db_settings.home_page_url) expect(current_settings).to be_a(Gitlab::FakeApplicationSettings)
end end
context 'when a new column is used before being migrated' do context 'when a new column is used before being migrated' do
...@@ -168,6 +162,20 @@ describe Gitlab::CurrentSettings do ...@@ -168,6 +162,20 @@ describe Gitlab::CurrentSettings do
end end
end end
end end
context 'with no ApplicationSetting DB record' do
it_behaves_like 'a non-persisted ApplicationSetting object'
end
context 'with an existing ApplicationSetting DB record' do
let!(:db_settings) { ApplicationSetting.build_from_defaults(home_page_url: 'http://mydomain.com').save! && ApplicationSetting.last }
it_behaves_like 'a non-persisted ApplicationSetting object'
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
end
end end
context 'when ApplicationSettings.current is present' do context 'when ApplicationSettings.current is present' 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