File tree 2 files changed +27
-1
lines changed
lib/json_api_client/query
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ def paginate(conditions = {})
47
47
end
48
48
49
49
def page ( number )
50
- @pagination_params [ klass . paginator . page_param ] = number
50
+ @pagination_params [ klass . paginator . page_param ] = number || 1
51
51
self
52
52
end
53
53
Original file line number Diff line number Diff line change @@ -38,6 +38,32 @@ def test_can_paginate
38
38
Article . paginate ( page : 3 , per_page : 6 ) . to_a
39
39
end
40
40
41
+ def test_pagination_default_number
42
+ JsonApiClient ::Paginating ::Paginator . page_param = :number
43
+ stub_request ( :get , "http://example.com/articles?#{ { page : { number : 1 } } . to_query } " )
44
+ . to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
45
+ data : [ {
46
+ type : "articles" ,
47
+ id : "1" ,
48
+ attributes : {
49
+ title : "JSON API paints my bikeshed!"
50
+ }
51
+ } ] ,
52
+ links : {
53
+ self : "http://example.com/articles?#{ { page : { number : 1 } } . to_query } " ,
54
+ next : "http://example.com/articles?#{ { page : { number : 2 } } . to_query } " ,
55
+ prev : nil ,
56
+ first : "http://example.com/articles?#{ { page : { number : 1 } } . to_query } " ,
57
+ last : "http://example.com/articles?#{ { page : { number : 6 } } . to_query } "
58
+ }
59
+ } . to_json )
60
+
61
+ articles = Article . page ( nil )
62
+ assert_equal 1 , articles . current_page
63
+ ensure
64
+ JsonApiClient ::Paginating ::Paginator . page_param = :page
65
+ end
66
+
41
67
def test_can_sort_asc
42
68
stub_request ( :get , "http://example.com/articles" )
43
69
. with ( query : { sort : "foo" } )
You can’t perform that action at this time.
0 commit comments