FIX: Error when integer values are set as default of string type settings (#25898)
Why this change? ``` some_setting: default: 0 type: string ``` A theme setting like the above will cause an error to be thrown on the server when importing the theme because the default would be parsed as an integer which caused an error to be thrown when we are validating the value of the setting. What does this change do? Convert the value to a string when working with string typed theme settings.
This commit is contained in:
parent
e84d462e28
commit
412b36cc93
|
@ -45,7 +45,7 @@ class ThemeSettingsValidator
|
||||||
)
|
)
|
||||||
when types[:string]
|
when types[:string]
|
||||||
validate_value_in_range!(
|
validate_value_in_range!(
|
||||||
value.length,
|
value.to_s.length,
|
||||||
min: opts[:min],
|
min: opts[:min],
|
||||||
max: opts[:max],
|
max: opts[:max],
|
||||||
errors:,
|
errors:,
|
||||||
|
|
|
@ -14,6 +14,10 @@ string_setting_03:
|
||||||
default: "string value"
|
default: "string value"
|
||||||
textarea: true
|
textarea: true
|
||||||
|
|
||||||
|
string_setting_04:
|
||||||
|
default: 0
|
||||||
|
type: string
|
||||||
|
|
||||||
integer_setting: 51
|
integer_setting: 51
|
||||||
|
|
||||||
integer_setting_02:
|
integer_setting_02:
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
RSpec.describe ThemeSettingsValidator do
|
||||||
|
describe ".validate_value" do
|
||||||
|
it "does not throw an error when an integer value is given with type `string`" do
|
||||||
|
errors = described_class.validate_value(1, ThemeSetting.types[:string], {})
|
||||||
|
|
||||||
|
expect(errors).to eq([])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue