mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: ignore and log bad json values for custom fields
This commit is contained in:
@@ -187,6 +187,47 @@ describe HasCustomFields do
|
||||
expect(test_item2.custom_fields).to eq("sixto" => "rodriguez", "de" => "la playa")
|
||||
end
|
||||
|
||||
it "supports arrays in json fields" do
|
||||
field_type = "json_array"
|
||||
CustomFieldsTestItem.register_custom_field_type(field_type, :json)
|
||||
|
||||
item = CustomFieldsTestItem.new
|
||||
item.custom_fields = {
|
||||
"json_array" => [{ a: "test" }, { b: "another" }]
|
||||
}
|
||||
item.save
|
||||
|
||||
item.reload
|
||||
|
||||
expect(item.custom_fields[field_type]).to eq(
|
||||
[{ "a" => "test" }, { "b" => "another" }]
|
||||
)
|
||||
|
||||
item.custom_fields["json_array"] = ['a', 'b']
|
||||
item.save
|
||||
|
||||
item.reload
|
||||
|
||||
expect(item.custom_fields[field_type]).to eq(["a", "b"])
|
||||
end
|
||||
|
||||
it "will not fail to load custom fields if json is corrupt" do
|
||||
|
||||
field_type = "bad_json"
|
||||
CustomFieldsTestItem.register_custom_field_type(field_type, :json)
|
||||
|
||||
item = CustomFieldsTestItem.create!
|
||||
|
||||
CustomFieldsTestItemCustomField.create!(
|
||||
custom_fields_test_item_id: item.id,
|
||||
name: field_type,
|
||||
value: "{test"
|
||||
)
|
||||
|
||||
item = item.reload
|
||||
expect(item.custom_fields[field_type]).to eq({})
|
||||
end
|
||||
|
||||
it "supports bulk retrieval with a list of ids" do
|
||||
item1 = CustomFieldsTestItem.new
|
||||
item1.custom_fields = { "a" => ["b", "c", "d"], 'not_whitelisted' => 'secret' }
|
||||
|
||||
Reference in New Issue
Block a user