mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-06 21:30:25 +08:00
Before, when adding a `type: object` site setting, if it did not match the schema, the only message returned was `Invalid object.` With these changes, it is possible to understand which properties did no match the schema
19 lines
714 B
Ruby
19 lines
714 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe ObjectsSettingValidator do
|
|
let(:schema) { { name: "test", properties: { title: { type: "string", required: true } } } }
|
|
|
|
describe "#valid_value?" do
|
|
it "returns true for valid objects" do
|
|
validator = ObjectsSettingValidator.new(schema: schema)
|
|
expect(validator.valid_value?('[{"title": "hello"}]')).to eq(true)
|
|
expect(validator.error_message).to be_nil
|
|
end
|
|
|
|
it "returns false with specific error message for invalid objects" do
|
|
validator = ObjectsSettingValidator.new(schema: schema)
|
|
expect(validator.valid_value?("[{}]")).to eq(false)
|
|
expect(validator.error_message).to include("must be present")
|
|
end
|
|
end
|
|
end
|