similar_test.rb
1.63 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
require_relative "test_helper"
class SimilarTest < Minitest::Test
def test_similar
store_names ["Annie's Naturals Organic Shiitake & Sesame Dressing"]
assert_search "Annie's Naturals Shiitake & Sesame Vinaigrette", ["Annie's Naturals Organic Shiitake & Sesame Dressing"], similar: true, fields: [:name]
end
def test_relation
store_names ["1% Organic Milk", "2% Organic Milk", "Popcorn"]
assert_equal ["2% Organic Milk"], Product.where(name: "1% Organic Milk").first.similar.fields(:name).order(:name).limit(1).map(&:name)
end
def test_fields
store_names ["1% Organic Milk", "2% Organic Milk", "Popcorn"]
assert_equal ["2% Organic Milk"], Product.where(name: "1% Organic Milk").first.similar(fields: ["name"]).map(&:name)
end
def test_order
store_names ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"]
assert_order "Lucerne Fat Free Chocolate Milk", ["Lucerne Milk Chocolate Fat Free", "Clover Fat Free Milk"], similar: true, fields: [:name]
end
def test_limit
store_names ["1% Organic Milk", "2% Organic Milk", "Fat Free Organic Milk", "Popcorn"]
assert_equal ["2% Organic Milk"], Product.where(name: "1% Organic Milk").first.similar(fields: ["name"], order: ["name"], limit: 1).map(&:name)
end
def test_per_page
store_names ["1% Organic Milk", "2% Organic Milk", "Fat Free Organic Milk", "Popcorn"]
assert_equal ["2% Organic Milk"], Product.where(name: "1% Organic Milk").first.similar(fields: ["name"], order: ["name"], per_page: 1).map(&:name)
end
def test_routing
store_names ["Test"], Store
assert_equal [], Store.first.similar(fields: ["name"]).map(&:name)
end
end