A platform for community discussion. Free, open, simple.
FIX: Don't rely on setting data type read from database
Gerhard Schlager84d14fd8a0f8
diff --git a/lib/site_settings/type_supervisor.rb b/lib/site_settings/type_supervisor.rbindex f1ca2e3110e..25860d1da9a 100644--- a/lib/site_settings/type_supervisor.rb+++ b/lib/site_settings/type_supervisor.rb@@ -100,7 +100,8 @@ class SiteSettings::TypeSupervisordef 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 typewhen self.class.types[:float]diff --git a/spec/components/site_setting_extension_spec.rb b/spec/components/site_setting_extension_spec.rbindex 1e67d99a29b..3f2b862c4ac 100644--- a/spec/components/site_setting_extension_spec.rb+++ b/spec/components/site_setting_extension_spec.rb@@ -124,6 +124,15 @@ describe SiteSettingExtension doexpect(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")+ endenddescribe "multisite" dodiff --git a/spec/components/site_settings/type_supervisor_spec.rb b/spec/components/site_settings/type_supervisor_spec.rbindex e404213508b..fb27122c867 100644--- a/spec/components/site_settings/type_supervisor_spec.rb+++ b/spec/components/site_settings/type_supervisor_spec.rb@@ -275,6 +275,12 @@ describe SiteSettings::TypeSupervisor doexpect(settings.type_supervisor.to_rb_value(:type_custom, 2)).to eq 2expect(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]])+ endendend