Skip to content

Commit

Permalink
FIX: ThemeSettingsValidator.validate_value returning wrong error (d…
Browse files Browse the repository at this point in the history
…iscourse#25901)

Why this change?

Before this change, the error messages returned when validating theme
settings of typed objects was an array of array instead of just an
array.
  • Loading branch information
tgxworld authored Feb 27, 2024
1 parent 52a4912 commit 18ca3d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/theme_settings_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def validate_value(value, type, opts)
translation_prefix: "string",
)
when types[:objects]
errors.push(
errors.concat(
ThemeSettingsObjectValidator.validate_objects(schema: opts[:schema], objects: value),
)
end
Expand Down
25 changes: 25 additions & 0 deletions spec/lib/theme_settings_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,30 @@

expect(errors).to eq([])
end

it "returns the right error messages when value is invalid for type `objects`" do
errors =
described_class.validate_value(
[{ name: "something" }],
ThemeSetting.types[:objects],
{
schema: {
name: "test",
properties: {
name: {
type: "string",
validations: {
max_length: 1,
},
},
},
},
},
)

expect(errors).to contain_exactly(
"The property at JSON Pointer '/0/name' must be at most 1 characters long.",
)
end
end
end

0 comments on commit 18ca3d3

Please sign in to comment.