searchgasm 1.2.2 → 1.3.0
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 +8 -0
- data/Manifest +42 -3
- data/README.rdoc +101 -82
- data/TODO.rdoc +1 -3
- data/lib/searchgasm/active_record/connection_adapters/mysql_adapter.rb +143 -6
- data/lib/searchgasm/active_record/connection_adapters/postgresql_adapter.rb +148 -0
- data/lib/searchgasm/active_record/connection_adapters/sqlite_adapter.rb +54 -0
- data/lib/searchgasm/condition/base.rb +59 -86
- data/lib/searchgasm/condition/begins_with.rb +3 -8
- data/lib/searchgasm/condition/blank.rb +5 -5
- data/lib/searchgasm/condition/ends_with.rb +3 -8
- data/lib/searchgasm/condition/equals.rb +4 -3
- data/lib/searchgasm/condition/greater_than.rb +3 -14
- data/lib/searchgasm/condition/greater_than_or_equal_to.rb +3 -14
- data/lib/searchgasm/condition/keywords.rb +3 -8
- data/lib/searchgasm/condition/less_than.rb +3 -14
- data/lib/searchgasm/condition/less_than_or_equal_to.rb +3 -14
- data/lib/searchgasm/condition/like.rb +15 -0
- data/lib/searchgasm/condition/nil.rb +5 -5
- data/lib/searchgasm/condition/not_begin_with.rb +17 -0
- data/lib/searchgasm/condition/not_end_with.rb +17 -0
- data/lib/searchgasm/condition/{does_not_equal.rb → not_equal.rb} +5 -4
- data/lib/searchgasm/condition/not_have_keywords.rb +17 -0
- data/lib/searchgasm/condition/not_like.rb +17 -0
- data/lib/searchgasm/condition/tree.rb +4 -5
- data/lib/searchgasm/conditions/base.rb +218 -72
- data/lib/searchgasm/modifiers/absolute.rb +15 -0
- data/lib/searchgasm/modifiers/acos.rb +11 -0
- data/lib/searchgasm/modifiers/asin.rb +11 -0
- data/lib/searchgasm/modifiers/atan.rb +11 -0
- data/lib/searchgasm/modifiers/base.rb +27 -0
- data/lib/searchgasm/modifiers/ceil.rb +15 -0
- data/lib/searchgasm/modifiers/char_length.rb +15 -0
- data/lib/searchgasm/modifiers/cos.rb +15 -0
- data/lib/searchgasm/modifiers/cot.rb +15 -0
- data/lib/searchgasm/modifiers/day_of_month.rb +15 -0
- data/lib/searchgasm/modifiers/day_of_week.rb +15 -0
- data/lib/searchgasm/modifiers/day_of_year.rb +15 -0
- data/lib/searchgasm/modifiers/degrees.rb +11 -0
- data/lib/searchgasm/modifiers/exp.rb +15 -0
- data/lib/searchgasm/modifiers/floor.rb +15 -0
- data/lib/searchgasm/modifiers/hex.rb +11 -0
- data/lib/searchgasm/modifiers/hour.rb +11 -0
- data/lib/searchgasm/modifiers/log.rb +15 -0
- data/lib/searchgasm/modifiers/log10.rb +11 -0
- data/lib/searchgasm/modifiers/log2.rb +11 -0
- data/lib/searchgasm/modifiers/md5.rb +11 -0
- data/lib/searchgasm/modifiers/microseconds.rb +11 -0
- data/lib/searchgasm/modifiers/milliseconds.rb +11 -0
- data/lib/searchgasm/modifiers/minute.rb +15 -0
- data/lib/searchgasm/modifiers/month.rb +15 -0
- data/lib/searchgasm/modifiers/octal.rb +15 -0
- data/lib/searchgasm/modifiers/radians.rb +11 -0
- data/lib/searchgasm/modifiers/round.rb +11 -0
- data/lib/searchgasm/modifiers/second.rb +15 -0
- data/lib/searchgasm/modifiers/sign.rb +11 -0
- data/lib/searchgasm/modifiers/sin.rb +11 -0
- data/lib/searchgasm/modifiers/square_root.rb +15 -0
- data/lib/searchgasm/modifiers/tan.rb +15 -0
- data/lib/searchgasm/modifiers/week.rb +11 -0
- data/lib/searchgasm/modifiers/year.rb +11 -0
- data/lib/searchgasm/shared/utilities.rb +0 -10
- data/lib/searchgasm/version.rb +2 -2
- data/lib/searchgasm.rb +15 -19
- data/searchgasm.gemspec +86 -9
- data/test/libs/ordered_hash.rb +9 -0
- data/test/test_condition_base.rb +21 -47
- data/test/test_condition_types.rb +44 -44
- data/test/test_conditions_base.rb +34 -21
- data/test/test_helper.rb +1 -0
- data/test/test_search_conditions.rb +1 -1
- metadata +85 -8
- data/lib/searchgasm/condition/contains.rb +0 -20
- data/lib/searchgasm/condition/during_evening.rb +0 -32
@@ -4,130 +4,130 @@ class TestConditionTypes < Test::Unit::TestCase
|
|
4
4
|
def test_sanitize
|
5
5
|
condition = Searchgasm::Condition::BeginsWith.new(Account, Account.columns_hash["name"])
|
6
6
|
condition.value = "Binary"
|
7
|
-
assert_equal
|
7
|
+
assert_equal ["\"accounts\".\"name\" LIKE ?", "Binary%"], condition.sanitize
|
8
8
|
|
9
9
|
condition = Searchgasm::Condition::Blank.new(Account, Account.columns_hash["id"])
|
10
10
|
condition.value = true
|
11
|
-
assert_equal
|
11
|
+
assert_equal "\"accounts\".\"id\" is NULL or \"accounts\".\"id\" = ''", condition.sanitize
|
12
12
|
|
13
13
|
condition = Searchgasm::Condition::Blank.new(Account, Account.columns_hash["id"])
|
14
14
|
condition.value = false
|
15
|
-
assert_equal
|
15
|
+
assert_equal "\"accounts\".\"id\" is NOT NULL and \"accounts\".\"id\" != ''", condition.sanitize
|
16
16
|
|
17
17
|
condition = Searchgasm::Condition::Blank.new(Account, Account.columns_hash["id"])
|
18
18
|
condition.value = "true"
|
19
|
-
assert_equal
|
19
|
+
assert_equal "\"accounts\".\"id\" is NULL or \"accounts\".\"id\" = ''", condition.sanitize
|
20
20
|
|
21
21
|
condition = Searchgasm::Condition::Blank.new(Account, Account.columns_hash["id"])
|
22
22
|
condition.value = "false"
|
23
|
-
assert_equal
|
23
|
+
assert_equal "\"accounts\".\"id\" is NOT NULL and \"accounts\".\"id\" != ''", condition.sanitize
|
24
24
|
|
25
25
|
condition = Searchgasm::Condition::Blank.new(Account, Account.columns_hash["id"])
|
26
26
|
condition.value = nil
|
27
|
-
assert_equal condition.sanitize
|
27
|
+
assert_equal nil, condition.sanitize
|
28
28
|
|
29
29
|
condition = Searchgasm::Condition::Blank.new(Account, Account.columns_hash["id"])
|
30
30
|
condition.value = ""
|
31
|
-
assert_equal condition.sanitize
|
31
|
+
assert_equal nil, condition.sanitize
|
32
32
|
|
33
33
|
condition = Searchgasm::Condition::ChildOf.new(User)
|
34
34
|
condition.value = User.first.id
|
35
|
-
assert_equal
|
35
|
+
assert_equal ["\"users\".\"parent_id\" = ?", User.first.id], condition.sanitize
|
36
36
|
|
37
37
|
condition = Searchgasm::Condition::ChildOf.new(User)
|
38
38
|
condition.value = User.first
|
39
|
-
assert_equal
|
40
|
-
|
41
|
-
condition = Searchgasm::Condition::Contains.new(Account, Account.columns_hash["name"])
|
42
|
-
condition.value = "Binary and blah"
|
43
|
-
assert_equal condition.sanitize, ["\"accounts\".\"name\" LIKE ?", "%Binary and blah%"]
|
39
|
+
assert_equal ["\"users\".\"parent_id\" = ?", User.first.id], condition.sanitize
|
44
40
|
|
45
41
|
condition = Searchgasm::Condition::DescendantOf.new(User)
|
46
42
|
condition.value = User.find(1)
|
47
|
-
assert_equal
|
48
|
-
|
49
|
-
condition = Searchgasm::Condition::DoesNotEqual.new(Account, Account.columns_hash["id"])
|
50
|
-
condition.value = 12
|
51
|
-
assert_equal condition.sanitize, "\"accounts\".\"id\" != 12"
|
52
|
-
|
53
|
-
condition = Searchgasm::Condition::DoesNotEqual.new(Account, Account.columns_hash["id"])
|
54
|
-
condition.value = [1,2,3,4]
|
55
|
-
assert_equal condition.sanitize, "\"accounts\".\"id\" NOT IN (1,2,3,4)"
|
56
|
-
|
57
|
-
condition = Searchgasm::Condition::DoesNotEqual.new(Account, Account.columns_hash["id"])
|
58
|
-
condition.value = (1..10)
|
59
|
-
assert_equal condition.sanitize, "\"accounts\".\"id\" NOT BETWEEN 1 AND 10"
|
43
|
+
assert_equal ["\"users\".\"id\" = ? OR \"users\".\"id\" = ?", 2, 3], condition.sanitize
|
60
44
|
|
61
45
|
condition = Searchgasm::Condition::EndsWith.new(Account, Account.columns_hash["name"])
|
62
46
|
condition.value = "Binary"
|
63
|
-
assert_equal
|
47
|
+
assert_equal ["\"accounts\".\"name\" LIKE ?", "%Binary"], condition.sanitize
|
64
48
|
|
65
49
|
condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["id"])
|
66
50
|
condition.value = 12
|
67
|
-
assert_equal
|
51
|
+
assert_equal "\"accounts\".\"id\" = 12", condition.sanitize
|
68
52
|
|
69
53
|
condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["id"])
|
70
54
|
condition.value = [1,2,3,4]
|
71
|
-
assert_equal
|
55
|
+
assert_equal "\"accounts\".\"id\" IN (1,2,3,4)", condition.sanitize
|
72
56
|
|
73
57
|
condition = Searchgasm::Condition::Equals.new(Account, Account.columns_hash["id"])
|
74
58
|
condition.value = (1..10)
|
75
|
-
assert_equal
|
59
|
+
assert_equal "\"accounts\".\"id\" BETWEEN 1 AND 10", condition.sanitize
|
76
60
|
|
77
61
|
condition = Searchgasm::Condition::GreaterThan.new(Account, Account.columns_hash["id"])
|
78
62
|
condition.value = 2
|
79
|
-
assert_equal
|
63
|
+
assert_equal ["\"accounts\".\"id\" > ?", 2], condition.sanitize
|
80
64
|
|
81
65
|
condition = Searchgasm::Condition::GreaterThanOrEqualTo.new(Account, Account.columns_hash["id"])
|
82
66
|
condition.value = 2
|
83
|
-
assert_equal
|
67
|
+
assert_equal ["\"accounts\".\"id\" >= ?", 2], condition.sanitize
|
84
68
|
|
85
69
|
condition = Searchgasm::Condition::InclusiveDescendantOf.new(User)
|
86
70
|
condition.value = User.find(1)
|
87
|
-
assert_equal
|
71
|
+
assert_equal ["(\"users\".\"id\" = ?) OR (\"users\".\"id\" = ? OR \"users\".\"id\" = ?)", 1, 2, 3], condition.sanitize
|
72
|
+
|
73
|
+
condition = Searchgasm::Condition::Like.new(Account, Account.columns_hash["name"])
|
74
|
+
condition.value = "Binary and blah"
|
75
|
+
assert_equal ["\"accounts\".\"name\" LIKE ?", "%Binary and blah%"], condition.sanitize
|
88
76
|
|
89
77
|
condition = Searchgasm::Condition::Nil.new(Account, Account.columns_hash["id"])
|
90
78
|
condition.value = true
|
91
|
-
assert_equal
|
79
|
+
assert_equal "\"accounts\".\"id\" is NULL", condition.sanitize
|
92
80
|
|
93
81
|
condition = Searchgasm::Condition::Nil.new(Account, Account.columns_hash["id"])
|
94
82
|
condition.value = false
|
95
|
-
assert_equal
|
83
|
+
assert_equal "\"accounts\".\"id\" is NOT NULL", condition.sanitize
|
96
84
|
|
97
85
|
condition = Searchgasm::Condition::Nil.new(Account, Account.columns_hash["id"])
|
98
86
|
condition.value = "true"
|
99
|
-
assert_equal
|
87
|
+
assert_equal "\"accounts\".\"id\" is NULL", condition.sanitize
|
100
88
|
|
101
89
|
condition = Searchgasm::Condition::Nil.new(Account, Account.columns_hash["id"])
|
102
90
|
condition.value = "false"
|
103
|
-
assert_equal
|
91
|
+
assert_equal "\"accounts\".\"id\" is NOT NULL", condition.sanitize
|
104
92
|
|
105
93
|
condition = Searchgasm::Condition::Nil.new(Account, Account.columns_hash["id"])
|
106
94
|
condition.value = nil
|
107
|
-
assert_equal condition.sanitize
|
95
|
+
assert_equal nil, condition.sanitize
|
108
96
|
|
109
97
|
condition = Searchgasm::Condition::Nil.new(Account, Account.columns_hash["id"])
|
110
98
|
condition.value = ""
|
111
|
-
assert_equal condition.sanitize
|
99
|
+
assert_equal nil, condition.sanitize
|
100
|
+
|
101
|
+
condition = Searchgasm::Condition::NotEqual.new(Account, Account.columns_hash["id"])
|
102
|
+
condition.value = 12
|
103
|
+
assert_equal "\"accounts\".\"id\" != 12", condition.sanitize
|
104
|
+
|
105
|
+
condition = Searchgasm::Condition::NotEqual.new(Account, Account.columns_hash["id"])
|
106
|
+
condition.value = [1,2,3,4]
|
107
|
+
assert_equal "\"accounts\".\"id\" NOT IN (1,2,3,4)", condition.sanitize
|
108
|
+
|
109
|
+
condition = Searchgasm::Condition::NotEqual.new(Account, Account.columns_hash["id"])
|
110
|
+
condition.value = (1..10)
|
111
|
+
assert_equal "\"accounts\".\"id\" NOT BETWEEN 1 AND 10", condition.sanitize
|
112
112
|
|
113
113
|
condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
|
114
114
|
condition.value = "freedom yeah, freedom YEAH right"
|
115
|
-
assert_equal
|
115
|
+
assert_equal ["\"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ? AND \"accounts\".\"name\" LIKE ?", "%freedom%", "%yeah%", "%right%"], condition.sanitize
|
116
116
|
|
117
117
|
condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
|
118
118
|
condition.value = "%^$*(^$)"
|
119
|
-
assert_equal condition.sanitize
|
119
|
+
assert_equal nil, condition.sanitize
|
120
120
|
|
121
121
|
condition = Searchgasm::Condition::LessThan.new(Account, Account.columns_hash["id"])
|
122
122
|
condition.value = 2
|
123
|
-
assert_equal
|
123
|
+
assert_equal ["\"accounts\".\"id\" < ?", 2], condition.sanitize
|
124
124
|
|
125
125
|
condition = Searchgasm::Condition::LessThanOrEqualTo.new(Account, Account.columns_hash["id"])
|
126
126
|
condition.value = 2
|
127
|
-
assert_equal
|
127
|
+
assert_equal ["\"accounts\".\"id\" <= ?", 2], condition.sanitize
|
128
128
|
|
129
129
|
condition = Searchgasm::Condition::SiblingOf.new(User)
|
130
130
|
condition.value = User.find(2)
|
131
|
-
assert_equal
|
131
|
+
assert_equal ["(\"users\".\"id\" != ?) AND (\"users\".\"parent_id\" = ?)", 2, 1], condition.sanitize
|
132
132
|
end
|
133
133
|
end
|
@@ -5,8 +5,8 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
5
5
|
Searchgasm::Conditions::Base.register_condition(Searchgasm::Condition::Keywords)
|
6
6
|
assert [Searchgasm::Condition::Keywords], Searchgasm::Conditions::Base.conditions
|
7
7
|
|
8
|
-
Searchgasm::Conditions::Base.register_condition(Searchgasm::Condition::
|
9
|
-
assert [Searchgasm::Condition::Keywords, Searchgasm::Condition::
|
8
|
+
Searchgasm::Conditions::Base.register_condition(Searchgasm::Condition::Like)
|
9
|
+
assert [Searchgasm::Condition::Keywords, Searchgasm::Condition::Like], Searchgasm::Conditions::Base.conditions
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_association_names
|
@@ -44,11 +44,11 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
44
44
|
conditions.name_contains = "Binary"
|
45
45
|
assert_equal ["\"accounts\".\"name\" LIKE ?", "%Binary%"], conditions.sanitize
|
46
46
|
conditions.id = 1
|
47
|
-
assert_equal ["(\"accounts\".\"
|
47
|
+
assert_equal ["(\"accounts\".\"id\" = 1) AND (\"accounts\".\"name\" LIKE ?)", "%Binary%"], conditions.sanitize
|
48
48
|
conditions.any = true
|
49
|
-
assert_equal ["(\"accounts\".\"
|
49
|
+
assert_equal ["(\"accounts\".\"id\" = 1) OR (\"accounts\".\"name\" LIKE ?)", "%Binary%"], conditions.sanitize
|
50
50
|
conditions.any = false
|
51
|
-
assert_equal ["(\"accounts\".\"
|
51
|
+
assert_equal ["(\"accounts\".\"id\" = 1) AND (\"accounts\".\"name\" LIKE ?)", "%Binary%"], conditions.sanitize
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_auto_joins
|
@@ -76,13 +76,13 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
76
76
|
conditions.id_gt = 5
|
77
77
|
now = Time.now
|
78
78
|
conditions.created_after = now
|
79
|
-
assert_equal
|
79
|
+
assert_equal ["(\"accounts\".\"created_at\" > ?) AND (\"accounts\".\"id\" > ?) AND (\"accounts\".\"name\" LIKE ?)", now, 5, "%Binary%"], conditions.sanitize
|
80
80
|
|
81
81
|
# test out associations
|
82
82
|
conditions.users.first_name_like = "Ben"
|
83
83
|
conditions.users.id_gt = 10
|
84
84
|
conditions.users.orders.total_lt = 500
|
85
|
-
assert_equal
|
85
|
+
assert_equal ["(\"accounts\".\"created_at\" > ?) AND (\"accounts\".\"id\" > ?) AND (\"accounts\".\"name\" LIKE ?) AND ((\"users\".\"first_name\" LIKE ?) AND (\"users\".\"id\" > ?) AND (\"orders\".\"total\" < ?))", now, 5, "%Binary%", "%Ben%", 10, 500], conditions.sanitize
|
86
86
|
|
87
87
|
# test that raw sql is returned
|
88
88
|
conditions.conditions = "awesome"
|
@@ -92,33 +92,33 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
92
92
|
def test_conditions
|
93
93
|
conditions = Searchgasm::Cache::AccountConditions.new
|
94
94
|
now = Time.now
|
95
|
-
v = {:
|
95
|
+
v = {:name_like => "Binary", :created_at_greater_than => now}
|
96
96
|
conditions.conditions = v
|
97
97
|
assert_equal v, conditions.conditions
|
98
98
|
|
99
99
|
sql = "id in (1,2,3,4)"
|
100
100
|
conditions.conditions = sql
|
101
101
|
assert_equal sql, conditions.conditions
|
102
|
-
assert_equal
|
102
|
+
assert_equal({}, conditions.send(:objects))
|
103
103
|
|
104
104
|
v2 = {:id_less_than => 5, :name_begins_with => "Beginning of string"}
|
105
105
|
conditions.conditions = v2
|
106
106
|
assert_equal v2, conditions.conditions
|
107
107
|
|
108
|
-
v = {:
|
108
|
+
v = {:name_like => "Binary", :created_at_greater_than => now}
|
109
109
|
conditions.conditions = v
|
110
110
|
assert_equal v2.merge(v), conditions.conditions
|
111
111
|
|
112
112
|
sql2 = "id > 5 and name = 'Test'"
|
113
113
|
conditions.conditions = sql2
|
114
114
|
assert_equal sql2, conditions.conditions
|
115
|
-
assert_equal
|
115
|
+
assert_equal({}, conditions.send(:objects))
|
116
116
|
|
117
117
|
conditions.name_contains = "awesome"
|
118
|
-
assert_equal({:
|
118
|
+
assert_equal({:name_like => "awesome"}, conditions.conditions)
|
119
119
|
|
120
120
|
conditions.conditions = {:id_gt => "", :name_starts_with => "Ben"}
|
121
|
-
assert_equal({:
|
121
|
+
assert_equal({:name_like => "awesome", :name_begins_with => "Ben"}, conditions.conditions)
|
122
122
|
end
|
123
123
|
|
124
124
|
# Other general usage tests, need to clean these up
|
@@ -150,7 +150,7 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
150
150
|
|
151
151
|
def test_assert_valid_values
|
152
152
|
conditions = Searchgasm::Cache::UserConditions.new
|
153
|
-
assert_raise(
|
153
|
+
assert_raise(NoMethodError) { conditions.conditions = {:unknown => "blah"} }
|
154
154
|
assert_nothing_raised { conditions.conditions = {:first_name => "blah"} }
|
155
155
|
assert_nothing_raised { conditions.conditions = {:first_name_contains => "blah"} }
|
156
156
|
end
|
@@ -163,15 +163,27 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
163
163
|
assert_equal conditions.users.last_name_begins_with, "Ben"
|
164
164
|
end
|
165
165
|
|
166
|
+
def test_virtual_columns
|
167
|
+
conditions = Searchgasm::Cache::AccountConditions.new
|
168
|
+
conditions.hour_of_created_gt = 2
|
169
|
+
assert_equal ["strftime('%H', \"accounts\".\"created_at\") > ?", 2], conditions.sanitize
|
170
|
+
conditions.dow_of_created_at_most = 5
|
171
|
+
assert_equal ["(strftime('%w', \"accounts\".\"created_at\") <= ?) AND (strftime('%H', \"accounts\".\"created_at\") > ?)", 5, 2], conditions.sanitize
|
172
|
+
conditions.month_of_created_at_nil = true
|
173
|
+
assert_equal ["(strftime('%w', \"accounts\".\"created_at\") <= ?) AND (strftime('%H', \"accounts\".\"created_at\") > ?) AND (strftime('%m', \"accounts\".\"created_at\") is NULL)", 5, 2], conditions.sanitize
|
174
|
+
conditions.min_of_hour_of_month_of_created_at_nil = true
|
175
|
+
assert_equal ["(strftime('%w', \"accounts\".\"created_at\") <= ?) AND (strftime('%H', \"accounts\".\"created_at\") > ?) AND (strftime('%m', strftime('%H', strftime('%M', \"accounts\".\"created_at\"))) is NULL) AND (strftime('%m', \"accounts\".\"created_at\") is NULL)", 5, 2], conditions.sanitize
|
176
|
+
end
|
177
|
+
|
166
178
|
def test_objects
|
167
179
|
conditions = Searchgasm::Cache::AccountConditions.new
|
168
|
-
assert_equal conditions.send(:objects)
|
180
|
+
assert_equal({}, conditions.send(:objects))
|
169
181
|
|
170
182
|
conditions.name_contains = "Binary"
|
171
|
-
assert_equal conditions.send(:objects).size
|
183
|
+
assert_equal 1, conditions.send(:objects).size
|
172
184
|
|
173
185
|
conditions.users.first_name_contains = "Ben"
|
174
|
-
assert_equal conditions.send(:objects).size
|
186
|
+
assert_equal 2, conditions.send(:objects).size
|
175
187
|
end
|
176
188
|
|
177
189
|
def test_reset
|
@@ -180,14 +192,15 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
180
192
|
conditions.name_contains = "Binary"
|
181
193
|
assert_equal 1, conditions.send(:objects).size
|
182
194
|
|
183
|
-
conditions.
|
184
|
-
|
195
|
+
conditions.reset_name_like!
|
196
|
+
conditions.reset_name_contains! # should set up aliases for reset
|
197
|
+
assert_equal({}, conditions.send(:objects))
|
185
198
|
|
186
199
|
conditions.users.first_name_like = "Ben"
|
187
200
|
assert_equal 1, conditions.send(:objects).size
|
188
201
|
|
189
202
|
conditions.reset_users!
|
190
|
-
assert_equal
|
203
|
+
assert_equal({}, conditions.send(:objects))
|
191
204
|
|
192
205
|
conditions.name_begins_with ="Binary"
|
193
206
|
conditions.users.orders.total_gt = 200
|
@@ -197,6 +210,6 @@ class TestConditionsBase < Test::Unit::TestCase
|
|
197
210
|
assert_equal 1, conditions.send(:objects).size
|
198
211
|
|
199
212
|
conditions.reset_users!
|
200
|
-
assert_equal
|
213
|
+
assert_equal({}, conditions.send(:objects))
|
201
214
|
end
|
202
215
|
end
|
data/test/test_helper.rb
CHANGED
@@ -3,6 +3,7 @@ require "rubygems"
|
|
3
3
|
require "ruby-debug"
|
4
4
|
require "activerecord"
|
5
5
|
require File.dirname(__FILE__) + '/libs/acts_as_tree'
|
6
|
+
require File.dirname(__FILE__) + '/libs/ordered_hash'
|
6
7
|
require File.dirname(__FILE__) + '/libs/rexml_fix'
|
7
8
|
require File.dirname(__FILE__) + '/../lib/searchgasm'
|
8
9
|
|
@@ -10,7 +10,7 @@ class TestSearchConditions < Test::Unit::TestCase
|
|
10
10
|
assert_kind_of Searchgasm::Conditions::Base, search.conditions
|
11
11
|
|
12
12
|
search = Account.new_search(:conditions => {:name_like => "Ben"})
|
13
|
-
assert_equal({:
|
13
|
+
assert_equal({:name_like => "Ben"}, search.conditions.conditions)
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_auto_joins
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: searchgasm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Johnson of Binary Logic
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-02 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -59,10 +59,7 @@ extra_rdoc_files:
|
|
59
59
|
- lib/searchgasm/condition/begins_with.rb
|
60
60
|
- lib/searchgasm/condition/blank.rb
|
61
61
|
- lib/searchgasm/condition/child_of.rb
|
62
|
-
- lib/searchgasm/condition/contains.rb
|
63
62
|
- lib/searchgasm/condition/descendant_of.rb
|
64
|
-
- lib/searchgasm/condition/does_not_equal.rb
|
65
|
-
- lib/searchgasm/condition/during_evening.rb
|
66
63
|
- lib/searchgasm/condition/ends_with.rb
|
67
64
|
- lib/searchgasm/condition/equals.rb
|
68
65
|
- lib/searchgasm/condition/greater_than.rb
|
@@ -71,7 +68,13 @@ extra_rdoc_files:
|
|
71
68
|
- lib/searchgasm/condition/keywords.rb
|
72
69
|
- lib/searchgasm/condition/less_than.rb
|
73
70
|
- lib/searchgasm/condition/less_than_or_equal_to.rb
|
71
|
+
- lib/searchgasm/condition/like.rb
|
74
72
|
- lib/searchgasm/condition/nil.rb
|
73
|
+
- lib/searchgasm/condition/not_begin_with.rb
|
74
|
+
- lib/searchgasm/condition/not_end_with.rb
|
75
|
+
- lib/searchgasm/condition/not_equal.rb
|
76
|
+
- lib/searchgasm/condition/not_have_keywords.rb
|
77
|
+
- lib/searchgasm/condition/not_like.rb
|
75
78
|
- lib/searchgasm/condition/sibling_of.rb
|
76
79
|
- lib/searchgasm/condition/tree.rb
|
77
80
|
- lib/searchgasm/conditions/base.rb
|
@@ -86,6 +89,41 @@ extra_rdoc_files:
|
|
86
89
|
- lib/searchgasm/helpers/control_types/select.rb
|
87
90
|
- lib/searchgasm/helpers/form.rb
|
88
91
|
- lib/searchgasm/helpers/utilities.rb
|
92
|
+
- lib/searchgasm/modifiers/absolute.rb
|
93
|
+
- lib/searchgasm/modifiers/acos.rb
|
94
|
+
- lib/searchgasm/modifiers/asin.rb
|
95
|
+
- lib/searchgasm/modifiers/atan.rb
|
96
|
+
- lib/searchgasm/modifiers/base.rb
|
97
|
+
- lib/searchgasm/modifiers/ceil.rb
|
98
|
+
- lib/searchgasm/modifiers/char_length.rb
|
99
|
+
- lib/searchgasm/modifiers/cos.rb
|
100
|
+
- lib/searchgasm/modifiers/cot.rb
|
101
|
+
- lib/searchgasm/modifiers/day_of_month.rb
|
102
|
+
- lib/searchgasm/modifiers/day_of_week.rb
|
103
|
+
- lib/searchgasm/modifiers/day_of_year.rb
|
104
|
+
- lib/searchgasm/modifiers/degrees.rb
|
105
|
+
- lib/searchgasm/modifiers/exp.rb
|
106
|
+
- lib/searchgasm/modifiers/floor.rb
|
107
|
+
- lib/searchgasm/modifiers/hex.rb
|
108
|
+
- lib/searchgasm/modifiers/hour.rb
|
109
|
+
- lib/searchgasm/modifiers/log.rb
|
110
|
+
- lib/searchgasm/modifiers/log10.rb
|
111
|
+
- lib/searchgasm/modifiers/log2.rb
|
112
|
+
- lib/searchgasm/modifiers/md5.rb
|
113
|
+
- lib/searchgasm/modifiers/microseconds.rb
|
114
|
+
- lib/searchgasm/modifiers/milliseconds.rb
|
115
|
+
- lib/searchgasm/modifiers/minute.rb
|
116
|
+
- lib/searchgasm/modifiers/month.rb
|
117
|
+
- lib/searchgasm/modifiers/octal.rb
|
118
|
+
- lib/searchgasm/modifiers/radians.rb
|
119
|
+
- lib/searchgasm/modifiers/round.rb
|
120
|
+
- lib/searchgasm/modifiers/second.rb
|
121
|
+
- lib/searchgasm/modifiers/sign.rb
|
122
|
+
- lib/searchgasm/modifiers/sin.rb
|
123
|
+
- lib/searchgasm/modifiers/square_root.rb
|
124
|
+
- lib/searchgasm/modifiers/tan.rb
|
125
|
+
- lib/searchgasm/modifiers/week.rb
|
126
|
+
- lib/searchgasm/modifiers/year.rb
|
89
127
|
- lib/searchgasm/search/base.rb
|
90
128
|
- lib/searchgasm/search/conditions.rb
|
91
129
|
- lib/searchgasm/search/ordering.rb
|
@@ -111,10 +149,7 @@ files:
|
|
111
149
|
- lib/searchgasm/condition/begins_with.rb
|
112
150
|
- lib/searchgasm/condition/blank.rb
|
113
151
|
- lib/searchgasm/condition/child_of.rb
|
114
|
-
- lib/searchgasm/condition/contains.rb
|
115
152
|
- lib/searchgasm/condition/descendant_of.rb
|
116
|
-
- lib/searchgasm/condition/does_not_equal.rb
|
117
|
-
- lib/searchgasm/condition/during_evening.rb
|
118
153
|
- lib/searchgasm/condition/ends_with.rb
|
119
154
|
- lib/searchgasm/condition/equals.rb
|
120
155
|
- lib/searchgasm/condition/greater_than.rb
|
@@ -123,7 +158,13 @@ files:
|
|
123
158
|
- lib/searchgasm/condition/keywords.rb
|
124
159
|
- lib/searchgasm/condition/less_than.rb
|
125
160
|
- lib/searchgasm/condition/less_than_or_equal_to.rb
|
161
|
+
- lib/searchgasm/condition/like.rb
|
126
162
|
- lib/searchgasm/condition/nil.rb
|
163
|
+
- lib/searchgasm/condition/not_begin_with.rb
|
164
|
+
- lib/searchgasm/condition/not_end_with.rb
|
165
|
+
- lib/searchgasm/condition/not_equal.rb
|
166
|
+
- lib/searchgasm/condition/not_have_keywords.rb
|
167
|
+
- lib/searchgasm/condition/not_like.rb
|
127
168
|
- lib/searchgasm/condition/sibling_of.rb
|
128
169
|
- lib/searchgasm/condition/tree.rb
|
129
170
|
- lib/searchgasm/conditions/base.rb
|
@@ -138,6 +179,41 @@ files:
|
|
138
179
|
- lib/searchgasm/helpers/control_types/select.rb
|
139
180
|
- lib/searchgasm/helpers/form.rb
|
140
181
|
- lib/searchgasm/helpers/utilities.rb
|
182
|
+
- lib/searchgasm/modifiers/absolute.rb
|
183
|
+
- lib/searchgasm/modifiers/acos.rb
|
184
|
+
- lib/searchgasm/modifiers/asin.rb
|
185
|
+
- lib/searchgasm/modifiers/atan.rb
|
186
|
+
- lib/searchgasm/modifiers/base.rb
|
187
|
+
- lib/searchgasm/modifiers/ceil.rb
|
188
|
+
- lib/searchgasm/modifiers/char_length.rb
|
189
|
+
- lib/searchgasm/modifiers/cos.rb
|
190
|
+
- lib/searchgasm/modifiers/cot.rb
|
191
|
+
- lib/searchgasm/modifiers/day_of_month.rb
|
192
|
+
- lib/searchgasm/modifiers/day_of_week.rb
|
193
|
+
- lib/searchgasm/modifiers/day_of_year.rb
|
194
|
+
- lib/searchgasm/modifiers/degrees.rb
|
195
|
+
- lib/searchgasm/modifiers/exp.rb
|
196
|
+
- lib/searchgasm/modifiers/floor.rb
|
197
|
+
- lib/searchgasm/modifiers/hex.rb
|
198
|
+
- lib/searchgasm/modifiers/hour.rb
|
199
|
+
- lib/searchgasm/modifiers/log.rb
|
200
|
+
- lib/searchgasm/modifiers/log10.rb
|
201
|
+
- lib/searchgasm/modifiers/log2.rb
|
202
|
+
- lib/searchgasm/modifiers/md5.rb
|
203
|
+
- lib/searchgasm/modifiers/microseconds.rb
|
204
|
+
- lib/searchgasm/modifiers/milliseconds.rb
|
205
|
+
- lib/searchgasm/modifiers/minute.rb
|
206
|
+
- lib/searchgasm/modifiers/month.rb
|
207
|
+
- lib/searchgasm/modifiers/octal.rb
|
208
|
+
- lib/searchgasm/modifiers/radians.rb
|
209
|
+
- lib/searchgasm/modifiers/round.rb
|
210
|
+
- lib/searchgasm/modifiers/second.rb
|
211
|
+
- lib/searchgasm/modifiers/sign.rb
|
212
|
+
- lib/searchgasm/modifiers/sin.rb
|
213
|
+
- lib/searchgasm/modifiers/square_root.rb
|
214
|
+
- lib/searchgasm/modifiers/tan.rb
|
215
|
+
- lib/searchgasm/modifiers/week.rb
|
216
|
+
- lib/searchgasm/modifiers/year.rb
|
141
217
|
- lib/searchgasm/search/base.rb
|
142
218
|
- lib/searchgasm/search/conditions.rb
|
143
219
|
- lib/searchgasm/search/ordering.rb
|
@@ -157,6 +233,7 @@ files:
|
|
157
233
|
- test/fixtures/user_groups.yml
|
158
234
|
- test/fixtures/users.yml
|
159
235
|
- test/libs/acts_as_tree.rb
|
236
|
+
- test/libs/ordered_hash.rb
|
160
237
|
- test/libs/rexml_fix.rb
|
161
238
|
- test/test_active_record_associations.rb
|
162
239
|
- test/test_active_record_base.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Searchgasm
|
2
|
-
module Condition
|
3
|
-
class Contains < Base
|
4
|
-
class << self
|
5
|
-
def name_for_column(column)
|
6
|
-
return unless string_column?(column)
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def aliases_for_column(column)
|
11
|
-
["#{column.name}_like", "#{column.name}_has"]
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_conditions(value)
|
16
|
-
["#{quoted_table_name}.#{quoted_column_name} LIKE ?", "%#{value}%"]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Searchgasm
|
2
|
-
module Condition
|
3
|
-
class DuringEvening < Base
|
4
|
-
class << self
|
5
|
-
def name_for_column(column)
|
6
|
-
return unless time_column?(column)
|
7
|
-
super
|
8
|
-
end
|
9
|
-
|
10
|
-
def aliases_for_column(column)
|
11
|
-
column_names = [column.name]
|
12
|
-
column_names << column.name.gsub(/_(at|on)$/, "") if column.name =~ /_(at|on)$/
|
13
|
-
|
14
|
-
aliases = []
|
15
|
-
column_names.each { |column_name| aliases += ["#{column_name}_in_the_evening", "#{column_name}_in_evening", "#{column_name}_evening"] }
|
16
|
-
aliases << "#{column_names.last}_during_evening" if column_names.size > 1
|
17
|
-
aliases
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_conditions(value)
|
22
|
-
evening_start = 17
|
23
|
-
evening_end = 22
|
24
|
-
|
25
|
-
# Need to set up a funcion in each adapter for dealing with dates. Mysql uses HOUR(), sqlite uses strftime(), postgres uses date_part('hour', date). Could potentially be a pain in the ass.
|
26
|
-
# Also, you could set up an hour = condition, and leverage that to do this.
|
27
|
-
if value == true
|
28
|
-
["#{quoted_table_name}.#{quoted_column_name} >= ? AND #{quoted_table_name}.#{quoted_column_name} <= ?", value]
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|