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.
Files changed (74) hide show
  1. data/CHANGELOG.rdoc +8 -0
  2. data/Manifest +42 -3
  3. data/README.rdoc +101 -82
  4. data/TODO.rdoc +1 -3
  5. data/lib/searchgasm/active_record/connection_adapters/mysql_adapter.rb +143 -6
  6. data/lib/searchgasm/active_record/connection_adapters/postgresql_adapter.rb +148 -0
  7. data/lib/searchgasm/active_record/connection_adapters/sqlite_adapter.rb +54 -0
  8. data/lib/searchgasm/condition/base.rb +59 -86
  9. data/lib/searchgasm/condition/begins_with.rb +3 -8
  10. data/lib/searchgasm/condition/blank.rb +5 -5
  11. data/lib/searchgasm/condition/ends_with.rb +3 -8
  12. data/lib/searchgasm/condition/equals.rb +4 -3
  13. data/lib/searchgasm/condition/greater_than.rb +3 -14
  14. data/lib/searchgasm/condition/greater_than_or_equal_to.rb +3 -14
  15. data/lib/searchgasm/condition/keywords.rb +3 -8
  16. data/lib/searchgasm/condition/less_than.rb +3 -14
  17. data/lib/searchgasm/condition/less_than_or_equal_to.rb +3 -14
  18. data/lib/searchgasm/condition/like.rb +15 -0
  19. data/lib/searchgasm/condition/nil.rb +5 -5
  20. data/lib/searchgasm/condition/not_begin_with.rb +17 -0
  21. data/lib/searchgasm/condition/not_end_with.rb +17 -0
  22. data/lib/searchgasm/condition/{does_not_equal.rb → not_equal.rb} +5 -4
  23. data/lib/searchgasm/condition/not_have_keywords.rb +17 -0
  24. data/lib/searchgasm/condition/not_like.rb +17 -0
  25. data/lib/searchgasm/condition/tree.rb +4 -5
  26. data/lib/searchgasm/conditions/base.rb +218 -72
  27. data/lib/searchgasm/modifiers/absolute.rb +15 -0
  28. data/lib/searchgasm/modifiers/acos.rb +11 -0
  29. data/lib/searchgasm/modifiers/asin.rb +11 -0
  30. data/lib/searchgasm/modifiers/atan.rb +11 -0
  31. data/lib/searchgasm/modifiers/base.rb +27 -0
  32. data/lib/searchgasm/modifiers/ceil.rb +15 -0
  33. data/lib/searchgasm/modifiers/char_length.rb +15 -0
  34. data/lib/searchgasm/modifiers/cos.rb +15 -0
  35. data/lib/searchgasm/modifiers/cot.rb +15 -0
  36. data/lib/searchgasm/modifiers/day_of_month.rb +15 -0
  37. data/lib/searchgasm/modifiers/day_of_week.rb +15 -0
  38. data/lib/searchgasm/modifiers/day_of_year.rb +15 -0
  39. data/lib/searchgasm/modifiers/degrees.rb +11 -0
  40. data/lib/searchgasm/modifiers/exp.rb +15 -0
  41. data/lib/searchgasm/modifiers/floor.rb +15 -0
  42. data/lib/searchgasm/modifiers/hex.rb +11 -0
  43. data/lib/searchgasm/modifiers/hour.rb +11 -0
  44. data/lib/searchgasm/modifiers/log.rb +15 -0
  45. data/lib/searchgasm/modifiers/log10.rb +11 -0
  46. data/lib/searchgasm/modifiers/log2.rb +11 -0
  47. data/lib/searchgasm/modifiers/md5.rb +11 -0
  48. data/lib/searchgasm/modifiers/microseconds.rb +11 -0
  49. data/lib/searchgasm/modifiers/milliseconds.rb +11 -0
  50. data/lib/searchgasm/modifiers/minute.rb +15 -0
  51. data/lib/searchgasm/modifiers/month.rb +15 -0
  52. data/lib/searchgasm/modifiers/octal.rb +15 -0
  53. data/lib/searchgasm/modifiers/radians.rb +11 -0
  54. data/lib/searchgasm/modifiers/round.rb +11 -0
  55. data/lib/searchgasm/modifiers/second.rb +15 -0
  56. data/lib/searchgasm/modifiers/sign.rb +11 -0
  57. data/lib/searchgasm/modifiers/sin.rb +11 -0
  58. data/lib/searchgasm/modifiers/square_root.rb +15 -0
  59. data/lib/searchgasm/modifiers/tan.rb +15 -0
  60. data/lib/searchgasm/modifiers/week.rb +11 -0
  61. data/lib/searchgasm/modifiers/year.rb +11 -0
  62. data/lib/searchgasm/shared/utilities.rb +0 -10
  63. data/lib/searchgasm/version.rb +2 -2
  64. data/lib/searchgasm.rb +15 -19
  65. data/searchgasm.gemspec +86 -9
  66. data/test/libs/ordered_hash.rb +9 -0
  67. data/test/test_condition_base.rb +21 -47
  68. data/test/test_condition_types.rb +44 -44
  69. data/test/test_conditions_base.rb +34 -21
  70. data/test/test_helper.rb +1 -0
  71. data/test/test_search_conditions.rb +1 -1
  72. metadata +85 -8
  73. data/lib/searchgasm/condition/contains.rb +0 -20
  74. data/lib/searchgasm/condition/during_evening.rb +0 -32
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Hour < Base
4
+ class << self
5
+ def return_type
6
+ :integer
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Log < Base
4
+ class << self
5
+ def modifier_names
6
+ super + ["ln"]
7
+ end
8
+
9
+ def return_type
10
+ :float
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Log10 < Base
4
+ class << self
5
+ def return_type
6
+ :float
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Log2 < Base
4
+ class << self
5
+ def return_type
6
+ :float
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Md5 < Base
4
+ class << self
5
+ def return_type
6
+ :string
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Microseconds < Base
4
+ class << self
5
+ def return_type
6
+ :integer
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Milliseconds < Base
4
+ class << self
5
+ def return_type
6
+ :integer
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Minute < Base
4
+ class << self
5
+ def modifier_names
6
+ super + ["min"]
7
+ end
8
+
9
+ def return_type
10
+ :integer
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Month < Base
4
+ class << self
5
+ def modifier_names
6
+ super + ["mon"]
7
+ end
8
+
9
+ def return_type
10
+ :integer
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Octal < Base
4
+ class << self
5
+ def modifier_names
6
+ super + ["oct"]
7
+ end
8
+
9
+ def return_type
10
+ :float
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Radians < Base
4
+ class << self
5
+ def return_type
6
+ :float
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Round < Base
4
+ class << self
5
+ def return_type
6
+ :integer
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Second < Base
4
+ class << self
5
+ def modifier_names
6
+ super + ["sec"]
7
+ end
8
+
9
+ def return_type
10
+ :integer
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Sign < Base
4
+ class << self
5
+ def return_type
6
+ :float
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Sin < Base
4
+ class << self
5
+ def return_type
6
+ :float
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class SquareRoot < Base
4
+ class << self
5
+ def modifier_names
6
+ super + ["sqrt", "sq_rt"]
7
+ end
8
+
9
+ def return_type
10
+ :float
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Tan < Base
4
+ class << self
5
+ def modifier_names
6
+ super + ["tangent"]
7
+ end
8
+
9
+ def return_type
10
+ :float
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Week < Base
4
+ class << self
5
+ def return_type
6
+ :integer
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Searchgasm
2
+ module Modifiers
3
+ class Year < Base
4
+ class << self
5
+ def return_type
6
+ :integer
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -45,16 +45,6 @@ module Searchgasm
45
45
 
