searchgasm 0.9.6 → 0.9.7
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 +2 -0
- data/Manifest +34 -21
- data/{README.mdown → README.rdoc} +96 -63
- data/Rakefile +1 -1
- data/examples/README.rdoc +4 -0
- data/lib/searchgasm/active_record/associations.rb +40 -42
- data/lib/searchgasm/active_record/base.rb +75 -61
- data/lib/searchgasm/condition/base.rb +127 -0
- data/lib/searchgasm/condition/begins_with.rb +20 -0
- data/lib/searchgasm/condition/child_of.rb +11 -0
- data/lib/searchgasm/condition/contains.rb +20 -0
- data/lib/searchgasm/condition/descendant_of.rb +24 -0
- data/lib/searchgasm/condition/does_not_equal.rb +28 -0
- data/lib/searchgasm/condition/ends_with.rb +20 -0
- data/lib/searchgasm/condition/equals.rb +20 -0
- data/lib/searchgasm/condition/greater_than.rb +25 -0
- data/lib/searchgasm/condition/greater_than_or_equal_to.rb +20 -0
- data/lib/searchgasm/condition/inclusive_descendant_of.rb +13 -0
- data/lib/searchgasm/condition/keywords.rb +33 -0
- data/lib/searchgasm/condition/less_than.rb +25 -0
- data/lib/searchgasm/condition/less_than_or_equal_to.rb +20 -0
- data/lib/searchgasm/condition/sibling_of.rb +16 -0
- data/lib/searchgasm/condition/tree.rb +16 -0
- data/lib/searchgasm/conditions/base.rb +221 -0
- data/lib/searchgasm/conditions/protection.rb +30 -0
- data/lib/searchgasm/config.rb +137 -0
- data/lib/searchgasm/helpers/form_helper.rb +159 -0
- data/lib/searchgasm/helpers/search_helper.rb +178 -0
- data/lib/searchgasm/helpers/utilities_helper.rb +125 -0
- data/lib/searchgasm/search/base.rb +73 -179
- data/lib/searchgasm/search/conditions.rb +42 -166
- data/lib/searchgasm/search/ordering.rb +149 -0
- data/lib/searchgasm/search/pagination.rb +69 -0
- data/lib/searchgasm/search/protection.rb +61 -0
- data/lib/searchgasm/utilities.rb +30 -0
- data/lib/searchgasm/version.rb +44 -47
- data/lib/searchgasm.rb +57 -21
- data/searchgasm.gemspec +71 -46
- data/test/test_active_record_associations.rb +1 -1
- data/test/test_active_record_base.rb +4 -4
- data/test/test_condition.rb +143 -0
- data/test/{test_searchgasm_conditions.rb → test_conditions_base.rb} +43 -33
- data/test/test_search_base.rb +189 -0
- data/test/test_search_ordering.rb +91 -0
- data/test/test_search_pagination.rb +56 -0
- data/test/test_search_protection.rb +35 -0
- metadata +70 -45
- data/lib/searchgasm/search/condition.rb +0 -105
- data/lib/searchgasm/search/condition_types/begins_with_condition.rb +0 -26
- data/lib/searchgasm/search/condition_types/child_of_condition.rb +0 -17
- data/lib/searchgasm/search/condition_types/contains_condition.rb +0 -26
- data/lib/searchgasm/search/condition_types/descendant_of_condition.rb +0 -30
- data/lib/searchgasm/search/condition_types/does_not_equal_condition.rb +0 -34
- data/lib/searchgasm/search/condition_types/ends_with_condition.rb +0 -26
- data/lib/searchgasm/search/condition_types/equals_condition.rb +0 -26
- data/lib/searchgasm/search/condition_types/greater_than_condition.rb +0 -31
- data/lib/searchgasm/search/condition_types/greater_than_or_equal_to_condition.rb +0 -26
- data/lib/searchgasm/search/condition_types/inclusive_descendant_of_condition.rb +0 -19
- data/lib/searchgasm/search/condition_types/keywords_condition.rb +0 -39
- data/lib/searchgasm/search/condition_types/less_than_condition.rb +0 -31
- data/lib/searchgasm/search/condition_types/less_than_or_equal_to_condition.rb +0 -26
- data/lib/searchgasm/search/condition_types/sibling_of_condition.rb +0 -22
- data/lib/searchgasm/search/condition_types/tree_condition.rb +0 -20
- data/lib/searchgasm/search/utilities.rb +0 -34
- data/test/test_searchgasm_base.rb +0 -185
- data/test/test_searchgasm_condition_types.rb +0 -143
@@ -1,143 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestSearchgasmConditionTypes < Test::Unit::TestCase
|
4
|
-
fixtures :accounts, :users, :orders
|
5
|
-
|
6
|
-
def setup
|
7
|
-
setup_db
|
8
|
-
load_fixtures
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
teardown_db
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_condition_name
|
16
|
-
assert_equal "equals", BinaryLogic::Searchgasm::Search::ConditionTypes::EqualsCondition.condition_name
|
17
|
-
assert_equal "keywords", BinaryLogic::Searchgasm::Search::ConditionTypes::KeywordsCondition.condition_name
|
18
|
-
assert_equal "greater_than_or_equal_to", BinaryLogic::Searchgasm::Search::ConditionTypes::GreaterThanOrEqualToCondition.condition_name
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_string_column
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_comparable_column
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_initialize
|
30
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::KeywordsCondition.new(Account, Account.columns_hash["name"])
|
31
|
-
assert_equal condition.klass, Account
|
32
|
-
assert_equal condition.column, Account.columns_hash["name"]
|
33
|
-
|
34
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::GreaterThanCondition.new(Account, "id")
|
35
|
-
assert_equal condition.column, Account.columns_hash["id"]
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_explicitly_set_value
|
39
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::EqualsCondition.new(Account, Account.columns_hash["name"])
|
40
|
-
assert !condition.explicitly_set_value?
|
41
|
-
condition.value = nil
|
42
|
-
assert condition.explicitly_set_value?
|
43
|
-
|
44
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::KeywordsCondition.new(Account, Account.columns_hash["name"])
|
45
|
-
assert !condition.explicitly_set_value?
|
46
|
-
condition.value = nil
|
47
|
-
assert !condition.explicitly_set_value?
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_ignore_blanks?
|
51
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::EqualsCondition.new(Account, Account.columns_hash["id"])
|
52
|
-
assert !condition.ignore_blanks?
|
53
|
-
|
54
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::KeywordsCondition.new(Account, Account.columns_hash["name"])
|
55
|
-
assert condition.ignore_blanks?
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_sanitize
|
59
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::BeginsWithCondition.new(Account, Account.columns_hash["name"])
|
60
|
-
condition.value = "Binary"
|
61
|
-
assert_equal condition.sanitize, ["\"accounts\".\"name\" LIKE ?", "Binary%"]
|
62
|
-
|
63
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::ChildOfCondition.new(User)
|
64
|
-
condition.value = User.first.id
|
65
|
-
assert_equal condition.sanitize, ["\"users\".\"parent_id\" = ?", User.first.id]
|
66
|
-
|
67
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::ChildOfCondition.new(User)
|
68
|
-
condition.value = User.first
|
69
|
-
assert_equal condition.sanitize, ["\"users\".\"parent_id\" = ?", User.first.id]
|
70
|
-
|
71
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::ContainsCondition.new(Account, Account.columns_hash["name"])
|
72
|
-
condition.value = "Binary and blah"
|
73
|
-
assert_equal condition.sanitize, ["\"accounts\".\"name\" LIKE ?", "%Binary and blah%"]
|
74
|
-
|
75
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::DescendantOfCondition.new(User)
|
76
|
-
condition.value = User.find(1)
|
77
|
-
assert_equal condition.sanitize, ["\"users\".\"id\" = ? OR \"users\".\"id\" = ?", 2, 3]
|
78
|
-
|
79
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::DoesNotEqualCondition.new(Account, Account.columns_hash["id"])
|
80
|
-
condition.value = 12
|
81
|
-
assert_equal condition.sanitize, "\"accounts\".\"id\" != 12"
|
82
|
-
|
83
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::DoesNotEqualCondition.new(Account, Account.columns_hash["id"])
|
84
|
-
condition.value = [1,2,3,4]
|
85
|
-
assert_equal condition.sanitize, "\"accounts\".\"id\" NOT IN (1,2,3,4)"
|
86
|
-
|
87
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::DoesNotEqualCondition.new(Account, Account.columns_hash["id"])
|
88
|
-
condition.value = (1..10)
|
89
|
-
assert_equal condition.sanitize, "\"accounts\".\"id\" NOT BETWEEN 1 AND 10"
|
90
|
-
|
91
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::EndsWithCondition.new(Account, Account.columns_hash["name"])
|
92
|
-
condition.value = "Binary"
|
93
|
-
assert_equal condition.sanitize, ["\"accounts\".\"name\" LIKE ?", "%Binary"]
|
94
|
-
|
95
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::EqualsCondition.new(Account, Account.columns_hash["id"])
|
96
|
-
condition.value = 12
|
97
|
-
assert_equal condition.sanitize, "\"accounts\".\"id\" = 12"
|
98
|
-
|
99
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::EqualsCondition.new(Account, Account.columns_hash["id"])
|
100
|
-
condition.value = [1,2,3,4]
|
101
|
-
assert_equal condition.sanitize, "\"accounts\".\"id\" IN (1,2,3,4)"
|
102
|
-
|
103
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::EqualsCondition.new(Account, Account.columns_hash["id"])
|
104
|
-
condition.value = (1..10)
|
105
|
-
assert_equal condition.sanitize, "\"accounts\".\"id\" BETWEEN 1 AND 10"
|
106
|
-
|
107
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::GreaterThanCondition.new(Account, Account.columns_hash["id"])
|
108
|
-
condition.value = 2
|
109
|
-
assert_equal condition.sanitize, ["\"accounts\".\"id\" > ?", 2]
|
110
|
-
|
111
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::GreaterThanOrEqualToCondition.new(Account, Account.columns_hash["id"])
|
112
|
-
condition.value = 2
|
113
|
-
assert_equal condition.sanitize, ["\"accounts\".\"id\" >= ?", 2]
|
114
|
-
|
115
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::InclusiveDescendantOfCondition.new(User)
|
116
|
-
condition.value = User.find(1)
|
117
|
-
assert_equal condition.sanitize, ["(\"users\".\"id\" = ?) OR (\"users\".\"id\" = ? OR \"users\".\"id\" = ?)", 1, 2, 3]
|
118
|
-
|
119
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::KeywordsCondition.new(Account, Account.columns_hash["name"])
|
120
|
-
condition.value = "freedom yeah, freedom YEAH right"
|
121
|
-
assert_equal condition.sanitize, ["\"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ?", "%freedom%", "%yeah%", "%right%"]
|
122
|
-
|
123
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::KeywordsCondition.new(Account, Account.columns_hash["name"])
|
124
|
-
condition.value = "%^$*(^$)"
|
125
|
-
assert_equal condition.sanitize, nil
|
126
|
-
|
127
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::LessThanCondition.new(Account, Account.columns_hash["id"])
|
128
|
-
condition.value = 2
|
129
|
-
assert_equal condition.sanitize, ["\"accounts\".\"id\" < ?", 2]
|
130
|
-
|
131
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::LessThanOrEqualToCondition.new(Account, Account.columns_hash["id"])
|
132
|
-
condition.value = 2
|
133
|
-
assert_equal condition.sanitize, ["\"accounts\".\"id\" <= ?", 2]
|
134
|
-
|
135
|
-
condition = BinaryLogic::Searchgasm::Search::ConditionTypes::SiblingOfCondition.new(User)
|
136
|
-
condition.value = User.find(2)
|
137
|
-
assert_equal condition.sanitize, ["(\"users\".\"id\" != ?) AND (\"users\".\"parent_id\" = ?)", 2, 1]
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_value
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|