Skip to content

Commit

Permalink
Fixed: query builder respects custom pagination params
Browse files Browse the repository at this point in the history
  • Loading branch information
kdonovan committed Aug 7, 2017
1 parent 2c7493c commit 0f89d79
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/json_api_client/query/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion test/unit/custom_paginator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 0f89d79

Please sign in to comment.