Skip to content

Commit 35ed838

Browse files
committed
Fix show_related_resources to work with global config
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
1 parent bf4b4cd commit 35ed838

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: lib/jsonapi/processor.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def show_related_resources
204204
options)
205205
end
206206

207-
if (JSONAPI.configuration.top_level_meta_include_page_count && opts[:record_count])
207+
if (paginator && JSONAPI.configuration.top_level_meta_include_page_count && opts[:record_count])
208208
opts[:page_count] = paginator.calculate_page_count(opts[:record_count])
209209
end
210210

Diff for: test/integration/requests/request_test.rb

+11
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,17 @@ def test_pagination_related_resources_links_meta
813813
JSONAPI.configuration.top_level_meta_include_record_count = false
814814
end
815815

816+
def test_pagination_none_related_resources_meta
817+
Api::V2::BookResource.paginator :offset
818+
Api::V2::BookCommentResource.paginator :none
819+
JSONAPI.configuration.top_level_meta_include_page_count = true
820+
assert_cacheable_jsonapi_get '/api/v2/books/1/book_comments'
821+
assert json_response['data']
822+
assert_nil json_response.dig('meta', 'record_count')
823+
ensure
824+
JSONAPI.configuration.top_level_meta_include_page_count = false
825+
end
826+
816827
def test_filter_related_resources_relationship_filter
817828
Api::V2::BookCommentResource.paginator :offset
818829
JSONAPI.configuration.top_level_meta_include_record_count = true

0 commit comments

Comments
 (0)