@@ -353,6 +353,39 @@ def test_put_content_type
353353 assert_match JSONAPI ::MEDIA_TYPE , headers [ 'Content-Type' ]
354354 end
355355
356+ def test_put_valid_json
357+ put '/posts/3' , params : '{"data": { "type": "posts", "id": "3", "attributes": { "title": "A great new Post" } } }' ,
358+ headers : {
359+ 'CONTENT_TYPE' => JSONAPI ::MEDIA_TYPE ,
360+ 'Accept' => JSONAPI ::MEDIA_TYPE
361+ }
362+
363+ assert_equal 200 , status
364+ end
365+
366+ def test_put_invalid_json
367+ put '/posts/3' , params : '{"data": { "type": "posts", "id": "3" "attributes": { "title": "A great new Post" } } }' ,
368+ headers : {
369+ 'CONTENT_TYPE' => JSONAPI ::MEDIA_TYPE ,
370+ 'Accept' => JSONAPI ::MEDIA_TYPE
371+ }
372+
373+ assert_equal 400 , status
374+ assert_equal 'Bad Request' , json_response [ 'errors' ] [ 0 ] [ 'title' ]
375+ assert_match 'unexpected token at' , json_response [ 'errors' ] [ 0 ] [ 'detail' ]
376+ end
377+
378+ def test_put_valid_json_but_array
379+ put '/posts/3' , params : '[{"data": { "type": "posts", "id": "3", "attributes": { "title": "A great new Post" } } }]' ,
380+ headers : {
381+ 'CONTENT_TYPE' => JSONAPI ::MEDIA_TYPE ,
382+ 'Accept' => JSONAPI ::MEDIA_TYPE
383+ }
384+
385+ assert_equal 400 , status
386+ assert_equal 'Request must be a hash' , json_response [ 'errors' ] [ 0 ] [ 'detail' ]
387+ end
388+
356389 def test_patch_content_type
357390 patch '/posts/3' , params :
358391 {
0 commit comments