File tree 2 files changed +15
-2
lines changed
lib/elasticsearch/model/response
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -122,8 +122,9 @@ def length
122
122
# Article.search('foo').paginate(page: 1, per_page: 30)
123
123
#
124
124
def paginate ( options )
125
- page = [ options [ :page ] . to_i , 1 ] . max
126
- per_page = ( options [ :per_page ] || klass . per_page ) . to_i
125
+ param_name = options [ :param_name ] || :page
126
+ page = [ options [ param_name ] . to_i , 1 ] . max
127
+ per_page = ( options [ :per_page ] || klass . per_page ) . to_i
127
128
128
129
search . definition . update size : per_page ,
129
130
from : ( page - 1 ) * per_page
Original file line number Diff line number Diff line change @@ -153,6 +153,18 @@ class WillPaginateResponse < Elasticsearch::Model::Response::Response
153
153
assert_equal 0 , @response . search . definition [ :from ]
154
154
assert_equal 33 , @response . search . definition [ :size ]
155
155
end
156
+
157
+ should "use the param_name" do
158
+ @response . klass . client
159
+ . expects ( :search )
160
+ . with do |definition |
161
+ assert_equal 10 , definition [ :from ]
162
+ true
163
+ end
164
+ . returns ( RESPONSE )
165
+
166
+ @response . paginate ( my_page : 2 , per_page : 10 , param_name : :my_page ) . to_a
167
+ end
156
168
end
157
169
158
170
context "#page and #per_page shorthand methods" do
You can’t perform that action at this time.
0 commit comments