File tree 2 files changed +26
-2
lines changed
lib/elasticsearch/model/response
2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -66,10 +66,11 @@ def offset_value
66
66
# Set the "limit" (`size`) value
67
67
#
68
68
def limit ( value )
69
+ return self if value . to_i <= 0
69
70
@results = nil
70
71
@records = nil
71
72
@response = nil
72
- @per_page = value
73
+ @per_page = value . to_i
73
74
74
75
search . definition . update :size => @per_page
75
76
search . definition . update :from => @per_page * ( @page - 1 ) if @page
@@ -79,11 +80,12 @@ def limit(value)
79
80
# Set the "offset" (`from`) value
80
81
#
81
82
def offset ( value )
83
+ return self if value . to_i < 0
82
84
@results = nil
83
85
@records = nil
84
86
@response = nil
85
87
@page = nil
86
- search . definition . update :from => value
88
+ search . definition . update :from => value . to_i
87
89
self
88
90
end
89
91
Original file line number Diff line number Diff line change @@ -104,6 +104,17 @@ def self.document_type; 'bar'; end
104
104
assert_nil @response . instance_variable_get ( :@records )
105
105
assert_nil @response . instance_variable_get ( :@results )
106
106
end
107
+
108
+ should 'coerce string parameters' do
109
+ @response . limit ( "35" )
110
+ assert_equal 35 , @response . search . definition [ :size ]
111
+ end
112
+
113
+ should 'ignore invalid string parameters' do
114
+ @response . limit ( 35 )
115
+ @response . limit ( "asdf" )
116
+ assert_equal 35 , @response . search . definition [ :size ]
117
+ end
107
118
end
108
119
109
120
context "with the page() and limit() methods" do
@@ -151,6 +162,17 @@ def self.document_type; 'bar'; end
151
162
assert_nil @response . instance_variable_get ( :@records )
152
163
assert_nil @response . instance_variable_get ( :@results )
153
164
end
165
+
166
+ should 'coerce string parameters' do
167
+ @response . offset ( "35" )
168
+ assert_equal 35 , @response . search . definition [ :from ]
169
+ end
170
+
171
+ should 'coerce invalid string parameters' do
172
+ @response . offset ( 35 )
173
+ @response . offset ( "asdf" )
174
+ assert_equal 0 , @response . search . definition [ :from ]
175
+ end
154
176
end
155
177
156
178
context "total" do
You can’t perform that action at this time.
0 commit comments