Commit 28007e3d75aa557e450741ea6e9ed9b5b3f851a5
1 parent
0638332e
Exists in
relation
and in
1 other branch
Test routing
Showing
2 changed files
with
22 additions
and
5 deletions
Show diff stats
lib/searchkick/relation.rb
... | ... | @@ -254,12 +254,12 @@ module Searchkick |
254 | 254 | self |
255 | 255 | end |
256 | 256 | |
257 | - def scroll(value, &block) | |
258 | - spawn.scroll!(value, &block) | |
257 | + def scroll(value = nil, &block) | |
258 | + spawn.scroll!(value = nil, &block) | |
259 | 259 | end |
260 | 260 | |
261 | - def scroll!(value, &block) | |
262 | - options[:scroll] = value | |
261 | + def scroll!(value = nil, &block) | |
262 | + options[:scroll] = value if value | |
263 | 263 | if block |
264 | 264 | execute.scroll(&block) |
265 | 265 | else |
... | ... | @@ -267,6 +267,15 @@ module Searchkick |
267 | 267 | end |
268 | 268 | end |
269 | 269 | |
270 | + def routing(value) | |
271 | + spawn.routing!(value) | |
272 | + end | |
273 | + | |
274 | + def routing!(value) | |
275 | + options[:routing] = value | |
276 | + self | |
277 | + end | |
278 | + | |
270 | 279 | # same as Active Record |
271 | 280 | def inspect |
272 | 281 | entries = results.first(11).map!(&:inspect) |
... | ... | @@ -274,6 +283,11 @@ module Searchkick |
274 | 283 | "#<#{self.class.name} [#{entries.join(', ')}]>" |
275 | 284 | end |
276 | 285 | |
286 | + # private | |
287 | + def query | |
288 | + Query.new(klass, term, options) | |
289 | + end | |
290 | + | |
277 | 291 | private |
278 | 292 | |
279 | 293 | def hash_args(old, new) |
... | ... | @@ -299,7 +313,7 @@ module Searchkick |
299 | 313 | |
300 | 314 | # TODO reset when ! methods called |
301 | 315 | def execute |
302 | - @execute ||= Query.new(klass, term, options).execute | |
316 | + @execute ||= query.execute | |
303 | 317 | end |
304 | 318 | |
305 | 319 | def spawn | ... | ... |
test/routing_test.rb
... | ... | @@ -4,6 +4,9 @@ class RoutingTest < Minitest::Test |
4 | 4 | def test_routing_query |
5 | 5 | query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false) |
6 | 6 | assert_equal query.params[:routing], "Dollar Tree" |
7 | + | |
8 | + query = Store.search("Dollar Tree", relation: true).routing("Dollar Tree").query | |
9 | + assert_equal query.params[:routing], "Dollar Tree" | |
7 | 10 | end |
8 | 11 | |
9 | 12 | def test_routing_mappings | ... | ... |