From 0f89d79f3b34be9a9652ab7358f93d05dc0871aa Mon Sep 17 00:00:00 2001 From: Kali Donovan Date: Mon, 7 Aug 2017 11:12:06 +0100 Subject: [PATCH] Fixed: query builder respects custom pagination params --- lib/json_api_client/query/builder.rb | 4 ++-- test/unit/custom_paginator_test.rb | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/json_api_client/query/builder.rb b/lib/json_api_client/query/builder.rb index 3494fc71..e21e2bf8 100644 --- a/lib/json_api_client/query/builder.rb +++ b/lib/json_api_client/query/builder.rb @@ -47,12 +47,12 @@ def paginate(conditions = {}) end def page(number) - @pagination_params[:number] = number + @pagination_params[ klass.paginator.page_param ] = number self end def per(size) - @pagination_params[:size] = size + @pagination_params[ klass.paginator.per_page_param ] = size self end diff --git a/test/unit/custom_paginator_test.rb b/test/unit/custom_paginator_test.rb index ca7361a2..4dbb1af2 100644 --- a/test/unit/custom_paginator_test.rb +++ b/test/unit/custom_paginator_test.rb @@ -3,6 +3,9 @@ class CustomPaginatorTest < MiniTest::Test class CustomPaginator < JsonApiClient::Paginating::Paginator + self.page_param = 'pagina' + self.per_page_param = 'limit' + def total_entries 42 end @@ -15,12 +18,14 @@ class Book < JsonApiClient::Resource def test_can_override stub_request(:get, "http://example.com/books") + .with(query: {page: {pagina: 3, limit: 6}}) .to_return(headers: {content_type: "application/vnd.api+json"}, body: { data: [] }.to_json) - books = Book.all + books = Book.paginate(page: 3, per_page: 6).to_a assert_equal 42, books.total_count assert_equal 42, books.total_entries end + end