Merge pull request #6393 from techAPJ/bad-json

FIX: ignore and log bad json values for custom fields
This commit is contained in:
Arpit Jalan
2018-09-13 15:54:01 +05:30
committed by GitHub
2 changed files with 59 additions and 4 deletions

View File

@@ -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' }