Skip to content

Commit 45b75a4

Browse files
committed
New request tests for key and route format combinations
1 parent f4427fd commit 45b75a4

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

test/fixtures/active_record.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,20 @@ class IsoCurrenciesController < JSONAPI::ResourceController
408408
end
409409

410410
module V6
411+
class CustomersController < JSONAPI::ResourceController
412+
end
413+
414+
class PurchaseOrdersController < JSONAPI::ResourceController
415+
end
416+
417+
class LineItemsController < JSONAPI::ResourceController
418+
end
419+
end
420+
421+
module V7
422+
class CustomersController < JSONAPI::ResourceController
423+
end
424+
411425
class PurchaseOrdersController < JSONAPI::ResourceController
412426
end
413427

@@ -800,6 +814,12 @@ class LineItemResource < JSONAPI::Resource
800814
has_one :purchase_order
801815
end
802816
end
817+
818+
module V7
819+
CustomerResource = V6::CustomerResource.dup
820+
PurchaseOrderResource = V6::PurchaseOrderResource.dup
821+
LineItemResource = V6::LineItemResource.dup
822+
end
803823
end
804824

805825
warn 'start testing Name Collisions'

test/integration/requests/request_test.rb

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,9 @@ def test_flow_link_has_many_self_link_put
451451
})
452452
end
453453

454-
def test_flow_self_formatted_route
454+
def test_flow_self_formatted_route_1
455455
JSONAPI.configuration.route_format = :dasherized_route
456+
JSONAPI.configuration.json_key_format = :dasherized_key
456457
get '/api/v6/purchase-orders'
457458
assert_equal 200, status
458459
po_1 = json_response['data'][0]
@@ -462,6 +463,18 @@ def test_flow_self_formatted_route
462463
assert_hash_equals po_1, json_response['data']
463464
end
464465

466+
def test_flow_self_formatted_route_2
467+
JSONAPI.configuration.route_format = :underscored_route
468+
JSONAPI.configuration.json_key_format = :dasherized_key
469+
get '/api/v7/purchase_orders'
470+
assert_equal 200, status
471+
po_1 = json_response['data'][0]
472+
473+
get po_1['links']['self']
474+
assert_equal 200, status
475+
assert_hash_equals po_1, json_response['data']
476+
end
477+
465478
def test_post_formatted_keys
466479
JSONAPI.configuration.route_format = :dasherized_route
467480
JSONAPI.configuration.json_key_format = :dasherized_key
@@ -476,6 +489,34 @@ def test_post_formatted_keys
476489
assert_equal 201, status
477490
end
478491

492+
def test_post_formatted_keys_different_route_key_1
493+
JSONAPI.configuration.route_format = :dasherized_route
494+
JSONAPI.configuration.json_key_format = :underscored_key
495+
post '/api/v6/purchase-orders',
496+
{
497+
'data' => {
498+
'delivery_name' => 'ASDFG Corp',
499+
'type' => 'purchase_orders'
500+
}
501+
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
502+
503+
assert_equal 201, status
504+
end
505+
506+
def test_post_formatted_keys_different_route_key_2
507+
JSONAPI.configuration.route_format = :underscored_route
508+
JSONAPI.configuration.json_key_format = :dasherized_key
509+
post '/api/v7/purchase_orders',
510+
{
511+
'data' => {
512+
'delivery-name' => 'ASDFG Corp',
513+
'type' => 'purchase-orders'
514+
}
515+
}.to_json, "CONTENT_TYPE" => JSONAPI::MEDIA_TYPE
516+
517+
assert_equal 201, status
518+
end
519+
479520
def test_post_formatted_keys_wrong_format
480521
JSONAPI.configuration.route_format = :dasherized_route
481522
JSONAPI.configuration.json_key_format = :dasherized_key

test/test_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ def as_json(options = nil)
155155
end
156156
JSONAPI.configuration.route_format = :underscored_route
157157

158+
namespace :v7 do
159+
jsonapi_resources :customers
160+
jsonapi_resources :purchase_orders
161+
jsonapi_resources :line_items
162+
end
158163
end
159164
end
160165

0 commit comments

Comments
 (0)