FIX: bypass all site setting work for shadowed method
This commit is contained in:
parent
530624d438
commit
70aed105a6
|
@ -65,6 +65,9 @@ module SiteSettingExtension
|
|||
|
||||
def setting(name_arg, default = nil, opts = {})
|
||||
name = name_arg.to_sym
|
||||
|
||||
shadowed_val = nil
|
||||
|
||||
mutex.synchronize do
|
||||
defaults.load_setting(
|
||||
name,
|
||||
|
@ -82,6 +85,7 @@ module SiteSettingExtension
|
|||
val = GlobalSetting.send(name)
|
||||
|
||||
unless val.nil? || (val == ''.freeze)
|
||||
shadowed_val = val
|
||||
hidden_settings << name
|
||||
shadowed_settings << name
|
||||
end
|
||||
|
@ -104,7 +108,11 @@ module SiteSettingExtension
|
|||
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
|
||||
|
||||
|
@ -291,6 +299,24 @@ module SiteSettingExtension
|
|||
[changes, deletions]
|
||||
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)
|
||||
clean_name = name.to_s.sub("?", "").to_sym
|
||||
|
||||
|
|
|
@ -472,6 +472,7 @@ describe SiteSettingExtension do
|
|||
it "should return default cause nothing is set" do
|
||||
expect(settings.nada).to eq('nothing')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "with a false override" do
|
||||
|
@ -484,6 +485,14 @@ describe SiteSettingExtension do
|
|||
it "should return default cause nothing is set" do
|
||||
expect(settings.bool).to eq(false)
|
||||
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
|
||||
|
||||
context "with global setting" do
|
||||
|
|
Loading…
Reference in New Issue