Skip to content

Commit 14bb1fc

Browse files
committed
test(controller): test custom page_count meta name
1 parent 489cdbd commit 14bb1fc

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

test/controllers/controller_test.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,14 +2689,11 @@ def test_books_record_count_in_meta
26892689

26902690
def test_books_page_count_in_meta
26912691
Api::V2::BookResource.paginator :paged
2692-
JSONAPI.configuration.top_level_meta_include_record_count = true
26932692
JSONAPI.configuration.top_level_meta_include_page_count = true
26942693
get :index, params: {include: 'book-comments'}
2695-
JSONAPI.configuration.top_level_meta_include_record_count = false
26962694
JSONAPI.configuration.top_level_meta_include_page_count = false
26972695

26982696
assert_response :success
2699-
assert_equal 901, json_response['meta']['record-count']
27002697
assert_equal 91, json_response['meta']['page-count']
27012698
assert_equal 10, json_response['data'].size
27022699
assert_equal 'Book 0', json_response['data'][0]['attributes']['title']
@@ -2717,6 +2714,21 @@ def test_books_record_count_in_meta_custom_name
27172714
assert_equal 'Book 0', json_response['data'][0]['attributes']['title']
27182715
end
27192716

2717+
def test_books_page_count_in_meta_custom_name
2718+
Api::V2::BookResource.paginator :paged
2719+
JSONAPI.configuration.top_level_meta_include_page_count = true
2720+
JSONAPI.configuration.top_level_meta_page_count_key = 'total_pages'
2721+
2722+
get :index, params: {include: 'book-comments'}
2723+
JSONAPI.configuration.top_level_meta_include_page_count = false
2724+
JSONAPI.configuration.top_level_meta_page_count_key = :page_count
2725+
2726+
assert_response :success
2727+
assert_equal 91, json_response['meta']['total-pages']
2728+
assert_equal 10, json_response['data'].size
2729+
assert_equal 'Book 0', json_response['data'][0]['attributes']['title']
2730+
end
2731+
27202732
def test_books_offset_pagination_no_params_includes_query_count_one_level
27212733
Api::V2::BookResource.paginator :offset
27222734

0 commit comments

Comments
 (0)