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 = {})
47
47
end
48
48
49
49
def page ( number )
50
- @pagination_params [ :number ] = number
50
+ @pagination_params [ klass . paginator . page_param ] = number
51
51
self
52
52
end
53
53
54
54
def per ( size )
55
- @pagination_params [ :size ] = size
55
+ @pagination_params [ klass . paginator . per_page_param ] = size
56
56
self
57
57
end
58
58
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
23
23
assert_equal 42 , books . total_count
24
24
assert_equal 42 , books . total_entries
25
25
end
26
+
26
27
end
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ def test_can_specify_multiple_includes
31
31
32
32
def test_can_paginate
33
33
stub_request ( :get , "http://example.com/articles" )
34
- . with ( query : { page : { number : 3 , size : 6 } } )
34
+ . with ( query : { page : { page : 3 , per_page : 6 } } )
35
35
. to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
36
36
data : [ ]
37
37
} . to_json )
You can’t perform that action at this time.
0 commit comments