46
46
  new_joins.compact.uniq
47
47
  end
48
-
49
- # "meaningful" is subjective which is why this is not a core extension like .blank?
50
- def meaningless?(value)
51
- return false if value == false
52
- value.blank?
53
- end
54
-
55
- def meaningful?(value)
56
- !meaningless?
57
- end
58
48
  end
59
49
  end
60
50
  end
@@ -66,8 +66,8 @@ module Searchgasm
66
66
  end
67
67
 
68
68
  MAJOR = 1
69
- MINOR = 2
70
- TINY = 2
69
+ MINOR = 3
70
+ TINY = 0
71
71
 
72
72
  # The current version as a Version instance
73
73
  CURRENT = new(MAJOR, MINOR, TINY)
data/lib/searchgasm.rb CHANGED
@@ -2,6 +2,9 @@ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) ||
2
2
 
3
3
  require "active_record"
4
4
  require "active_record/version"
5
+ require "active_record/connection_adapters/mysql_adapter"
6
+ require "active_record/connection_adapters/postgresql_adapter"
7
+ require "active_record/connection_adapters/sqlite_adapter"
5
8
  require "active_support"
6
9
 
7
10
  # Core Ext
@@ -18,6 +21,9 @@ require "searchgasm/config"
18
21
  # ActiveRecord
