Skip to content

Commit

Permalink
Fix show_related_resources to work with global config
Browse files Browse the repository at this point in the history
problem:

When the paginator is :none and top_level_meta_include_page_count is true
The show_related_resources was crashing as the paginator is nil

solution:

Just fixing the immediate problem but the code still leaves page_count
as nil in the meta
  • Loading branch information
bliof committed Jun 21, 2022
1 parent bf4b4cd commit 35ed838
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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_meta
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

0 comments on commit 35ed838

Please sign in to comment.