summaryrefslogtreecommitdiff
path: root/lib/gitlab/current_settings.rb
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2017-01-14 00:18:40 -0500
committerRémy Coutable <remy@rymai.me>2017-01-15 01:07:29 -0500
commitf6cc29ed83921c3dce98d8c519c4826e7cc8221a (patch)
tree72e16219c0c0609c2516ae9eb62bd9b3136f7a3f /lib/gitlab/current_settings.rb
parentb038c53073b191df2044f96d4ff5d01a35b22d83 (diff)
downloadgitlab-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.rb16
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