19
22
  require "searchgasm/active_record/base"
20
23
  require "searchgasm/active_record/associations"
24
+ require "searchgasm/active_record/connection_adapters/mysql_adapter"
25
+ require "searchgasm/active_record/connection_adapters/postgresql_adapter"
26
+ require "searchgasm/active_record/connection_adapters/sqlite_adapter"
21
27
 
22
28
  # Search
23
29
  require "searchgasm/search/ordering"
@@ -33,23 +39,14 @@ require "searchgasm/conditions/base"
33
39
 
34
40
  # Condition
35
41
  require "searchgasm/condition/base"
36
- require "searchgasm/condition/begins_with"
37
- require "searchgasm/condition/blank"
38
- require "searchgasm/condition/contains"
39
- require "searchgasm/condition/does_not_equal"
40
- require "searchgasm/condition/ends_with"
41
- require "searchgasm/condition/equals"
42
- require "searchgasm/condition/greater_than"
43
- require "searchgasm/condition/greater_than_or_equal_to"
44
- require "searchgasm/condition/keywords"
45
- require "searchgasm/condition/less_than"
46
- require "searchgasm/condition/less_than_or_equal_to"
47
- require "searchgasm/condition/nil"
48
42
  require "searchgasm/condition/tree"
49
- require "searchgasm/condition/child_of"
50
- require "searchgasm/condition/descendant_of"
51
- require "searchgasm/condition/inclusive_descendant_of"
52
- require "searchgasm/condition/sibling_of"
43
+ SEARCHGASM_CONDITIONS = [:begins_with, :blank, :child_of, :descendant_of, :ends_with, :equals, :greater_than, :greater_than_or_equal_to, :inclusive_descendant_of, :like, :nil, :not_begin_with, :not_end_with, :not_equal, :not_have_keywords, :keywords, :less_than, :less_than_or_equal_to, :sibling_of]
44
+ SEARCHGASM_CONDITIONS.each { |condition| require "searchgasm/condition/#{condition}" }
45
+
46
+ # Modifiers
47
+ require "searchgasm/modifiers/base"
48
+ SEARCHGASM_MODIFIERS = [:day_of_month, :day_of_week, :day_of_year, :hour, :microseconds, :milliseconds, :minute, :month, :second, :week, :year]
49
+ SEARCHGASM_MODIFIERS.each { |modifier| require "searchgasm/modifiers/#{modifier}" }
53
50
 
54
51
  # Helpers
55
52
  require "searchgasm/helpers/utilities"
@@ -78,9 +75,8 @@ module Searchgasm
78
75
  include Protection
79
76
  end
80
77
 
