diff options
author | Rémy Coutable <remy@rymai.me> | 2017-01-14 00:18:40 -0500 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-01-15 01:07:29 -0500 |
commit | f6cc29ed83921c3dce98d8c519c4826e7cc8221a (patch) | |
tree | 72e16219c0c0609c2516ae9eb62bd9b3136f7a3f /lib/gitlab/current_settings.rb | |
parent | b038c53073b191df2044f96d4ff5d01a35b22d83 (diff) | |
download | gitlab-ce-f6cc29ed83921c3dce98d8c519c4826e7cc8221a.tar.gz |
Don't persist ApplicationSetting in test envdont-persist-application-settings-in-test-env
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/gitlab/current_settings.rb')
-rw-r--r-- | lib/gitlab/current_settings.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/gitlab/current_settings.rb b/lib/gitlab/current_settings.rb index c4fc3709c93..c79e17b57ee 100644 --- a/lib/gitlab/current_settings.rb +++ b/lib/gitlab/current_settings.rb @@ -9,7 +9,9 @@ module Gitlab end def ensure_application_settings! - if connect_to_db? + return fake_application_settings unless connect_to_db? + + unless ENV['IN_MEMORY_APPLICATION_SETTINGS'] == 'true' begin settings = ::ApplicationSetting.current # In case Redis isn't running or the Redis UNIX socket file is not available @@ -20,15 +22,23 @@ module Gitlab settings ||= ::ApplicationSetting.create_from_defaults unless ActiveRecord::Migrator.needs_migration? end - settings || fake_application_settings + settings || in_memory_application_settings end def sidekiq_throttling_enabled? current_application_settings.sidekiq_throttling_enabled? end + def in_memory_application_settings + @in_memory_application_settings ||= ApplicationSetting.new(ApplicationSetting::DEFAULTS) + # In case migrations the application_settings table is not created yet, + # we fallback to a simple OpenStruct + rescue ActiveRecord::StatementInvalid + fake_application_settings + end + def fake_application_settings - ApplicationSetting.new(ApplicationSetting::DEFAULTS) + OpenStruct.new(ApplicationSetting::DEFAULTS) end private |