routing_test.rb
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require_relative "test_helper"
class RoutingTest < Minitest::Test
def test_routing_query
query = Store.search("Dollar Tree", routing: "Dollar Tree", execute: false)
assert_equal query.params[:routing], "Dollar Tree"
query = Store.search("Dollar Tree").routing("Dollar Tree")
assert_equal query.params[:routing], "Dollar Tree"
end
def test_routing_mappings
mappings = Store.searchkick_index.index_options[:mappings]
if Searchkick.server_below?("7.0.0")
mappings = mappings[:store]
end
assert_equal mappings[:_routing], required: true
end
def test_routing_correct_node
store_names ["Dollar Tree"], Store
assert_search "*", ["Dollar Tree"], {routing: "Dollar Tree"}, Store
end
def test_routing_incorrect_node
store_names ["Dollar Tree"], Store
assert_search "*", ["Dollar Tree"], {routing: "Boom"}, Store
end
def test_routing_async
skip unless defined?(ActiveJob)
with_options(Song, routing: true, callbacks: :async) do
store_names ["Dollar Tree"], Song
Song.destroy_all
end
end
def test_routing_queue
skip unless defined?(ActiveJob) && defined?(Redis)
with_options(Song, routing: true, callbacks: :queue) do
store_names ["Dollar Tree"], Song
Song.destroy_all
Searchkick::ProcessQueueJob.perform_later(class_name: "Song")
end
end
end