81
- [:begins_with, :blank, :child_of, :contains, :descendant_of, :does_not_equal, :ends_with, :equals, :greater_than, :greater_than_or_equal_to, :inclusive_descendant_of, :nil, :keywords, :less_than, :less_than_or_equal_to, :sibling_of].each do |condition|
82
- Base.register_condition("Searchgasm::Condition::#{condition.to_s.camelize}".constantize)
83
- end
78
+ SEARCHGASM_CONDITIONS.each { |condition| Base.register_condition("Searchgasm::Condition::#{condition.to_s.camelize}".constantize) }
79
+ SEARCHGASM_MODIFIERS.each { |modifier| Base.register_modifier("Searchgasm::Modifiers::#{modifier.to_s.camelize}".constantize) }
84
80
  end
85
81
 
86
82
  # The namespace I put all cached search classes.
data/searchgasm.gemspec CHANGED
@@ -1,18 +1,18 @@
1
1
 
2
- # Gem::Specification for Searchgasm-1.2.2
2
+ # Gem::Specification for Searchgasm-1.3.0
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: searchgasm
7
7
  version: !ruby/object:Gem::Version
8
- version: 1.2.2
8
+ version: 1.3.0
9
9
  platform: ruby
10
10
  authors:
11
11
  - Ben Johnson of Binary Logic
12
12
  autorequire:
13
13
  bindir: bin
14
14
 
15
- date: 2008-09-29 00:00:00 -04:00
15
+ date: 2008-10-02 00:00:00 -04:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -62,10 +62,7 @@ extra_rdoc_files:
62
62
  - lib/searchgasm/condition/begins_with.rb
63
63
  - lib/searchgasm/condition/blank.rb
64
64
  - lib/searchgasm/condition/child_of.rb
65
- - lib/searchgasm/condition/contains.rb
66
65
  - lib/searchgasm/condition/descendant_of.rb
67
- - lib/searchgasm/condition/does_not_equal.rb
68
- - lib/searchgasm/condition/during_evening.rb
69
66
  - lib/searchgasm/condition/ends_with.rb
70
67
  - lib/searchgasm/condition/equals.rb
71
68
  - lib/searchgasm/condition/greater_than.rb
@@ -74,7 +71,13 @@ extra_rdoc_files:
74
71
  - lib/searchgasm/condition/keywords.rb
75
72
  - lib/searchgasm/condition/less_than.rb
76
73
  - lib/searchgasm/condition/less_than_or_equal_to.rb
74
+ - lib/searchgasm/condition/like.rb
77
75
  - lib/searchgasm/condition/nil.rb
76
+ - lib/searchgasm/condition/not_begin_with.rb
77
+ - lib/searchgasm/condition/not_end_with.rb
78
+ - lib/searchgasm/condition/not_equal.rb
79
+ - lib/searchgasm/condition/not_have_keywords.rb
80
+ - lib/searchgasm/condition/not_like.rb
78
81
  - lib/searchgasm/condition/sibling_of.rb
79
82
  - lib/searchgasm/condition/tree.rb
80
83
  - lib/searchgasm/conditions/base.rb
@@ -89,6 +92,41 @@ extra_rdoc_files:
89
92
  - lib/searchgasm/helpers/control_types/select.rb
90
93
  - lib/searchgasm/helpers/form.rb
91
94
  - lib/searchgasm/helpers/utilities.rb
