mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Don't rely on setting data type read from database
This commit is contained in:
@ -100,7 +100,8 @@ class SiteSettings::TypeSupervisor
|
|||||||
|
|
||||||
def to_rb_value(name, value, override_type = nil)
|
def to_rb_value(name, value, override_type = nil)
|
||||||
name = name.to_sym
|
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
|
case type
|
||||||
when self.class.types[:float]
|
when self.class.types[:float]
|
||||||
|
@ -124,6 +124,15 @@ describe SiteSettingExtension do
|
|||||||
expect(settings2.hello).to eq(99)
|
expect(settings2.hello).to eq(99)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "multisite" do
|
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)).to eq 2
|
||||||
expect(settings.type_supervisor.to_rb_value(:type_custom, '2|3')).to eq '2|3'
|
expect(settings.type_supervisor.to_rb_value(:type_custom, '2|3')).to eq '2|3'
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user