results_test.rb
1.64 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
require_relative "test_helper"
class ResultsTest < Minitest::Test
def test_array_methods
store_names ["Product A", "Product B"]
products = Product.search("product")
assert_equal 2, products.count
assert_equal 2, products.size
assert_equal 2, products.length
assert products.any?
refute products.empty?
refute products.none?
refute products.one?
assert products.many?
assert_kind_of Product, products[0]
assert_kind_of Array, products.slice(0, 1)
assert_kind_of Array, products.to_ary
end
def test_with_hit
store_names ["Product A", "Product B"]
results = Product.search("product")
assert_kind_of Enumerator, results.with_hit
assert_equal 2, results.with_hit.to_a.size
count = 0
results.with_hit do |product, hit|
assert_kind_of Product, product
assert_kind_of Hash, hit
count += 1
end
assert_equal 2, count
end
def test_with_score
store_names ["Product A", "Product B"]
results = Product.search("product")
assert_kind_of Enumerator, results.with_score
assert_equal 2, results.with_score.to_a.size
count = 0
results.with_score do |product, score|
assert_kind_of Product, product
assert_kind_of Numeric, score
count += 1
end
assert_equal 2, count
end
def test_model_name_with_model
store_names ["Product A", "Product B"]
results = Product.search("product")
assert_equal "Product", results.model_name.human
end
def test_model_name_without_model
store_names ["Product A", "Product B"]
results = Searchkick.search("product")
assert_equal "Result", results.model_name.human
end
end