FIX: Don't rely on setting data type read from database

This commit is contained in:
Gerhard Schlager 2018-07-24 11:24:34 +02:00
parent 9989c8179d
commit 84d14fd8a0
3 changed files with 17 additions and 1 deletions

View File

@ -100,7 +100,8 @@ class SiteSettings::TypeSupervisor
def to_rb_value(name, value, override_type = nil)
name = name.to_sym
type = @types[name] = (override_type || @types[name] || get_data_type(name, value))
@types[name] = (@types[name] || get_data_type(name, value))
type = (override_type || @types[name])
case type
when self.class.types[:float]

View File

@ -124,6 +124,15 @@ describe SiteSettingExtension do
expect(settings2.hello).to eq(99)
end
it "does not override types in the type supervisor" do
settings.setting(:foo, "bar")
settings.provider.save(:foo, "bar", SiteSetting.types[:enum])
settings.refresh!
expect(settings.foo).to eq("bar")
settings.foo = "baz"
expect(settings.foo).to eq("baz")
end
end
describe "multisite" do

View File

@ -275,6 +275,12 @@ describe SiteSettings::TypeSupervisor do
expect(settings.type_supervisor.to_rb_value(:type_custom, 2)).to eq 2
expect(settings.type_supervisor.to_rb_value(:type_custom, '2|3')).to eq '2|3'
end
it 'should not modify the types of settings' do
types = SiteSettings::TypeSupervisor.types
settings.type_supervisor.to_rb_value(:default_locale, 'fr', types[:enum])
expect(settings.type_supervisor.to_db_value(:default_locale, 'en')).to eq(['en', types[:string]])
end
end
end