Make it easier to define custom settings
Many CONSUL installations struggle when trying to define their own settings or trying to overwrite the default ones. Particularly because tests assume the default settings are used, so changing them breaks the test suite in many cases. So we're adding a custom setting model in order to make it easier to change the default settings and define new ones, while making sure doing so won't break the tests. While these settings can also be changed by administrators, defining custom settings in the code is useful in come cases. For example, when certain default settings have been decided while using staging environments and there's interest in using the same settings on production, when institutions would like to use the same custom settings across several CONSUL installations, or (when we implement multitenancy) when defining the same default settings for each new tenant.
This commit is contained in:
31
app/models/custom/setting.rb
Normal file
31
app/models/custom/setting.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
require_dependency Rails.root.join("app", "models", "setting").to_s
|
||||||
|
|
||||||
|
class Setting
|
||||||
|
class << self
|
||||||
|
alias_method :consul_defaults, :defaults
|
||||||
|
|
||||||
|
# Change this code when you'd like to add settings that aren't
|
||||||
|
# already present in the database. These settings will be added when
|
||||||
|
# first installing CONSUL, when deploying code with Capistrano, or
|
||||||
|
# when manually executing the `settings:add_new_settings` task.
|
||||||
|
#
|
||||||
|
# If a setting already exists in the database, changing its value in
|
||||||
|
# this file will have no effect unless the task `rake db:seed` is
|
||||||
|
# invoked or the method `Setting.reset_defaults` is executed. Doing
|
||||||
|
# so will overwrite the values of all existing settings in the
|
||||||
|
# database, so use with care.
|
||||||
|
#
|
||||||
|
# The tests in the spec/ folder rely on CONSUL's default settings, so
|
||||||
|
# it's recommended not to change the default settings in the test
|
||||||
|
# environment.
|
||||||
|
def defaults
|
||||||
|
if Rails.env.test?
|
||||||
|
consul_defaults
|
||||||
|
else
|
||||||
|
consul_defaults.merge({
|
||||||
|
# Overwrite default CONSUL settings or add new settings here
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user