FIX: Don't rely on setting data type read from database
This commit is contained in:
parent
9989c8179d
commit
84d14fd8a0
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue