Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix show_related_resources and top_level_meta_include_page_count #1392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jsonapi/processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def show_related_resources
options)
end

if (JSONAPI.configuration.top_level_meta_include_page_count && opts[:record_count])
if (paginator && JSONAPI.configuration.top_level_meta_include_page_count && opts[:record_count])
opts[:page_count] = paginator.calculate_page_count(opts[:record_count])
end

Expand Down
11 changes: 11 additions & 0 deletions test/integration/requests/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,17 @@ def test_pagination_related_resources_links_meta
JSONAPI.configuration.top_level_meta_include_record_count = false
end

def test_pagination_none_related_resources_and_top_level_meta_include_page_count
Api::V2::BookResource.paginator :offset
Api::V2::BookCommentResource.paginator :none
JSONAPI.configuration.top_level_meta_include_page_count = true
assert_cacheable_jsonapi_get '/api/v2/books/1/book_comments'
assert json_response['data']
assert_nil json_response.dig('meta', 'record_count')
ensure
JSONAPI.configuration.top_level_meta_include_page_count = false
end

def test_filter_related_resources_relationship_filter
Api::V2::BookCommentResource.paginator :offset
JSONAPI.configuration.top_level_meta_include_record_count = true
Expand Down