mirror of
https://github.com/discourse/discourse.git
synced 2024-11-21 16:38:15 -06:00
FEATURE: Allow plugins to easily add defaults to GlobalSetting
usage: GlobalSetting.add_default("plugin_setting_name", "value")
This commit is contained in:
parent
0cdded8079
commit
20fbf81505
@ -137,6 +137,14 @@ class GlobalSetting
|
||||
end
|
||||
end
|
||||
|
||||
def self.add_default(name, default)
|
||||
unless self.respond_to? name
|
||||
define_singleton_method(name) do
|
||||
default
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class BaseProvider
|
||||
def self.coerce(setting)
|
||||
return setting == "true" if setting == "true" || setting == "false"
|
||||
|
@ -50,6 +50,20 @@ describe GlobalSetting do
|
||||
end
|
||||
end
|
||||
|
||||
describe '.add_default' do
|
||||
after do
|
||||
class <<GlobalSetting; remove_method :foo_bar_foo; end
|
||||
end
|
||||
|
||||
it "can correctly add defaults" do
|
||||
GlobalSetting.add_default "foo_bar_foo", 1
|
||||
expect(GlobalSetting.foo_bar_foo).to eq(1)
|
||||
|
||||
GlobalSetting.add_default "cdn_url", "a"
|
||||
expect(GlobalSetting.foo_bar_foo).not_to eq("a")
|
||||
end
|
||||
end
|
||||
|
||||
describe '.redis_config' do
|
||||
describe 'when slave config is not present' do
|
||||
it "should not set any connector" do
|
||||
|
Loading…
Reference in New Issue
Block a user