pg_search_plugin_test.rb
1.51 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
require 'test_helper'
class PgSearchPluginTest < ActiveSupport::TestCase
def setup
@environment = Environment.default
@environment.enable_plugin(PgSearchPlugin)
end
should 'locate profile' do
profile = fast_create(Profile, :name => 'John', :identifier => 'waterfall')
assert_includes search(Profile, 'John'), profile
assert_includes search(Profile, 'john'), profile
assert_includes search(Profile, 'waterfall'), profile
assert_includes search(Profile, 'water'), profile
end
should 'locate one or more profiles' do
profile1 = fast_create(Profile, :identifier => 'administrator')
profile2 = fast_create(Profile, :identifier => 'debugger')
assert_includes search(Profile, 'admin deb'), profile1
assert_includes search(Profile, 'admin deb'), profile2
end
# TODO This feature is available only on Postgresql 9.0
# http://www.postgresql.org/docs/9.0/static/unaccent.html
# should 'ignore accents' do
# profile = fast_create(Profile, :name => 'Produção', :identifier => 'colméia')
# assert_includes search(Profile, 'Produção'), profile
# assert_includes search(Profile, 'Producao'), profile
# assert_includes search(Profile, 'colméia'), profile
# assert_includes search(Profile, 'colmeia'), profile
# end
should 'check if filter option is defined' do
plugin = PgSearchPlugin.new
assert plugin.find_by_contents('asset', Profile, 'query', {:page => 1})
end
private
def search(scope, query)
scope.pg_search_plugin_search(query)
end
end