partial_reindex_test.rb
1.99 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require_relative "test_helper"
class PartialReindexTest < Minitest::Test
def test_class_method
store [{name: "Hi", color: "Blue"}]
# normal search
assert_search "hi", ["Hi"], fields: [:name], load: false
assert_search "blue", ["Hi"], fields: [:color], load: false
# update
product = Product.first
product.name = "Bye"
product.color = "Red"
Searchkick.callbacks(false) do
product.save!
end
Product.search_index.refresh
# index not updated
assert_search "hi", ["Hi"], fields: [:name], load: false
assert_search "blue", ["Hi"], fields: [:color], load: false
# partial reindex
Product.reindex(:search_name)
# name updated, but not color
assert_search "bye", ["Bye"], fields: [:name], load: false
assert_search "blue", ["Bye"], fields: [:color], load: false
end
def test_instance_method
store [{name: "Hi", color: "Blue"}]
# normal search
assert_search "hi", ["Hi"], fields: [:name], load: false
assert_search "blue", ["Hi"], fields: [:color], load: false
# update
product = Product.first
product.name = "Bye"
product.color = "Red"
Searchkick.callbacks(false) do
product.save!
end
Product.search_index.refresh
# index not updated
assert_search "hi", ["Hi"], fields: [:name], load: false
assert_search "blue", ["Hi"], fields: [:color], load: false
product.reindex(:search_name, refresh: true)
# name updated, but not color
assert_search "bye", ["Bye"], fields: [:name], load: false
assert_search "blue", ["Bye"], fields: [:color], load: false
end
def test_instance_method_async
product = Product.create!(name: "Hi")
product.reindex(:search_data, mode: :async)
end
def test_missing
store [{name: "Hi", color: "Blue"}]
product = Product.first
Product.search_index.remove(product)
error = assert_raises(Searchkick::ImportError) do
product.reindex(:search_name)
end
assert_match "document missing", error.message
end
end