/
normalizer_spec.rb
58 lines (47 loc) · 2.06 KB
/
normalizer_spec.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
require "spec_helper"
describe PgSearch::Normalizer do
describe "#add_normalization" do
context "for PostgreSQL 9.0 and above" do
context "when config[:ignore] includes :accents" do
it "wraps the expression in unaccent()" do
config = stub("config", :ignore => [:accents], :postgresql_version => 90000)
normalizer = PgSearch::Normalizer.new(config)
normalizer.add_normalization("foo").should == "unaccent(foo)"
end
context "when a custom unaccent function is specified" do
it "wraps the expression in that function" do
PgSearch.stub(:unaccent_function).and_return("my_unaccent")
config = stub("config", :ignore => [:accents], :postgresql_version => 90000)
normalizer = PgSearch::Normalizer.new(config)
normalizer.add_normalization("foo").should == "my_unaccent(foo)"
end
end
end
context "when config[:ignore] does not include :accents" do
it "passes the expression through" do
config = stub("config", :ignore => [], :postgresql_version => 90000)
normalizer = PgSearch::Normalizer.new(config)
normalizer.add_normalization("foo").should == "foo"
end
end
end
context "for PostgreSQL versions before 9.0" do
context "when config[:ignore] includes :accents" do
it "raises a NotSupportedForPostgresqlVersion exception" do
config = stub("config", :ignore => [:accents], :postgresql_version => 89999)
normalizer = PgSearch::Normalizer.new(config)
expect {
normalizer.add_normalization("foo")
}.to raise_exception(PgSearch::NotSupportedForPostgresqlVersion)
end
end
context "when config[:ignore] does not include :accents" do
it "passes the expression through" do
config = stub("config", :ignore => [], :postgresql_version => 90000)
normalizer = PgSearch::Normalizer.new(config)
normalizer.add_normalization("foo").should == "foo"
end
end
end
end
end