@@ -5,6 +5,7 @@ class RequestTest < ActionDispatch::IntegrationTest
55
66 def setup
77 JSONAPI . configuration . json_key_format = :underscored_key
8+ JSONAPI . configuration . route_format = :underscored_route
89 end
910
1011 def after_teardown
@@ -451,4 +452,116 @@ def test_flow_link_has_many_self_link_put
451452 } )
452453 end
453454
455+ def test_flow_self_formatted_route_1
456+ JSONAPI . configuration . route_format = :dasherized_route
457+ JSONAPI . configuration . json_key_format = :dasherized_key
458+ get '/api/v6/purchase-orders'
459+ assert_equal 200 , status
460+ po_1 = json_response [ 'data' ] [ 0 ]
461+ assert_equal 'purchase-orders' , json_response [ 'data' ] [ 0 ] [ 'type' ]
462+
463+ get po_1 [ 'links' ] [ 'self' ]
464+ assert_equal 200 , status
465+ assert_hash_equals po_1 , json_response [ 'data' ]
466+ end
467+
468+ def test_flow_self_formatted_route_2
469+ JSONAPI . configuration . route_format = :underscored_route
470+ JSONAPI . configuration . json_key_format = :dasherized_key
471+ get '/api/v7/purchase_orders'
472+ assert_equal 200 , status
473+ assert_equal 'purchase-orders' , json_response [ 'data' ] [ 0 ] [ 'type' ]
474+
475+ po_1 = json_response [ 'data' ] [ 0 ]
476+
477+ get po_1 [ 'links' ] [ 'self' ]
478+ assert_equal 200 , status
479+ assert_hash_equals po_1 , json_response [ 'data' ]
480+ end
481+
482+ def test_flow_self_formatted_route_3
483+ JSONAPI . configuration . route_format = :underscored_route
484+ JSONAPI . configuration . json_key_format = :underscored_key
485+ get '/api/v7/purchase_orders'
486+ assert_equal 200 , status
487+ assert_equal 'purchase_orders' , json_response [ 'data' ] [ 0 ] [ 'type' ]
488+
489+ po_1 = json_response [ 'data' ] [ 0 ]
490+
491+ get po_1 [ 'links' ] [ 'self' ]
492+ assert_equal 200 , status
493+ assert_hash_equals po_1 , json_response [ 'data' ]
494+ end
495+
496+ def test_post_formatted_keys
497+ JSONAPI . configuration . route_format = :dasherized_route
498+ JSONAPI . configuration . json_key_format = :dasherized_key
499+ post '/api/v6/purchase-orders' ,
500+ {
501+ 'data' => {
502+ 'delivery-name' => 'ASDFG Corp' ,
503+ 'type' => 'purchase-orders'
504+ }
505+ } . to_json , "CONTENT_TYPE" => JSONAPI ::MEDIA_TYPE
506+
507+ assert_equal 201 , status
508+ end
509+
510+ def test_post_formatted_keys_different_route_key_1
511+ JSONAPI . configuration . route_format = :dasherized_route
512+ JSONAPI . configuration . json_key_format = :underscored_key
513+ post '/api/v6/purchase-orders' ,
514+ {
515+ 'data' => {
516+ 'delivery_name' => 'ASDFG Corp' ,
517+ 'type' => 'purchase_orders'
518+ }
519+ } . to_json , "CONTENT_TYPE" => JSONAPI ::MEDIA_TYPE
520+
521+ assert_equal 201 , status
522+ end
523+
524+ def test_post_formatted_keys_different_route_key_2
525+ JSONAPI . configuration . route_format = :underscored_route
526+ JSONAPI . configuration . json_key_format = :dasherized_key
527+ post '/api/v7/purchase_orders' ,
528+ {
529+ 'data' => {
530+ 'delivery-name' => 'ASDFG Corp' ,
531+ 'type' => 'purchase-orders'
532+ }
533+ } . to_json , "CONTENT_TYPE" => JSONAPI ::MEDIA_TYPE
534+
535+ assert_equal 201 , status
536+ end
537+
538+ def test_post_formatted_keys_wrong_format
539+ JSONAPI . configuration . route_format = :dasherized_route
540+ JSONAPI . configuration . json_key_format = :dasherized_key
541+ post '/api/v6/purchase-orders' ,
542+ {
543+ 'data' => {
544+ 'delivery_name' => 'ASDFG Corp' ,
545+ 'type' => 'purchase-orders'
546+ }
547+ } . to_json , "CONTENT_TYPE" => JSONAPI ::MEDIA_TYPE
548+
549+ assert_equal 400 , status
550+ end
551+
552+ def test_patch_formatted_dasherized
553+ JSONAPI . configuration . route_format = :dasherized_route
554+ JSONAPI . configuration . json_key_format = :dasherized_key
555+ patch '/api/v6/purchase-orders/1' ,
556+ {
557+ 'data' => {
558+ 'id' => '1' ,
559+ 'delivery-name' => 'ASDFG Corp' ,
560+ 'type' => 'purchase-orders'
561+ }
562+ } . to_json , "CONTENT_TYPE" => JSONAPI ::MEDIA_TYPE
563+
564+ assert_equal 200 , status
565+ end
566+
454567end
0 commit comments