95
+ - lib/searchgasm/modifiers/absolute.rb
96
+ - lib/searchgasm/modifiers/acos.rb
97
+ - lib/searchgasm/modifiers/asin.rb
98
+ - lib/searchgasm/modifiers/atan.rb
99
+ - lib/searchgasm/modifiers/base.rb
100
+ - lib/searchgasm/modifiers/ceil.rb
101
+ - lib/searchgasm/modifiers/char_length.rb
102
+ - lib/searchgasm/modifiers/cos.rb
103
+ - lib/searchgasm/modifiers/cot.rb
104
+ - lib/searchgasm/modifiers/day_of_month.rb
105
+ - lib/searchgasm/modifiers/day_of_week.rb
106
+ - lib/searchgasm/modifiers/day_of_year.rb
107
+ - lib/searchgasm/modifiers/degrees.rb
108
+ - lib/searchgasm/modifiers/exp.rb
109
+ - lib/searchgasm/modifiers/floor.rb
110
+ - lib/searchgasm/modifiers/hex.rb
111
+ - lib/searchgasm/modifiers/hour.rb
112
+ - lib/searchgasm/modifiers/log.rb
113
+ - lib/searchgasm/modifiers/log10.rb
114
+ - lib/searchgasm/modifiers/log2.rb
115
+ - lib/searchgasm/modifiers/md5.rb
116
+ - lib/searchgasm/modifiers/microseconds.rb
117
+ - lib/searchgasm/modifiers/milliseconds.rb
118
+ - lib/searchgasm/modifiers/minute.rb
119
+ - lib/searchgasm/modifiers/month.rb
120
+ - lib/searchgasm/modifiers/octal.rb
121
+ - lib/searchgasm/modifiers/radians.rb
122
+ - lib/searchgasm/modifiers/round.rb
123
+ - lib/searchgasm/modifiers/second.rb
124
+ - lib/searchgasm/modifiers/sign.rb
125
+ - lib/searchgasm/modifiers/sin.rb
126
+ - lib/searchgasm/modifiers/square_root.rb
127
+ - lib/searchgasm/modifiers/tan.rb
128
+ - lib/searchgasm/modifiers/week.rb
129
+ - lib/searchgasm/modifiers/year.rb
92
130
  - lib/searchgasm/search/base.rb
93
131
  - lib/searchgasm/search/conditions.rb
94
132
  - lib/searchgasm/search/ordering.rb
@@ -114,10 +152,7 @@ files:
114
152
  - lib/searchgasm/condition/begins_with.rb
115
153
  - lib/searchgasm/condition/blank.rb
116
154
  - lib/searchgasm/condition/child_of.rb
117
- - lib/searchgasm/condition/contains.rb
118
155
  - lib/searchgasm/condition/descendant_of.rb
119
- - lib/searchgasm/condition/does_not_equal.rb
120
- - lib/searchgasm/condition/during_evening.rb
121
156
  - lib/searchgasm/condition/ends_with.rb
122
157
  - lib/searchgasm/condition/equals.rb
123
158
  - lib/searchgasm/condition/greater_than.rb
@@ -126,7 +161,13 @@ files:
126
161
  - lib/searchgasm/condition/keywords.rb
127
162
  - lib/searchgasm/condition/less_than.rb
128
163
  - lib/searchgasm/condition/less_than_or_equal_to.rb
164
+ - lib/searchgasm/condition/like.rb
129
165
  - lib/searchgasm/condition/nil.rb
166
+ - lib/searchgasm/condition/not_begin_with.rb
167
+ - lib/searchgasm/condition/not_end_with.rb
168
+ - lib/searchgasm/condition/not_equal.rb
169
+ - lib/searchgasm/condition/not_have_keywords.rb
170
+ - lib/searchgasm/condition/not_like.rb
130
171
  - lib/searchgasm/condition/sibling_of.rb
131
172
  - lib/searchgasm/condition/tree.rb
132
173
  - lib/searchgasm/conditions/base.rb
@@ -141,6 +182,41 @@ files:
141
182
  - lib/searchgasm/helpers/control_types/select.rb
142
183
  - lib/searchgasm/helpers/form.rb
143
184
  - lib/searchgasm/helpers/utilities.rb
