Skip to content

Commit d185ebb

Browse files
authored
Merge pull request #962 from fsmanuel/fix/processor
Prevent error if using paginator :none
2 parents 5dfeb0f + 5bb56cb commit d185ebb

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/jsonapi/processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def find
6969
include_directives: include_directives)
7070
end
7171

72-
if (JSONAPI.configuration.top_level_meta_include_page_count && page_options[:record_count])
72+
if (JSONAPI.configuration.top_level_meta_include_page_count && paginator && page_options[:record_count])
7373
page_options[:page_count] = paginator ? paginator.calculate_page_count(page_options[:record_count]) : 1
7474
end
7575

test/controllers/controller_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -3033,6 +3033,18 @@ def test_books_page_count_in_meta
30333033
assert_equal 'Book 0', json_response['data'][0]['attributes']['title']
30343034
end
30353035

3036+
def test_books_no_page_count_in_meta_with_none_paginator
3037+
Api::V2::BookResource.paginator :none
3038+
JSONAPI.configuration.top_level_meta_include_page_count = true
3039+
assert_cacheable_get :index, params: {include: 'book-comments'}
3040+
JSONAPI.configuration.top_level_meta_include_page_count = false
3041+
3042+
assert_response :success
3043+
assert_nil json_response['meta']['page-count']
3044+
assert_equal 901, json_response['data'].size
3045+
assert_equal 'Book 0', json_response['data'][0]['attributes']['title']
3046+
end
3047+
30363048
def test_books_record_count_in_meta_custom_name
30373049
Api::V2::BookResource.paginator :offset
30383050
JSONAPI.configuration.top_level_meta_include_record_count = true

0 commit comments

Comments
 (0)