Commit 28007e3d75aa557e450741ea6e9ed9b5b3f851a5

Authored by Andrew Kane
1 parent 0638332e

Test routing

lib/searchkick/relation.rb
@@ -254,12 +254,12 @@ module Searchkick @@ -254,12 +254,12 @@ module Searchkick
254 self 254 self
255 end 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 end 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 if block 263 if block
264 execute.scroll(&block) 264 execute.scroll(&block)
265 else 265 else
@@ -267,6 +267,15 @@ module Searchkick @@ -267,6 +267,15 @@ module Searchkick
267 end 267 end
268 end 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 # same as Active Record 279 # same as Active Record
271 def inspect 280 def inspect
272 entries = results.first(11).map!(&:inspect) 281 entries = results.first(11).map!(&:inspect)
@@ -274,6 +283,11 @@ module Searchkick @@ -274,6 +283,11 @@ module Searchkick
274 "#<#{self.class.name} [#{entries.join(', ')}]>" 283 "#<#{self.class.name} [#{entries.join(', ')}]>"
275 end 284 end
276 285
  286 + # private
  287 + def query
  288 + Query.new(klass, term, options)
  289 + end
  290 +
277 private 291 private
278 292
279 def hash_args(old, new) 293 def hash_args(old, new)
@@ -299,7 +313,7 @@ module Searchkick @@ -299,7 +313,7 @@ module Searchkick
299 313
300 # TODO reset when ! methods called 314 # TODO reset when ! methods called
301 def execute 315 def execute
302 - @execute ||= Query.new(klass, term, options).execute 316 + @execute ||= query.execute
303 end 317 end
304 318
305 def spawn 319 def spawn
test/routing_test.rb
@@ -4,6 +4,9 @@ class RoutingTest &lt; Minitest::Test @@ -4,6 +4,9 @@ class RoutingTest &lt; Minitest::Test
4 def test_routing_query 4 def test_routing_query
5 query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false) 5 query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false)
6 assert_equal query.params[:routing], "Dollar Tree" 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 end 10 end
8 11
9 def test_routing_mappings 12 def test_routing_mappings