185
+ - lib/searchgasm/modifiers/absolute.rb
186
+ - lib/searchgasm/modifiers/acos.rb
187
+ - lib/searchgasm/modifiers/asin.rb
188
+ - lib/searchgasm/modifiers/atan.rb
189
+ - lib/searchgasm/modifiers/base.rb
190
+ - lib/searchgasm/modifiers/ceil.rb
191
+ - lib/searchgasm/modifiers/char_length.rb
192
+ - lib/searchgasm/modifiers/cos.rb
193
+ - lib/searchgasm/modifiers/cot.rb
194
+ - lib/searchgasm/modifiers/day_of_month.rb
195
+ - lib/searchgasm/modifiers/day_of_week.rb
196
+ - lib/searchgasm/modifiers/day_of_year.rb
197
+ - lib/searchgasm/modifiers/degrees.rb
198
+ - lib/searchgasm/modifiers/exp.rb
199
+ - lib/searchgasm/modifiers/floor.rb
200
+ - lib/searchgasm/modifiers/hex.rb
201
+ - lib/searchgasm/modifiers/hour.rb
202
+ - lib/searchgasm/modifiers/log.rb
203
+ - lib/searchgasm/modifiers/log10.rb
204
+ - lib/searchgasm/modifiers/log2.rb
205
+ - lib/searchgasm/modifiers/md5.rb
206
+ - lib/searchgasm/modifiers/microseconds.rb
207
+ - lib/searchgasm/modifiers/milliseconds.rb
208
+ - lib/searchgasm/modifiers/minute.rb
209
+ - lib/searchgasm/modifiers/month.rb
210
+ - lib/searchgasm/modifiers/octal.rb
211
+ - lib/searchgasm/modifiers/radians.rb
212
+ - lib/searchgasm/modifiers/round.rb
213
+ - lib/searchgasm/modifiers/second.rb
214
+ - lib/searchgasm/modifiers/sign.rb
215
+ - lib/searchgasm/modifiers/sin.rb
216
+ - lib/searchgasm/modifiers/square_root.rb
217
+ - lib/searchgasm/modifiers/tan.rb
218
+ - lib/searchgasm/modifiers/week.rb
219
+ - lib/searchgasm/modifiers/year.rb
144
220
  - lib/searchgasm/search/base.rb
145
221
  - lib/searchgasm/search/conditions.rb
146
222
  - lib/searchgasm/search/ordering.rb
@@ -160,6 +236,7 @@ files:
160
236
  - test/fixtures/user_groups.yml
161
237
  - test/fixtures/users.yml
162
238
  - test/libs/acts_as_tree.rb
239
+ - test/libs/ordered_hash.rb
163
240
  - test/libs/rexml_fix.rb
164
241
  - test/test_active_record_associations.rb
165
242
  - test/test_active_record_base.rb
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ def each(&block)
3
+ sorted_keys = keys.sort { |a, b| a.to_s <=> b.to_s }
4
+ sorted_keys.each do |key|
5
+ yield key, self[key]
6
+ end
7
+ self
8
+ end
9
+ end
@@ -1,53 +1,38 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
3
  class TestConditionBase < Test::Unit::TestCase
4
- def test_condition_name
5
- assert_equal "equals", Searchgasm::Condition::Equals.condition_name
6
- assert_equal "keywords", Searchgasm::Condition::Keywords.condition_name
7
- assert_equal "greater_than_or_equal_to", Searchgasm::Condition::GreaterThanOrEqualTo.condition_name
4
+ def test_condition_type_name
5
+ assert_equal "equals", Searchgasm::Condition::Equals.condition_type_name
6
+ assert_equal "keywords", Searchgasm::Condition::Keywords.condition_type_name
7
+ assert_equal "greater_than_or_equal_to", Searchgasm::Condition::GreaterThanOrEqualTo.condition_type_name
8
8
  end
9
9
 
10
- def test_name_for_column
11
- assert_equal "id_equals", Searchgasm::Condition::Equals.name_for_column(Account.columns_hash["id"])
12
- assert_equal nil, Searchgasm::Condition::Keywords.name_for_column(Account.columns_hash["id"])
10
+ def test_ignore_meaningless_value?
11
+ assert !Searchgasm::Condition::Equals.ignore_meaningless_value?
12
+ assert Searchgasm::Condition::Keywords.ignore_meaningless_value?
13
+ assert !Searchgasm::Condition::NotEqual.ignore_meaningless_value?
13
14
  end
