FIX: bypass all site setting work for shadowed method

This commit is contained in:
Sam 2017-10-27 11:12:44 +11:00
parent 530624d438
commit 70aed105a6
2 changed files with 36 additions and 1 deletions

View File

@ -65,6 +65,9 @@ module SiteSettingExtension
def setting(name_arg, default = nil, opts = {}) def setting(name_arg, default = nil, opts = {})
name = name_arg.to_sym name = name_arg.to_sym
shadowed_val = nil
mutex.synchronize do mutex.synchronize do
defaults.load_setting( defaults.load_setting(
name, name,
@ -82,6 +85,7 @@ module SiteSettingExtension
val = GlobalSetting.send(name) val = GlobalSetting.send(name)
unless val.nil? || (val == ''.freeze) unless val.nil? || (val == ''.freeze)
shadowed_val = val
hidden_settings << name hidden_settings << name
shadowed_settings << name shadowed_settings << name
end end
@ -104,7 +108,11 @@ module SiteSettingExtension
opts.extract!(*SiteSettings::TypeSupervisor::CONSUMED_OPTS) opts.extract!(*SiteSettings::TypeSupervisor::CONSUMED_OPTS)
) )
setup_methods(name) if !shadowed_val.nil?
setup_shadowed_methods(name, shadowed_val)
else
setup_methods(name)
end
end end
end end
@ -291,6 +299,24 @@ module SiteSettingExtension
[changes, deletions] [changes, deletions]
end end
def setup_shadowed_methods(name, value)
clean_name = name.to_s.sub("?", "").to_sym
define_singleton_method clean_name do
value
end
define_singleton_method "#{clean_name}?" do
value
end
define_singleton_method "#{clean_name}=" do |val|
Rails.logger.warn("An attempt was to change #{clean_name} SiteSetting to #{val} however it is shadowed so this will be ignored!")
nil
end
end
def setup_methods(name) def setup_methods(name)
clean_name = name.to_s.sub("?", "").to_sym clean_name = name.to_s.sub("?", "").to_sym

View File

@ -472,6 +472,7 @@ describe SiteSettingExtension do
it "should return default cause nothing is set" do it "should return default cause nothing is set" do
expect(settings.nada).to eq('nothing') expect(settings.nada).to eq('nothing')
end end
end end
context "with a false override" do context "with a false override" do
@ -484,6 +485,14 @@ describe SiteSettingExtension do
it "should return default cause nothing is set" do it "should return default cause nothing is set" do
expect(settings.bool).to eq(false) expect(settings.bool).to eq(false)
end end
it "should not trigger any message bus work if you try to set it" do
m = MessageBus.track_publish('/site_settings') do
settings.bool = true
expect(settings.bool).to eq(false)
end
expect(m.length).to eq(0)
end
end end
context "with global setting" do context "with global setting" do