forked from ankane/searchkick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inheritance_test.rb
80 lines (65 loc) · 2.21 KB
/
inheritance_test.rb
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
75
76
77
78
79
80
require_relative "test_helper"
class TestInheritance < Minitest::Test
def test_child_reindex
store_names ["Max"], Cat
assert Dog.reindex
Animal.searchkick_index.refresh
assert_equal 1, Animal.search("*").size
end
def test_child_index_name
assert_equal "animals-#{Date.today.year}", Dog.searchkick_index.name
end
def test_child_search
store_names ["Bear"], Dog
store_names ["Bear"], Cat
assert_equal 1, Dog.search("bear").size
end
def test_parent_search
store_names ["Bear"], Dog
store_names ["Bear"], Cat
assert_equal 2, Animal.search("bear").size
end
def test_force_one_type
store_names ["Green Bear"], Dog
store_names ["Blue Bear"], Cat
assert_equal ["Blue Bear"], Animal.search("bear", type: [Cat]).map(&:name)
end
def test_force_multiple_types
store_names ["Green Bear"], Dog
store_names ["Blue Bear"], Cat
store_names ["Red Bear"], Animal
assert_equal ["Green Bear", "Blue Bear"], Animal.search("bear", type: [Dog, Cat]).map(&:name)
end
def test_child_autocomplete
store_names ["Max"], Cat
store_names ["Mark"], Dog
assert_equal ["Max"], Cat.search("ma", fields: [:name], autocomplete: true).map(&:name)
end
def test_parent_autocomplete
store_names ["Max"], Cat
store_names ["Bear"], Dog
assert_equal ["Bear"], Animal.search("bea", fields: [:name], autocomplete: true).map(&:name).sort
end
# def test_child_suggest
# store_names ["Shark"], Cat
# store_names ["Sharp"], Dog
# assert_equal ["shark"], Cat.search("shar", fields: [:name], suggest: true).suggestions
# end
def test_parent_suggest
store_names ["Shark"], Cat
store_names ["Tiger"], Dog
assert_equal ["tiger"], Animal.search("tige", fields: [:name], suggest: true).suggestions.sort
end
def test_reindex
store_names ["Bear A"], Cat
store_names ["Bear B"], Dog
Animal.reindex
assert_equal 1, Dog.search("bear").size
end
# TODO move somewhere better
def test_multiple_indices
store_names ["Product A"]
store_names ["Product B"], Animal
assert_search "product", ["Product A", "Product B"], index_name: [Product.searchkick_index.name, Animal.searchkick_index.name], conversions: false
end
end