14
15
 
15
- def test_ignore_meaningless?
16
- assert !Searchgasm::Condition::Equals.ignore_meaningless?
17
- assert Searchgasm::Condition::Keywords.ignore_meaningless?
18
- assert !Searchgasm::Condition::DoesNotEqual.ignore_meaningless?
19
- end
20
-
21
- def test_type_cast_sql_type
22
- assert_equal nil, Searchgasm::Condition::Equals.type_cast_sql_type
23
- assert_equal nil, Searchgasm::Condition::Keywords.type_cast_sql_type
24
- assert_equal "boolean", Searchgasm::Condition::Nil.type_cast_sql_type
25
- assert_equal "boolean", Searchgasm::Condition::Blank.type_cast_sql_type
26
- assert_equal nil, Searchgasm::Condition::GreaterThan.type_cast_sql_type
27
- end
28
-
29
- def test_string_column
30
- assert !Searchgasm::Condition::Base.string_column?(Account.columns_hash["id"])
31
- assert Searchgasm::Condition::Base.string_column?(Account.columns_hash["name"])
32
- assert !Searchgasm::Condition::Base.string_column?(Account.columns_hash["active"])
33
- assert Searchgasm::Condition::Base.string_column?(User.columns_hash["bio"])
34
- end
35
-
36
- def test_comparable_column
37
- assert Searchgasm::Condition::Base.comparable_column?(Account.columns_hash["id"])
38
- assert !Searchgasm::Condition::Base.comparable_column?(Account.columns_hash["name"])
39
- assert !Searchgasm::Condition::Base.comparable_column?(Account.columns_hash["active"])
40
- assert !Searchgasm::Condition::Base.comparable_column?(User.columns_hash["bio"])
41
- assert Searchgasm::Condition::Base.comparable_column?(Order.columns_hash["total"])
16
+ def test_value_type
17
+ assert_equal nil, Searchgasm::Condition::Equals.value_type
18
+ assert_equal nil, Searchgasm::Condition::Keywords.value_type
19
+ assert_equal :boolean, Searchgasm::Condition::Nil.value_type
20
+ assert_equal :boolean, Searchgasm::Condition::Blank.value_type
21
+ assert_equal nil, Searchgasm::Condition::GreaterThan.value_type
42
22
  end
43
23
 
44
24
  def test_initialize
45
25
  condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
46
26
  assert_equal condition.klass, Account
47
- assert_equal condition.column, Account.columns_hash["name"]
27
+ assert_equal Account.columns_hash["name"], condition.column
48
28
 
49
29
  condition = Searchgasm::Condition::GreaterThan.new(Account, "id")
50
- assert_equal condition.column, Account.columns_hash["id"]
30
+ assert_equal Account.columns_hash["id"], condition.column
31
+
32
+ condition = Searchgasm::Condition::GreaterThan.new(Account, "id", :string, "some sql")
33
+ assert_equal Account.columns_hash["id"], condition.column
34
+ condition.value = "awesome"
35
+ assert_equal ["some sql > ?", "awesome"], condition.sanitize
51
36
  end
52
37
 
53
38
  def test_explicitly_set_value
@@ -57,17 +42,6 @@ class TestConditionBase < Test::Unit::TestCase
57
42
  assert condition.explicitly_set_value?
58
43
  end
59
44
 
60
- def test_name
61
- condition = Searchgasm::Condition::Keywords.new(Account, Account.columns_hash["name"])
62
- assert_equal "name_keywords", condition.name
63
-
64
- condition = Searchgasm::Condition::DescendantOf.new(User)
65
- assert_equal "descendant_of", condition.name
66
-
67
- condition = Searchgasm::Condition::DescendantOf.new(Account)
68
- assert_equal nil, condition.name
69
- end
70
-
71
45
  def test_sanitize
72
46
  # This is tested thoroughly in test_condition_types
73
47
  end