Skip to content

Commit 338cce7

Browse files
committed
Merge pull request #375 from cerebris/fix_record_count
Fix record count
2 parents 23adbed + c107a59 commit 338cce7

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/jsonapi/operation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def pagination_params
175175
def options
176176
opts = {}
177177
opts.merge!(pagination_params: pagination_params) if JSONAPI.configuration.top_level_links_include_pagination
178-
opts.merge!(record_count: pagination_params) if JSONAPI.configuration.top_level_meta_include_record_count
178+
opts.merge!(record_count: record_count) if JSONAPI.configuration.top_level_meta_include_record_count
179179
opts
180180
end
181181

test/integration/requests/request_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,19 @@ def test_pagination_related_resources_links
398398
assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=41', json_response['links']['last']
399399
end
400400

401+
def test_pagination_related_resources_links_meta
402+
Api::V2::BookResource.paginator :offset
403+
Api::V2::BookCommentResource.paginator :offset
404+
JSONAPI.configuration.top_level_meta_include_record_count = true
405+
get '/api/v2/books/1/book_comments?page[limit]=10'
406+
assert_equal 51, json_response['meta']['record_count']
407+
assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=0', json_response['links']['first']
408+
assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=10', json_response['links']['next']
409+
assert_equal 'http://www.example.com/api/v2/books/1/book_comments?page%5Blimit%5D=10&page%5Boffset%5D=41', json_response['links']['last']
410+
ensure
411+
JSONAPI.configuration.top_level_meta_include_record_count = false
412+
end
413+
401414
def test_pagination_related_resources_without_related
402415
Api::V2::BookResource.paginator :offset
403416
Api::V2::BookCommentResource.paginator :offset

0 commit comments

Comments
 (0)