@@ -456,6 +456,28 @@ def test_create_simple
456456 assert_equal json_response [ 'data' ] [ 'links' ] [ 'self' ] , response . location
457457 end
458458
459+ def test_create_simple_id_not_allowed
460+ set_content_type_header!
461+ post :create , params :
462+ {
463+ data : {
464+ type : 'posts' ,
465+ id : 'asdfg' ,
466+ attributes : {
467+ title : 'JR is Great' ,
468+ body : 'JSONAPIResources is the greatest thing since unsliced bread.'
469+ } ,
470+ relationships : {
471+ author : { data : { type : 'people' , id : '3' } }
472+ }
473+ }
474+ }
475+
476+ assert_response :bad_request
477+ assert_match /id is not allowed/ , response . body
478+ assert_equal nil , response . location
479+ end
480+
459481 def test_create_link_to_missing_object
460482 set_content_type_header!
461483 post :create , params :
@@ -508,6 +530,7 @@ def test_create_extra_param_allow_extra_params
508530 {
509531 data : {
510532 type : 'posts' ,
533+ id : 'my_id' ,
511534 attributes : {
512535 asdfg : 'aaaa' ,
513536 title : 'JR is Great' ,
@@ -526,10 +549,13 @@ def test_create_extra_param_allow_extra_params
526549 assert_equal 'JR is Great' , json_response [ 'data' ] [ 'attributes' ] [ 'title' ]
527550 assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.' , json_response [ 'data' ] [ 'attributes' ] [ 'body' ]
528551
529- assert_equal 1 , json_response [ 'meta' ] [ "warnings" ] . count
552+ assert_equal 2 , json_response [ 'meta' ] [ "warnings" ] . count
530553 assert_equal "Param not allowed" , json_response [ 'meta' ] [ "warnings" ] [ 0 ] [ "title" ]
531- assert_equal "asdfg is not allowed." , json_response [ 'meta' ] [ "warnings" ] [ 0 ] [ "detail" ]
554+ assert_equal "id is not allowed." , json_response [ 'meta' ] [ "warnings" ] [ 0 ] [ "detail" ]
532555 assert_equal '105' , json_response [ 'meta' ] [ "warnings" ] [ 0 ] [ "code" ]
556+ assert_equal "Param not allowed" , json_response [ 'meta' ] [ "warnings" ] [ 1 ] [ "title" ]
557+ assert_equal "asdfg is not allowed." , json_response [ 'meta' ] [ "warnings" ] [ 1 ] [ "detail" ]
558+ assert_equal '105' , json_response [ 'meta' ] [ "warnings" ] [ 1 ] [ "code" ]
533559 assert_equal json_response [ 'data' ] [ 'links' ] [ 'self' ] , response . location
534560 ensure
535561 JSONAPI . configuration . raise_if_parameters_not_allowed = true
0 commit comments