test/unit/schemacop/v3/array_node_test.rb in schemacop-3.0.28 vs test/unit/schemacop/v3/array_node_test.rb in schemacop-3.0.29
- old
+ new
@@ -928,8 +928,33 @@
cont :string
cont :integer
end
end
end
+
+ def test_parse_json
+ schema :array, parse_json: true do
+ list :integer
+ end
+ assert_validation([1, 2, 3])
+ assert_validation('[1,2,3]')
+ assert_cast('[1,2,3]', [1, 2, 3])
+
+ assert_validation('[1,2,"3"]') do
+ error '/[2]', 'Invalid type, got type "String", expected "integer".'
+ end
+
+ assert_validation('{ "id": 42 }') do
+ error '/', 'Invalid type, got type "Hash", expected "array".'
+ end
+
+ assert_validation('{42]') do
+ error '/', /JSON parse error: "(\d+: )?unexpected token at '{42]'"\./
+ end
+
+ assert_validation('"foo"') do
+ error '/', 'Invalid type, got type "String", expected "array".'
+ end
+ end
end
end
end