@@ -49,18 +49,18 @@ def test_meta_data
49
49
50
50
def test_custom_meta_data
51
51
stub_request ( :get , "http://localhost:3000/api/1/custom_paginations.json" )
52
- . to_return ( headers : { content_type : "application/json" } , body : {
53
- custom_paginations : [
54
- { id : 1 , name : "Jeff Ching" , email_address : "ching.jeff@gmail.com" } ,
55
- { id : 2 , name : "Barry Bonds" , email_address : "barry@bonds.com" } ,
56
- { id : 3 , name : "Hank Aaron" , email_address : "hank@aaron.com" }
57
- ] ,
58
- meta : {
59
- per : 3 ,
60
- page : 2 ,
61
- total : 10
62
- }
63
- } . to_json )
52
+ . to_return ( headers : { content_type : "application/json" } , body : {
53
+ custom_paginations : [
54
+ { id : 1 , name : "Jeff Ching" , email_address : "ching.jeff@gmail.com" } ,
55
+ { id : 2 , name : "Barry Bonds" , email_address : "barry@bonds.com" } ,
56
+ { id : 3 , name : "Hank Aaron" , email_address : "hank@aaron.com" }
57
+ ] ,
58
+ meta : {
59
+ per : 3 ,
60
+ page : 2 ,
61
+ total : 10
62
+ }
63
+ } . to_json )
64
64
65
65
users = CustomPagination . all
66
66
assert_equal 3 , users . length
@@ -71,4 +71,58 @@ def test_custom_meta_data
71
71
assert_equal 4 , users . total_pages
72
72
end
73
73
74
+ # will_paginate gem specific parameters check
75
+ # https://github.com/mislav/will_paginate/blob/master/lib/will_paginate/collection.rb
76
+ def test_will_paginate_params
77
+ stub_request ( :get , "http://localhost:3000/api/1/custom_paginations.json" )
78
+ . to_return ( headers : { content_type : "application/json" } , body : {
79
+ custom_paginations : [
80
+ { id : 1 , name : "Jeff Ching" , email_address : "ching.jeff@gmail.com" } ,
81
+ { id : 2 , name : "Barry Bonds" , email_address : "barry@bonds.com" } ,
82
+ { id : 3 , name : "Hank Aaron" , email_address : "hank@aaron.com" }
83
+ ] ,
84
+ meta : {
85
+ per : 3 ,
86
+ page : 2 ,
87
+ total : 10
88
+ }
89
+ } . to_json )
90
+
91
+ users = CustomPagination . all
92
+ assert_equal 4 , users . total_pages
93
+ assert_equal 3 , users . offset
94
+ assert_equal 1 , users . previous_page
95
+ assert_equal 3 , users . next_page
96
+ assert_equal false , users . out_of_bounds?
97
+ assert_equal 2 , users . current_page
98
+ assert_equal 10 , users . total_entries
99
+ assert_equal 3 , users . per_page
100
+ end
101
+
102
+ # kaminari gem specific parameters check
103
+ # https://github.com/amatsuda/kaminari/blob/master/lib/kaminari/models/array_extension.rb
104
+ def test_kaminari_params
105
+ stub_request ( :get , "http://localhost:3000/api/1/custom_paginations.json" )
106
+ . to_return ( headers : { content_type : "application/json" } , body : {
107
+ custom_paginations : [
108
+ { id : 1 , name : "Jeff Ching" , email_address : "ching.jeff@gmail.com" } ,
109
+ { id : 2 , name : "Barry Bonds" , email_address : "barry@bonds.com" } ,
110
+ { id : 3 , name : "Hank Aaron" , email_address : "hank@aaron.com" }
111
+ ] ,
112
+ meta : {
113
+ per : 3 ,
114
+ page : 2 ,
115
+ total : 10
116
+ }
117
+ } . to_json )
118
+
119
+ users = CustomPagination . all
120
+ assert_equal 3 , users . limit_value
121
+ assert_equal 1 , users . previous_page
122
+ assert_equal 3 , users . next_page
123
+ assert_equal 2 , users . current_page
124
+ assert_equal 10 , users . total_entries
125
+ assert_equal 3 , users . per_page
126
+ end
127
+
74
128
end
0 commit comments