searchlogic 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +6 -0
- data/Manifest +37 -18
- data/README.rdoc +13 -17
- data/TODO.rdoc +1 -3
- data/lib/searchlogic.rb +6 -6
- data/lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb +9 -9
- data/lib/searchlogic/conditions/base.rb +20 -6
- data/lib/searchlogic/search/base.rb +0 -5
- data/lib/searchlogic/search/searching.rb +3 -1
- data/lib/searchlogic/version.rb +1 -1
- data/searchlogic.gemspec +4 -4
- data/test/active_record_tests/associations_test.rb +95 -0
- data/test/active_record_tests/base_test.rb +108 -0
- data/test/condition_tests/base_test.rb +54 -0
- data/test/condition_tests/begins_with_test.rb +11 -0
- data/test/condition_tests/blank_test.rb +31 -0
- data/test/condition_tests/child_of_test.rb +17 -0
- data/test/condition_tests/descendant_of_test.rb +16 -0
- data/test/condition_tests/ends_with_test.rb +11 -0
- data/test/condition_tests/equals_test.rb +19 -0
- data/test/condition_tests/greater_than_or_equal_to_test.rb +11 -0
- data/test/condition_tests/greater_than_test.rb +11 -0
- data/test/condition_tests/inclusive_descendant_of_test.rb +16 -0
- data/test/condition_tests/keyswords_test.rb +19 -0
- data/test/condition_tests/less_than_or_equal_to_test.rb +11 -0
- data/test/condition_tests/less_than_test.rb +11 -0
- data/test/condition_tests/like_test.rb +11 -0
- data/test/condition_tests/nil_test.rb +31 -0
- data/test/condition_tests/not_begin_with_test.rb +8 -0
- data/test/condition_tests/not_blank_test.rb +8 -0
- data/test/condition_tests/not_end_with_test.rb +8 -0
- data/test/condition_tests/not_equal_test.rb +19 -0
- data/test/condition_tests/not_have_keywords_test.rb +8 -0
- data/test/condition_tests/not_like_test.rb +8 -0
- data/test/condition_tests/not_nil_test.rb +13 -0
- data/test/condition_tests/sibling_of_test.rb +15 -0
- data/test/conditions_tests/base_test.rb +221 -0
- data/test/conditions_tests/protection_test.rb +18 -0
- data/test/{test_config.rb → config_test.rb} +1 -1
- data/test/fixtures/accounts.yml +0 -3
- data/test/fixtures/animals.yml +7 -0
- data/test/fixtures/orders.yml +2 -4
- data/test/fixtures/user_groups.yml +3 -9
- data/test/fixtures/users.yml +6 -12
- data/{test_libs → test/libs}/acts_as_tree.rb +0 -0
- data/{test_libs → test/libs}/rexml_fix.rb +0 -0
- data/test/modifier_tests/day_of_month_test.rb +16 -0
- data/test/search_tests/base_test.rb +237 -0
- data/test/search_tests/conditions_test.rb +21 -0
- data/test/search_tests/ordering_test.rb +167 -0
- data/test/search_tests/pagination_test.rb +74 -0
- data/test/search_tests/protection_test.rb +26 -0
- data/test/test_helper.rb +79 -83
- metadata +73 -32
- data/examples/README.rdoc +0 -4
- data/test/fixtures/cats.yml +0 -3
- data/test/fixtures/dogs.yml +0 -3
- data/test/test_active_record_associations.rb +0 -81
- data/test/test_active_record_base.rb +0 -93
- data/test/test_condition_base.rb +0 -52
- data/test/test_condition_types.rb +0 -143
- data/test/test_conditions_base.rb +0 -242
- data/test/test_conditions_protection.rb +0 -16
- data/test/test_search_base.rb +0 -227
- data/test/test_search_conditions.rb +0 -19
- data/test/test_search_ordering.rb +0 -165
- data/test/test_search_pagination.rb +0 -72
- data/test/test_search_protection.rb +0 -24
- data/test_libs/ordered_hash.rb +0 -9
@@ -0,0 +1,108 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ActiveRecordTests
|
4
|
+
class BaseTest < ActiveSupport::TestCase
|
5
|
+
def test_standard_find
|
6
|
+
binary_logic = accounts(:binary_logic)
|
7
|
+
neco = accounts(:neco)
|
8
|
+
binary_fun = accounts(:binary_fun)
|
9
|
+
|
10
|
+
assert_equal [binary_logic, binary_fun, neco], Account.all
|
11
|
+
assert_equal binary_logic, Account.first
|
12
|
+
|
13
|
+
assert_equal [binary_logic, binary_fun, neco], Account.find(:all)
|
14
|
+
assert_equal [binary_logic], Account.find(:all, :conditions => {:name => "Binary Logic"})
|
15
|
+
assert_equal [binary_logic], Account.find(:all, :conditions => ["name = ?", "Binary Logic"])
|
16
|
+
assert_equal [binary_logic], Account.find(:all, :conditions => "name = 'Binary Logic'")
|
17
|
+
assert_equal binary_logic, Account.find(:first)
|
18
|
+
assert_equal [binary_logic, binary_fun, neco], Account.find(:all, nil)
|
19
|
+
assert_equal [binary_logic, binary_fun, neco], Account.find(:all, {})
|
20
|
+
assert_equal [binary_logic, binary_fun, neco], Account.find(:all, :select => "id, name")
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_standard_calculations
|
24
|
+
binary_logic = accounts(:binary_logic)
|
25
|
+
neco = accounts(:neco)
|
26
|
+
binary_fun = accounts(:binary_fun)
|
27
|
+
|
28
|
+
assert_equal 3, Account.count({})
|
29
|
+
assert_equal 3, Account.count(nil)
|
30
|
+
assert_equal 3, Account.count(:limit => 1)
|
31
|
+
assert_equal 0, Account.count(:limit => 10, :offset => 10)
|
32
|
+
assert_equal binary_logic.id + neco.id + binary_fun.id, Account.sum("id")
|
33
|
+
assert_equal binary_logic.id + neco.id + binary_fun.id, Account.sum("id", {})
|
34
|
+
assert_equal (binary_logic.id + neco.id + binary_fun.id) / 3.0, Account.average("id")
|
35
|
+
assert_equal neco.id, Account.maximum("id")
|
36
|
+
assert_equal binary_logic.id, Account.minimum("id")
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_valid_ar_options
|
40
|
+
assert_equal [:conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :from, :lock], ActiveRecord::Base.valid_find_options
|
41
|
+
assert_equal [:conditions, :joins, :order, :select, :group, :having, :distinct, :limit, :offset, :include, :from], ActiveRecord::Base.valid_calculations_options
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_build_search
|
45
|
+
search = Account.new_search(:conditions => {:name_keywords => "awesome"}, :page => 2, :per_page => 15)
|
46
|
+
assert_kind_of Searchlogic::Search::Base, search
|
47
|
+
assert_equal({}, search.scope)
|
48
|
+
assert_equal Account, search.klass
|
49
|
+
assert_equal "awesome", search.conditions.name_keywords
|
50
|
+
assert_equal 2, search.page
|
51
|
+
assert_equal 15, search.per_page
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_searchlogic_searching
|
55
|
+
binary_logic = accounts(:binary_logic)
|
56
|
+
neco = accounts(:neco)
|
57
|
+
binary_fun = accounts(:binary_fun)
|
58
|
+
|
59
|
+
assert_equal [binary_logic, binary_fun], Account.all(:conditions => {:name_contains => "Binary"})
|
60
|
+
assert_equal [binary_logic], Account.all(:conditions => {:name_contains => "Binary", :users => {:first_name_starts_with => "Ben"}})
|
61
|
+
assert_equal [], Account.all(:conditions => {:name_contains => "Binary", :users => {:first_name_starts_with => "Ben", :last_name => "Mills"}})
|
62
|
+
assert_equal [binary_logic, neco], Account.all(:conditions => {:users => {:id_gt => 0}}, :include => :users)
|
63
|
+
|
64
|
+
read_only_accounts = Account.all(:conditions => {:name_contains => "Binary"}, :readonly => true)
|
65
|
+
assert read_only_accounts.first.readonly?
|
66
|
+
|
67
|
+
assert_equal [binary_logic, binary_fun], Account.all(:conditions => {:name_contains => "Binary"}, :page => 2)
|
68
|
+
assert_equal [], Account.all(:conditions => {:name_contains => "Binary"}, :page => 2, :per_page => 20)
|
69
|
+
|
70
|
+
assert_equal [binary_logic], Account.scope1.all(:conditions => {:users => {:first_name_starts_with => "Ben"}})
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_searchlogic_counting
|
74
|
+
assert_equal 2, Account.count(:conditions => {:name_contains => "Binary"})
|
75
|
+
assert_equal 1, Account.count(:conditions => {:name_contains => "Binary", :users => {:first_name_contains => "Ben"}})
|
76
|
+
assert_equal 1, Account.count(:conditions => {:name_contains => "Binary", :users => {:first_name_contains => "Ben"}}, :limit => 10, :offset => 10, :order_by => "id", :group => "id")
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_scoping
|
80
|
+
assert_equal({:conditions => {:name => "Binary"}, :limit => 10, :readonly => true}, Account.send(:with_scope, :find => {:conditions => {:name => "Binary"}, :limit => 10, :readonly => true}) { Account.send(:scope, :find) })
|
81
|
+
assert_equal({:conditions => ["\"accounts\".\"name\" LIKE ?", "%Binary%"], :limit => 10, :offset => 20}, Account.send(:with_scope, :find => {:conditions => {:name_contains => "Binary"}, :per_page => 10, :page => 3}) { Account.send(:scope, :find) })
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_accessible_conditions
|
85
|
+
Account.conditions_accessible :name_contains
|
86
|
+
assert_equal Set.new(["name_contains"]), Account.accessible_conditions
|
87
|
+
Account.conditions_accessible :id_gt
|
88
|
+
assert_equal Set.new(["id_gt", "name_contains"]), Account.accessible_conditions
|
89
|
+
Account.conditions_accessible :id_gt, :name_contains
|
90
|
+
assert_equal Set.new(["id_gt", "name_contains"]), Account.accessible_conditions
|
91
|
+
Account.send(:write_inheritable_attribute, :conditions_accessible, nil)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_protected_conditions
|
95
|
+
Account.conditions_protected :name_contains
|
96
|
+
assert_equal Set.new(["name_contains"]), Account.protected_conditions
|
97
|
+
Account.conditions_protected :id_gt
|
98
|
+
assert_equal Set.new(["id_gt", "name_contains"]), Account.protected_conditions
|
99
|
+
Account.conditions_protected :id_gt, :name_contains
|
100
|
+
assert_equal Set.new(["id_gt", "name_contains"]), Account.protected_conditions
|
101
|
+
Account.send(:write_inheritable_attribute, :conditions_protected, nil)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_includes
|
105
|
+
assert_nothing_raised { Account.all(:conditions => {:users => {:first_name_like => "Ben"}}, :include => :users) }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class BaseTest < ActiveSupport::TestCase
|
5
|
+
def test_condition_type_name
|
6
|
+
assert_equal "equals", Searchlogic::Condition::Equals.condition_type_name
|
7
|
+
assert_equal "keywords", Searchlogic::Condition::Keywords.condition_type_name
|
8
|
+
assert_equal "greater_than_or_equal_to", Searchlogic::Condition::GreaterThanOrEqualTo.condition_type_name
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_ignore_meaningless_value?
|
12
|
+
assert !Searchlogic::Condition::Equals.ignore_meaningless_value?
|
13
|
+
assert Searchlogic::Condition::Keywords.ignore_meaningless_value?
|
14
|
+
assert !Searchlogic::Condition::NotEqual.ignore_meaningless_value?
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_value_type
|
18
|
+
assert_nil Searchlogic::Condition::Equals.value_type
|
19
|
+
assert_nil Searchlogic::Condition::Keywords.value_type
|
20
|
+
assert_equal :boolean, Searchlogic::Condition::Nil.value_type
|
21
|
+
assert_equal :boolean, Searchlogic::Condition::Blank.value_type
|
22
|
+
assert_nil Searchlogic::Condition::GreaterThan.value_type
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_initialize
|
26
|
+
condition = Searchlogic::Condition::Keywords.new(Account, :column => Account.columns_hash["name"])
|
27
|
+
assert_equal condition.klass, Account
|
28
|
+
assert_equal Account.columns_hash["name"], condition.column
|
29
|
+
|
30
|
+
condition = Searchlogic::Condition::GreaterThan.new(Account, :column => "id")
|
31
|
+
assert_equal Account.columns_hash["id"], condition.column
|
32
|
+
|
33
|
+
condition = Searchlogic::Condition::GreaterThan.new(Account, :column => "id", :column_type => :string, :column_sql_format => "some sql")
|
34
|
+
assert_equal Account.columns_hash["id"], condition.column
|
35
|
+
condition.value = "awesome"
|
36
|
+
assert_equal ["some sql > ?", "awesome"], condition.sanitize
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_explicitly_set_value
|
40
|
+
condition = Searchlogic::Condition::Keywords.new(Account, :column => Account.columns_hash["name"])
|
41
|
+
assert !condition.explicitly_set_value?
|
42
|
+
condition.value = "test"
|
43
|
+
assert condition.explicitly_set_value?
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_sanitize
|
47
|
+
# This is tested thoroughly in test_condition_types
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_value
|
51
|
+
# This is tested thoroughly in test_condition_types
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class BeginsWithTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::BeginsWith.new(Account, :column => Account.columns_hash["name"])
|
7
|
+
condition.value = "Binary"
|
8
|
+
assert_equal ["\"accounts\".\"name\" LIKE ?", "Binary%"], condition.sanitize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class BlankTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
|
7
|
+
condition.value = "true"
|
8
|
+
assert_equal "\"accounts\".\"id\" IS NULL or \"accounts\".\"id\" = '' or \"accounts\".\"id\" = false", condition.sanitize
|
9
|
+
|
10
|
+
condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
|
11
|
+
condition.value = "false"
|
12
|
+
assert_equal "\"accounts\".\"id\" IS NOT NULL and \"accounts\".\"id\" != '' and \"accounts\".\"id\" != false", condition.sanitize
|
13
|
+
|
14
|
+
condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
|
15
|
+
condition.value = true
|
16
|
+
assert_equal "\"accounts\".\"id\" IS NULL or \"accounts\".\"id\" = '' or \"accounts\".\"id\" = false", condition.sanitize
|
17
|
+
|
18
|
+
condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
|
19
|
+
condition.value = false
|
20
|
+
assert_equal "\"accounts\".\"id\" IS NOT NULL and \"accounts\".\"id\" != '' and \"accounts\".\"id\" != false", condition.sanitize
|
21
|
+
|
22
|
+
condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
|
23
|
+
condition.value = nil
|
24
|
+
assert_nil condition.sanitize
|
25
|
+
|
26
|
+
condition = Searchlogic::Condition::Blank.new(Account, :column => Account.columns_hash["id"])
|
27
|
+
condition.value = ""
|
28
|
+
assert_nil condition.sanitize
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class ChildOfTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
ben = users(:ben)
|
7
|
+
|
8
|
+
condition = Searchlogic::Condition::ChildOf.new(User)
|
9
|
+
condition.value = ben.id
|
10
|
+
assert_equal ["\"users\".\"parent_id\" = ?", ben.id], condition.sanitize
|
11
|
+
|
12
|
+
condition = Searchlogic::Condition::ChildOf.new(User)
|
13
|
+
condition.value = ben
|
14
|
+
assert_equal ["\"users\".\"parent_id\" = ?", ben.id], condition.sanitize
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class DescendantOfTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
ben = users(:ben)
|
7
|
+
drew = users(:drew)
|
8
|
+
jennifer = users(:jennifer)
|
9
|
+
tren = users(:tren)
|
10
|
+
|
11
|
+
condition = Searchlogic::Condition::DescendantOf.new(User)
|
12
|
+
condition.value = ben
|
13
|
+
assert_equal ["\"users\".\"id\" = ? OR \"users\".\"id\" = ? OR \"users\".\"id\" = ?", drew.id, tren.id, jennifer.id], condition.sanitize
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class EndsWithTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::EndsWith.new(Account, :column => Account.columns_hash["name"])
|
7
|
+
condition.value = "Binary"
|
8
|
+
assert_equal ["\"accounts\".\"name\" LIKE ?", "%Binary"], condition.sanitize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class EqualsTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::Equals.new(Account, :column => Account.columns_hash["id"])
|
7
|
+
condition.value = 12
|
8
|
+
assert_equal ["\"accounts\".\"id\" = ?", 12], condition.sanitize
|
9
|
+
|
10
|
+
condition = Searchlogic::Condition::Equals.new(Account, :column => Account.columns_hash["id"])
|
11
|
+
condition.value = [1,2,3,4]
|
12
|
+
assert_equal ["\"accounts\".\"id\" IN (?)", [1, 2, 3, 4]], condition.sanitize
|
13
|
+
|
14
|
+
condition = Searchlogic::Condition::Equals.new(Account, :column => Account.columns_hash["id"])
|
15
|
+
condition.value = (1..10)
|
16
|
+
assert_equal ["\"accounts\".\"id\" BETWEEN ? AND ?", 1, 10], condition.sanitize
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class GreaterThanOrEqualToTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::GreaterThanOrEqualTo.new(Account, :column => Account.columns_hash["id"])
|
7
|
+
condition.value = 2
|
8
|
+
assert_equal ["\"accounts\".\"id\" >= ?", 2], condition.sanitize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class GreaterThanTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::GreaterThan.new(Account, :column => Account.columns_hash["id"])
|
7
|
+
condition.value = 2
|
8
|
+
assert_equal ["\"accounts\".\"id\" > ?", 2], condition.sanitize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class InclusiveDescendantOfTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
ben = users(:ben)
|
7
|
+
drew = users(:drew)
|
8
|
+
jennifer = users(:jennifer)
|
9
|
+
tren = users(:tren)
|
10
|
+
|
11
|
+
condition = Searchlogic::Condition::InclusiveDescendantOf.new(User)
|
12
|
+
condition.value = ben
|
13
|
+
assert_equal ["(\"users\".\"id\" = ?) OR (\"users\".\"id\" = ? OR \"users\".\"id\" = ? OR \"users\".\"id\" = ?)", ben.id, drew.id, tren.id, jennifer.id], condition.sanitize
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class KeywordsTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::Keywords.new(Account, :column => Account.columns_hash["name"])
|
7
|
+
condition.value = "freedom yeah, freedom YEAH right"
|
8
|
+
assert_equal ["\"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ?", "%freedom%", "%yeah%", "%right%"], condition.sanitize
|
9
|
+
|
10
|
+
condition = Searchlogic::Condition::Keywords.new(Account, :column => Account.columns_hash["name"])
|
11
|
+
condition.value = "%^$*(^$)"
|
12
|
+
assert_nil condition.sanitize
|
13
|
+
|
14
|
+
condition = Searchlogic::Condition::Keywords.new(Account, :column => Account.columns_hash["name"])
|
15
|
+
condition.value = "%^$*(^$) àáâãäåßéèêëìíîïñòóôõöùúûüýÿ"
|
16
|
+
assert_equal ["\"accounts\".\"name\" LIKE ?", "%àáâãäåßéèêëìíîïñòóôõöùúûüýÿ%"], condition.sanitize
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class LessThanOrEqualToTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::LessThanOrEqualTo.new(Account, :column => Account.columns_hash["id"])
|
7
|
+
condition.value = 2
|
8
|
+
assert_equal ["\"accounts\".\"id\" <= ?", 2], condition.sanitize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class LessThanTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::LessThan.new(Account, :column => Account.columns_hash["id"])
|
7
|
+
condition.value = 2
|
8
|
+
assert_equal ["\"accounts\".\"id\" < ?", 2], condition.sanitize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class LikeTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::Like.new(Account, :column => Account.columns_hash["name"])
|
7
|
+
condition.value = "Binary and blah"
|
8
|
+
assert_equal ["\"accounts\".\"name\" LIKE ?", "%Binary and blah%"], condition.sanitize
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
|
+
|
3
|
+
module ConditionTests
|
4
|
+
class NilTest < ActiveSupport::TestCase
|
5
|
+
def test_sanitize
|
6
|
+
condition = Searchlogic::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
|
7
|
+
condition.value = true
|
8
|
+
assert_equal "\"accounts\".\"id\" IS NULL", condition.sanitize
|
9
|
+
|
10
|
+
condition = Searchlogic::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
|
11
|
+
condition.value = false
|
12
|
+
assert_equal "\"accounts\".\"id\" IS NOT NULL", condition.sanitize
|
13
|
+
|
14
|
+
condition = Searchlogic::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
|
15
|
+
condition.value = "true"
|
16
|
+
assert_equal "\"accounts\".\"id\" IS NULL", condition.sanitize
|
17
|
+
|
18
|
+
condition = Searchlogic::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
|
19
|
+
condition.value = "false"
|
20
|
+
assert_equal "\"accounts\".\"id\" IS NOT NULL", condition.sanitize
|
21
|
+
|
22
|
+
condition = Searchlogic::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
|
23
|
+
condition.value = nil
|
24
|
+
assert_nil condition.sanitize
|
25
|
+
|
26
|
+
condition = Searchlogic::Condition::Nil.new(Account, :column => Account.columns_hash["id"])
|
27
|
+
condition.value = ""
|
28
|
+
assert_nil condition.sanitize
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|