Skip to content

Commit a78f492

Browse files
committed
[MODEL] Fixed, that param_name is used when paginating with WillPaginate
Closes elastic#307
1 parent 32ae874 commit a78f492

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

elasticsearch-model/lib/elasticsearch/model/response/pagination.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ def length
122122
# Article.search('foo').paginate(page: 1, per_page: 30)
123123
#
124124
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
127128

128129
search.definition.update size: per_page,
129130
from: (page - 1) * per_page

elasticsearch-model/test/unit/response_pagination_will_paginate_test.rb

+12
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ class WillPaginateResponse < Elasticsearch::Model::Response::Response
153153
assert_equal 0, @response.search.definition[:from]
154154
assert_equal 33, @response.search.definition[:size]
155155
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
156168
end
157169

158170
context "#page and #per_page shorthand methods" do

0 commit comments

Comments
 (0)