-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfuzzy_search_test.rb
More file actions
53 lines (42 loc) · 1.31 KB
/
Copy pathfuzzy_search_test.rb
File metadata and controls
53 lines (42 loc) · 1.31 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
require 'test_helper'
class Name::FuzzySearchTest < ActiveSupport::TestCase
test 'finds similar names by similarity' do
matches = Name.fuzzy_search('Escherichia coli').to_a
assert_equal names(:escherichia_coli), matches.first
assert_equal 1.0, matches.first.score
end
test 'uses all valid names by default' do
matches = Name.fuzzy_search('Escherichia colie', threshold: 0.5).to_a
assert_includes matches, names(:escherichia_coli)
assert_not_includes matches, names(:escherichia_colie)
end
test 'supports levenshtein searches' do
matches = Name.fuzzy_search(
'Bacillus subtiliss', method: :levenshtein, threshold: 1
).to_a
assert_equal [names(:bacillus_subtilis)], matches
assert_equal 1, matches.first.score
end
test 'supports genus selections' do
matches = Name.fuzzy_search(
'Bacilus',
method: :levenshtein,
threshold: 2,
selection: :valid_genera
).to_a
assert_equal [names(:bacillus)], matches
end
test 'limits matches' do
matches = Name.fuzzy_search(
'Escherichia',
threshold: 0,
limit: 1
).to_a
assert_equal 1, matches.size
end
test 'raises for unsupported methods' do
assert_raises(ArgumentError) do
Name.fuzzy_search('Escherichia coli', method: :unknown).to_a
end
end
end