@@ -511,6 +511,28 @@ def test_create_simple
511511 assert_equal json_response [ 'data' ] [ 'links' ] [ 'self' ] , response . location
512512 end
513513
514+ def test_create_simple_id_not_allowed
515+ set_content_type_header!
516+ post :create , params :
517+ {
518+ data : {
519+ type : 'posts' ,
520+ id : 'asdfg' ,
521+ attributes : {
522+ title : 'JR is Great' ,
523+ body : 'JSONAPIResources is the greatest thing since unsliced bread.'
524+ } ,
525+ relationships : {
526+ author : { data : { type : 'people' , id : '3' } }
527+ }
528+ }
529+ }
530+
531+ assert_response :bad_request
532+ assert_match /id is not allowed/ , response . body
533+ assert_equal nil , response . location
534+ end
535+
514536 def test_create_link_to_missing_object
515537 set_content_type_header!
516538 post :create , params :
@@ -563,6 +585,7 @@ def test_create_extra_param_allow_extra_params
563585 {
564586 data : {
565587 type : 'posts' ,
588+ id : 'my_id' ,
566589 attributes : {
567590 asdfg : 'aaaa' ,
568591 title : 'JR is Great' ,
@@ -581,10 +604,13 @@ def test_create_extra_param_allow_extra_params
581604 assert_equal 'JR is Great' , json_response [ 'data' ] [ 'attributes' ] [ 'title' ]
582605 assert_equal 'JSONAPIResources is the greatest thing since unsliced bread.' , json_response [ 'data' ] [ 'attributes' ] [ 'body' ]
583606
584- assert_equal 1 , json_response [ 'meta' ] [ "warnings" ] . count
607+ assert_equal 2 , json_response [ 'meta' ] [ "warnings" ] . count
585608 assert_equal "Param not allowed" , json_response [ 'meta' ] [ "warnings" ] [ 0 ] [ "title" ]
586- assert_equal "asdfg is not allowed." , json_response [ 'meta' ] [ "warnings" ] [ 0 ] [ "detail" ]
609+ assert_equal "id is not allowed." , json_response [ 'meta' ] [ "warnings" ] [ 0 ] [ "detail" ]
587610 assert_equal '105' , json_response [ 'meta' ] [ "warnings" ] [ 0 ] [ "code" ]
611+ assert_equal "Param not allowed" , json_response [ 'meta' ] [ "warnings" ] [ 1 ] [ "title" ]
612+ assert_equal "asdfg is not allowed." , json_response [ 'meta' ] [ "warnings" ] [ 1 ] [ "detail" ]
613+ assert_equal '105' , json_response [ 'meta' ] [ "warnings" ] [ 1 ] [ "code" ]
588614 assert_equal json_response [ 'data' ] [ 'links' ] [ 'self' ] , response . location
589615 ensure
590616 JSONAPI . configuration . raise_if_parameters_not_allowed = true
0 commit comments