Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7bc4c7b

Browse files
committed
Coerce pagination string params
1 parent d6e534c commit 7bc4c7b

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def limit(value)
6969
@results = nil
7070
@records = nil
7171
@response = nil
72-
@per_page = value
72+
@per_page = value.to_i
7373

7474
search.definition.update :size => @per_page
7575
search.definition.update :from => @per_page * (@page - 1) if @page
@@ -83,7 +83,7 @@ def offset(value)
8383
@records = nil
8484
@response = nil
8585
@page = nil
86-
search.definition.update :from => value
86+
search.definition.update :from => value.to_i
8787
self
8888
end
8989

‎elasticsearch-model/test/unit/response_pagination_kaminari_test.rb‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ def self.document_type; 'bar'; end
104104
assert_nil @response.instance_variable_get(:@records)
105105
assert_nil @response.instance_variable_get(:@results)
106106
end
107+
108+
should 'coerce string parameters' do
109+
@response.limit("35")
110+
assert_equal 35, @response.search.definition[:size]
111+
end
107112
end
108113

109114
context "with the page() and limit() methods" do
@@ -151,6 +156,11 @@ def self.document_type; 'bar'; end
151156
assert_nil @response.instance_variable_get(:@records)
152157
assert_nil @response.instance_variable_get(:@results)
153158
end
159+
160+
should 'coerce string parameters' do
161+
@response.offset("35")
162+
assert_equal 35, @response.search.definition[:from]
163+
end
154164
end
155165

156166
context "total" do

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /