Skip to content

Commit b444939

Browse files
committed
Prevent error if using paginator :none
The PR fixes a bug if you use `paginator :none` and have `config.top_level_meta_include_page_count` set to `true`.
1 parent 5465aba commit b444939

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/jsonapi/processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def find
9292
include_directives: include_directives)
9393
end
9494

95-
if (JSONAPI.configuration.top_level_meta_include_page_count && page_options[:record_count])
95+
if (JSONAPI.configuration.top_level_meta_include_page_count && paginator && page_options[:record_count])
9696
page_options[:page_count] = paginator.calculate_page_count(page_options[:record_count])
9797
end
9898

test/controllers/controller_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,6 +2881,18 @@ def test_books_page_count_in_meta
28812881
assert_equal 'Book 0', json_response['data'][0]['attributes']['title']
28822882
end
28832883

2884+
def test_books_no_page_count_in_meta_with_none_paginator
2885+
Api::V2::BookResource.paginator :none
2886+
JSONAPI.configuration.top_level_meta_include_page_count = true
2887+
assert_cacheable_get :index, params: {include: 'book-comments'}
2888+
JSONAPI.configuration.top_level_meta_include_page_count = false
2889+
2890+
assert_response :success
2891+
assert_nil json_response['meta']['page-count']
2892+
assert_equal 901, json_response['data'].size
2893+
assert_equal 'Book 0', json_response['data'][0]['attributes']['title']
2894+
end
2895+
28842896
def test_books_record_count_in_meta_custom_name
28852897
Api::V2::BookResource.paginator :offset
28862898
JSONAPI.configuration.top_level_meta_include_record_count = true

0 commit comments

Comments
 (0)