File tree Expand file tree Collapse file tree 4 files changed +29
-3
lines changed
lib/json_api_client/query Expand file tree Collapse file tree 4 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -47,12 +47,12 @@ def paginate(conditions = {})
4747 end
4848
4949 def page ( number )
50- @pagination_params [ :number ] = number
50+ @pagination_params [ klass . paginator . page_param ] = number
5151 self
5252 end
5353
5454 def per ( size )
55- @pagination_params [ :size ] = size
55+ @pagination_params [ klass . paginator . per_page_param ] = size
5656 self
5757 end
5858
Original file line number Diff line number Diff line change 1+ require 'test_helper'
2+
3+ class CustomPaginatorTest < MiniTest ::Test
4+
5+ class CustomPaginator < JsonApiClient ::Paginating ::Paginator
6+ self . page_param = 'pagina'
7+ self . per_page_param = 'limit'
8+ end
9+
10+ class Book < JsonApiClient ::Resource
11+ self . site = "http://example.com/"
12+ self . paginator = CustomPaginator
13+ end
14+
15+ def test_can_override_query_param_names
16+ stub_request ( :get , "http://example.com/books" )
17+ . with ( query : { page : { pagina : 3 , limit : 6 } } )
18+ . to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
19+ data : [ ]
20+ } . to_json )
21+
22+ Book . paginate ( page : 3 , per_page : 6 ) . to_a
23+ end
24+
25+ end
Original file line number Diff line number Diff line change @@ -23,4 +23,5 @@ def test_can_override
2323 assert_equal 42 , books . total_count
2424 assert_equal 42 , books . total_entries
2525 end
26+
2627end
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ def test_can_specify_multiple_includes
3131
3232 def test_can_paginate
3333 stub_request ( :get , "http://example.com/articles" )
34- . with ( query : { page : { number : 3 , size : 6 } } )
34+ . with ( query : { page : { page : 3 , per_page : 6 } } )
3535 . to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
3636 data : [ ]
3737 } . to_json )
You can’t perform that action at this time.
0 commit comments