de 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/README +28 -0
- data/Rakefile +1 -0
- data/de.gemspec +26 -0
- data/lib/de/boolean/operand.rb +46 -0
- data/lib/de/boolean/operator.rb +134 -0
- data/lib/de/boolean.rb +2 -0
- data/lib/de/de.rb +210 -0
- data/lib/de/error.rb +6 -0
- data/lib/de/sunspot_solr/operand.rb +273 -0
- data/lib/de/sunspot_solr/operator.rb +131 -0
- data/lib/de/sunspot_solr/search.rb +179 -0
- data/lib/de/sunspot_solr.rb +9 -0
- data/lib/de/symmetric_operator.rb +31 -0
- data/lib/de/version.rb +3 -0
- data/lib/de.rb +3 -0
- data/test/de_boolean_and_test.rb +51 -0
- data/test/de_boolean_not_test.rb +39 -0
- data/test/de_boolean_operand_test.rb +30 -0
- data/test/de_boolean_operator_test.rb +34 -0
- data/test/de_boolean_or_test.rb +51 -0
- data/test/de_expression_test.rb +35 -0
- data/test/de_operand_test.rb +29 -0
- data/test/de_operator_test.rb +48 -0
- data/test/de_sunspot_solr_and_test.rb +113 -0
- data/test/de_sunspot_solr_not_test.rb +49 -0
- data/test/de_sunspot_solr_or_test.rb +61 -0
- data/test/de_sunspot_solr_search_test.rb +251 -0
- data/test/de_sunspot_solr_sunspot_operand_test.rb +509 -0
- metadata +145 -0
@@ -0,0 +1,509 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'de'
|
3
|
+
require 'de/sunspot_solr'
|
4
|
+
|
5
|
+
class DeSunspotSolrSunspotOperandTest < Test::Unit::TestCase
|
6
|
+
include De::SunspotSolr
|
7
|
+
|
8
|
+
def test_constructor
|
9
|
+
assert_nothing_raised(De::Error::AbstractClassObjectCreationError) { SunspotOperand.new('some name', :client_id, :equal_to, 44) }
|
10
|
+
|
11
|
+
operand = SunspotOperand.new('some name', :client_id, :equal_to, 44)
|
12
|
+
assert_equal('some name', operand.name)
|
13
|
+
assert_equal('client_id', operand.content)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_add
|
17
|
+
operand = SunspotOperand.new('some name', :client_id, :equal_to, 44)
|
18
|
+
operand2 = SunspotOperand.new('some name 2', :client_id, :eaual_to, 42)
|
19
|
+
|
20
|
+
assert_raise(De::Error::TypeError) { operand << operand2 }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_equal
|
24
|
+
operand = SunspotOperand.new('some name', :client_id, :equal_to, 44)
|
25
|
+
operand2 = SunspotOperand.new('some name', :client_id, :equal_to, 44)
|
26
|
+
operand3 = SunspotOperand.new('some name 2', :client_id, :equal_to, 44)
|
27
|
+
operand4 = SunspotOperand.new('some name', :client_id, :equal_to, 42)
|
28
|
+
operand5 = SunspotOperand.new('some name', :products_group_id, :equal_to, 44)
|
29
|
+
operand6 = SunspotOperand.new('some name', :client_id, :less_than, 44)
|
30
|
+
|
31
|
+
assert(operand == operand2)
|
32
|
+
assert(operand2 == operand)
|
33
|
+
assert(operand == operand3)
|
34
|
+
assert(operand != operand4)
|
35
|
+
assert(operand != operand5)
|
36
|
+
assert(operand != operand6)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_valid?
|
40
|
+
operand = SunspotOperand.new('some name', :client_id, :not_existent_operand, 44)
|
41
|
+
assert_equal(false, operand.valid?, 'Operand with unknown @operand field should be invalid')
|
42
|
+
|
43
|
+
operand = SunspotOperand.new('some name', :client_id, :equal_to, 44)
|
44
|
+
assert_equal(false, operand.valid?, 'Operand without (valid) root should be invalid')
|
45
|
+
|
46
|
+
operand2 = SunspotOperand.new('some name 2', :title, :equal_to, 44)
|
47
|
+
search = Search.new('search_product', 'Product', {
|
48
|
+
:properties => {
|
49
|
+
:client_id => {:type => :integer, :dynamic => false},
|
50
|
+
:name => {:type => :string, :dynamic => false},
|
51
|
+
:price => {:type => :integer, :dynamic => true}
|
52
|
+
},
|
53
|
+
:dynamics => {:integer => :int_params, :string => :string_params, :time => :time_params, :text => :string_params}
|
54
|
+
})
|
55
|
+
search << operand
|
56
|
+
search << operand2
|
57
|
+
assert_equal(false, operand2.valid?, 'Operand not registered in root should be invalid')
|
58
|
+
assert_equal(true, operand.valid?, 'Operand registered in root should be valid')
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_evaluate_integer
|
63
|
+
search = Search.new('search_product', 'Product', {
|
64
|
+
:properties => {
|
65
|
+
:client_id => {:type => :integer, :dynamic => false},
|
66
|
+
:group_id => {:type => :integer, :dynamic => true},
|
67
|
+
},
|
68
|
+
:dynamics => {:integer => :int_params}
|
69
|
+
})
|
70
|
+
|
71
|
+
op1 = SunspotOperand.new('op1', :client_id, :equal_to, 44)
|
72
|
+
search << op1
|
73
|
+
assert_equal("with(:client_id).equal_to(44)",op1.evaluate.gsub(/\s+/, ' '))
|
74
|
+
|
75
|
+
op2 = SunspotOperand.new('op2', :client_id, :between, 42..44)
|
76
|
+
search << op2
|
77
|
+
assert_equal("with(:client_id).between(42..44)",op2.evaluate.gsub(/\s+/, ' '))
|
78
|
+
|
79
|
+
op3 = SunspotOperand.new('op3', :client_id, :any_of, [42, 43, 44])
|
80
|
+
search << op3
|
81
|
+
assert_equal("with(:client_id).any_of([42,43,44])",op3.evaluate.gsub(/\s+/, ' '))
|
82
|
+
|
83
|
+
op4 = SunspotOperand.new('op4', :group_id, :greater_than, 188)
|
84
|
+
search << op4
|
85
|
+
assert_equal("dynamic(:int_params) do with(:group_id).greater_than(188) end",op4.evaluate.gsub(/\s+/, ' '))
|
86
|
+
|
87
|
+
op5 = SunspotOperand.new('op5', :group_id, :between, 200..250)
|
88
|
+
search << op5
|
89
|
+
assert_equal("dynamic(:int_params) do with(:group_id).between(200..250) end",op5.evaluate.gsub(/\s+/, ' '))
|
90
|
+
|
91
|
+
op6 = SunspotOperand.new('op6', :group_id, :any_of, [42, 43, 44])
|
92
|
+
search << op6
|
93
|
+
assert_equal("dynamic(:int_params) do with(:group_id).any_of([42,43,44]) end", op6.evaluate.gsub(/\s+/, ' '))
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_evaluate_float
|
97
|
+
search = Search.new('search_product', 'Product', {
|
98
|
+
:properties => {
|
99
|
+
:client_id => {:type => :float, :dynamic => false},
|
100
|
+
:group_id => {:type => :float, :dynamic => true},
|
101
|
+
},
|
102
|
+
:dynamics => {:float => :float_params}
|
103
|
+
})
|
104
|
+
|
105
|
+
op1 = SunspotOperand.new('op1', :client_id, :less_than, 44.0)
|
106
|
+
search << op1
|
107
|
+
assert_equal("with(:client_id).less_than(44.0)",op1.evaluate.gsub(/\s+/, ' '))
|
108
|
+
|
109
|
+
op2 = SunspotOperand.new('op2', :client_id, :between, 42.0..44.0)
|
110
|
+
search << op2
|
111
|
+
assert_equal("with(:client_id).between(42.0..44.0)",op2.evaluate.gsub(/\s+/, ' '))
|
112
|
+
|
113
|
+
op3 = SunspotOperand.new('op3', :client_id, :any_of, [42.0, 43.0, 44.0])
|
114
|
+
search << op3
|
115
|
+
assert_equal("with(:client_id).any_of([42.0,43.0,44.0])",op3.evaluate.gsub(/\s+/, ' '))
|
116
|
+
|
117
|
+
op4 = SunspotOperand.new('op4', :group_id, :greater_than, 188.0)
|
118
|
+
search << op4
|
119
|
+
assert_equal("dynamic(:float_params) do with(:group_id).greater_than(188.0) end",op4.evaluate.gsub(/\s+/, ' '))
|
120
|
+
|
121
|
+
op5 = SunspotOperand.new('op5', :group_id, :between, 200..250)
|
122
|
+
search << op5
|
123
|
+
assert_equal("dynamic(:float_params) do with(:group_id).between(200.0..250.0) end",op5.evaluate.gsub(/\s+/, ' '))
|
124
|
+
|
125
|
+
op6 = SunspotOperand.new('op6', :group_id, :any_of, [42, 43.4, 44])
|
126
|
+
search << op6
|
127
|
+
assert_equal("dynamic(:float_params) do with(:group_id).any_of([42.0,43.4,44.0]) end", op6.evaluate.gsub(/\s+/, ' '))
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_evaluate_time
|
131
|
+
search = Search.new('search_product', 'Product', {
|
132
|
+
:properties => {
|
133
|
+
:start_date => {:type => :time, :dynamic => false},
|
134
|
+
:end_date => {:type => :time, :dynamic => true},
|
135
|
+
},
|
136
|
+
:dynamics => {:time => :time_params}
|
137
|
+
})
|
138
|
+
|
139
|
+
now = Time.now
|
140
|
+
tomorrow = now + 1.day
|
141
|
+
|
142
|
+
op1 = SunspotOperand.new('op1', :start_date, :equal_to, now)
|
143
|
+
search << op1
|
144
|
+
assert_equal("with(:start_date).equal_to('#{now.to_s(:db)}')",op1.evaluate.gsub(/\s+/, ' '))
|
145
|
+
|
146
|
+
op2 = SunspotOperand.new('op2', :start_date, :between, now..tomorrow)
|
147
|
+
search << op2
|
148
|
+
assert_equal("with(:start_date).between('#{now.to_s(:db)}'..'#{tomorrow.to_s(:db)}')",op2.evaluate.gsub(/\s+/, ' '))
|
149
|
+
|
150
|
+
op3 = SunspotOperand.new('op3', :start_date, :any_of, [now, tomorrow])
|
151
|
+
search << op3
|
152
|
+
assert_equal("with(:start_date).any_of(['#{now.to_s(:db)}','#{tomorrow.to_s(:db)}'])",op3.evaluate.gsub(/\s+/, ' '))
|
153
|
+
|
154
|
+
op4 = SunspotOperand.new('op4', :end_date, :greater_than, now)
|
155
|
+
search << op4
|
156
|
+
assert_equal("dynamic(:time_params) do with(:end_date).greater_than('#{now.to_s(:db)}') end",op4.evaluate.gsub(/\s+/, ' '))
|
157
|
+
|
158
|
+
op5 = SunspotOperand.new('op5', :end_date, :between, now..tomorrow)
|
159
|
+
search << op5
|
160
|
+
assert_equal("dynamic(:time_params) do with(:end_date).between('#{now.to_s(:db)}'..'#{tomorrow.to_s(:db)}') end",op5.evaluate.gsub(/\s+/, ' '))
|
161
|
+
|
162
|
+
op6 = SunspotOperand.new('op6', :end_date, :any_of, [now, tomorrow])
|
163
|
+
search << op6
|
164
|
+
assert_equal("dynamic(:time_params) do with(:end_date).any_of(['#{now.to_s(:db)}','#{tomorrow.to_s(:db)}']) end", op6.evaluate.gsub(/\s+/, ' '))
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_evaluate_string
|
168
|
+
search = Search.new('search_product', 'Product', {
|
169
|
+
:properties => {
|
170
|
+
:name => {:type => :string, :dynamic => false},
|
171
|
+
:title => {:type => :string, :dynamic => true},
|
172
|
+
},
|
173
|
+
:dynamics => {:string => :string_params}
|
174
|
+
})
|
175
|
+
|
176
|
+
name = 'some name'
|
177
|
+
name2 = 'another name'
|
178
|
+
|
179
|
+
op1 = SunspotOperand.new('op1', :name, :equal_to, name)
|
180
|
+
search << op1
|
181
|
+
assert_equal("with(:name).equal_to('#{name}')",op1.evaluate.gsub(/\s+/, ' '))
|
182
|
+
|
183
|
+
op2 = SunspotOperand.new('op2', :name, :between, 'AB'..'AC')
|
184
|
+
search << op2
|
185
|
+
assert_equal("with(:name).between('AB'..'AC')",op2.evaluate.gsub(/\s+/, ' '))
|
186
|
+
|
187
|
+
op3 = SunspotOperand.new('op3', :name, :any_of, [name, name2])
|
188
|
+
search << op3
|
189
|
+
assert_equal("with(:name).any_of(['#{name}','#{name2}'])",op3.evaluate.gsub(/\s+/, ' '))
|
190
|
+
|
191
|
+
op4 = SunspotOperand.new('op4', :title, :less_than, name)
|
192
|
+
search << op4
|
193
|
+
assert_equal("dynamic(:string_params) do with(:title).less_than('#{name}') end",op4.evaluate.gsub(/\s+/, ' '))
|
194
|
+
|
195
|
+
op5 = SunspotOperand.new('op5', :title, :between, 'AB'..'AC')
|
196
|
+
search << op5
|
197
|
+
assert_equal("dynamic(:string_params) do with(:title).between('AB'..'AC') end",op5.evaluate.gsub(/\s+/, ' '))
|
198
|
+
|
199
|
+
op6 = SunspotOperand.new('op6', :title, :any_of, [name, name2])
|
200
|
+
search << op6
|
201
|
+
assert_equal("dynamic(:string_params) do with(:title).any_of(['#{name}','#{name2}']) end", op6.evaluate.gsub(/\s+/, ' '))
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
def test_evaluate_text
|
206
|
+
search = Search.new('search_product', 'Product', {
|
207
|
+
:properties => {
|
208
|
+
:name => {:type => :text, :dynamic => false},
|
209
|
+
:title => {:type => :text, :dynamic => true},
|
210
|
+
},
|
211
|
+
:dynamics => {:text => :string_params}
|
212
|
+
})
|
213
|
+
|
214
|
+
name = 'some name'
|
215
|
+
name2 = 'another name'
|
216
|
+
|
217
|
+
op1 = SunspotOperand.new('op1', :name, :equal_to, name)
|
218
|
+
search << op1
|
219
|
+
assert_equal("with(:name).equal_to('#{name}')",op1.evaluate.gsub(/\s+/, ' '))
|
220
|
+
|
221
|
+
op2 = SunspotOperand.new('op2', :name, :between, 'AB'..'AC')
|
222
|
+
search << op2
|
223
|
+
assert_equal("with(:name).between('AB'..'AC')",op2.evaluate.gsub(/\s+/, ' '))
|
224
|
+
|
225
|
+
op3 = SunspotOperand.new('op3', :name, :any_of, [name, name2])
|
226
|
+
search << op3
|
227
|
+
assert_equal("with(:name).any_of(['#{name}','#{name2}'])",op3.evaluate.gsub(/\s+/, ' '))
|
228
|
+
|
229
|
+
op4 = SunspotOperand.new('op4', :title, :less_than, name)
|
230
|
+
search << op4
|
231
|
+
assert_equal("dynamic(:string_params) do with(:title).less_than('#{name}') end",op4.evaluate.gsub(/\s+/, ' '))
|
232
|
+
|
233
|
+
op5 = SunspotOperand.new('op5', :title, :between, 'AB'..'AC')
|
234
|
+
search << op5
|
235
|
+
assert_equal("dynamic(:string_params) do with(:title).between('AB'..'AC') end",op5.evaluate.gsub(/\s+/, ' '))
|
236
|
+
|
237
|
+
op6 = SunspotOperand.new('op6', :title, :any_of, [name, name2])
|
238
|
+
search << op6
|
239
|
+
assert_equal("dynamic(:string_params) do with(:title).any_of(['#{name}','#{name2}']) end", op6.evaluate.gsub(/\s+/, ' '))
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_interval_operand
|
243
|
+
search = Search.new('search_product', 'Product', {
|
244
|
+
:properties => {
|
245
|
+
:start_date => {:type => :time, :dynamic => false},
|
246
|
+
:name => {:type => :string, :dynamic => false}
|
247
|
+
},
|
248
|
+
:dynamics => {:time => :time_params}
|
249
|
+
})
|
250
|
+
|
251
|
+
now = Time.now
|
252
|
+
|
253
|
+
op1 = IntervalSunspotOperand.new('op1', :start_date, :equal_to, 2)
|
254
|
+
search << op1
|
255
|
+
assert_equal("with(:start_date).equal_to('#{(now + 2.days).to_s(:db)}')", op1.evaluate.gsub(/\s+/, ' '))
|
256
|
+
|
257
|
+
op2 = IntervalSunspotOperand.new('op2', :start_date, :between, 1..2)
|
258
|
+
search << op2
|
259
|
+
assert_equal("with(:start_date).between('#{(now + 1.day).to_s(:db)}'..'#{(now + 2.days).to_s(:db)}')",op2.evaluate.gsub(/\s+/, ' '))
|
260
|
+
|
261
|
+
op3 = IntervalSunspotOperand.new('op3', :start_date, :any_of, [1,2])
|
262
|
+
search << op3
|
263
|
+
assert_equal("with(:start_date).any_of(['#{(now + 1.day).to_s(:db)}','#{(now + 2.days).to_s(:db)}'])",op3.evaluate.gsub(/\s+/, ' '))
|
264
|
+
|
265
|
+
op4 = IntervalSunspotOperand.new('op4', :name, :less_than, 'test')
|
266
|
+
assert(!op4.valid?)
|
267
|
+
|
268
|
+
op5 = IntervalSunspotOperand.new('op5', :start_date, :between, 1...3)
|
269
|
+
search << op5
|
270
|
+
assert_equal("with(:start_date).between('#{(now + 1.day).to_s(:db)}'...'#{(now + 3.days).to_s(:db)}')",op5.evaluate.gsub(/\s+/, ' '))
|
271
|
+
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_EqualTo
|
275
|
+
search = Search.new('search_product', 'Product', {
|
276
|
+
:properties => {
|
277
|
+
:name => {:type => :string, :dynamic => false}
|
278
|
+
},
|
279
|
+
:dynamics => {}
|
280
|
+
})
|
281
|
+
|
282
|
+
op = EqualTo.new(:name, 'test')
|
283
|
+
search << op
|
284
|
+
assert_equal("with(:name).equal_to('test')", op.evaluate.gsub(/\s+/, ' '))
|
285
|
+
end
|
286
|
+
|
287
|
+
def test_Without
|
288
|
+
search = Search.new('search_product', 'Product', {
|
289
|
+
:properties => {
|
290
|
+
:name => {:type => :string, :dynamic => false}
|
291
|
+
},
|
292
|
+
:dynamics => {}
|
293
|
+
})
|
294
|
+
|
295
|
+
op = Without.new(:name, 'test')
|
296
|
+
search << op
|
297
|
+
assert_equal("without(:name, 'test')", op.evaluate.gsub(/\s+/, ' '))
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_GreaterThan
|
301
|
+
search = Search.new('search_product', 'Product', {
|
302
|
+
:properties => {
|
303
|
+
:start_date => {:type => :time, :dynamic => false}
|
304
|
+
},
|
305
|
+
:dynamics => {}
|
306
|
+
})
|
307
|
+
|
308
|
+
now = Time.now
|
309
|
+
|
310
|
+
op = GreaterThan.new(:start_date, now)
|
311
|
+
search << op
|
312
|
+
assert_equal("with(:start_date).greater_than('#{now.to_s(:db)}')", op.evaluate.gsub(/\s+/, ' '))
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_LessThan
|
316
|
+
search = Search.new('search_product', 'Product', {
|
317
|
+
:properties => {
|
318
|
+
:start_date => {:type => :time, :dynamic => false}
|
319
|
+
},
|
320
|
+
:dynamics => {}
|
321
|
+
})
|
322
|
+
|
323
|
+
now = Time.now
|
324
|
+
|
325
|
+
op = LessThan.new(:start_date, now)
|
326
|
+
search << op
|
327
|
+
assert_equal("with(:start_date).less_than('#{now.to_s(:db)}')", op.evaluate.gsub(/\s+/, ' '))
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_GreaterThanOrEqual
|
331
|
+
search = Search.new('search_product', 'Product', {
|
332
|
+
:properties => {
|
333
|
+
:start_date => {:type => :time, :dynamic => false}
|
334
|
+
},
|
335
|
+
:dynamics => {}
|
336
|
+
})
|
337
|
+
|
338
|
+
now = Time.now
|
339
|
+
|
340
|
+
op = GreaterThanOrEqual.new(:start_date, now)
|
341
|
+
search << op
|
342
|
+
assert_equal("any_of do with(:start_date).greater_than('#{now.to_s(:db)}') with(:start_date, '#{now.to_s(:db)}') end", op.evaluate.gsub(/\s+/, ' '))
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_LessThanOrEqual
|
346
|
+
search = Search.new('search_product', 'Product', {
|
347
|
+
:properties => {
|
348
|
+
:start_date => {:type => :time, :dynamic => false}
|
349
|
+
},
|
350
|
+
:dynamics => {}
|
351
|
+
})
|
352
|
+
|
353
|
+
now = Time.now
|
354
|
+
|
355
|
+
op = LessThanOrEqual.new(:start_date, now)
|
356
|
+
search << op
|
357
|
+
assert_equal("any_of do with(:start_date).less_than('#{now.to_s(:db)}') with(:start_date, '#{now.to_s(:db)}') end", op.evaluate.gsub(/\s+/, ' '))
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_Between
|
361
|
+
search = Search.new('search_product', 'Product', {
|
362
|
+
:properties => {
|
363
|
+
:start_date => {:type => :time, :dynamic => false}
|
364
|
+
},
|
365
|
+
:dynamics => {}
|
366
|
+
})
|
367
|
+
|
368
|
+
now = Time.now
|
369
|
+
tomorrow = now + 1.day
|
370
|
+
|
371
|
+
op = Between.new(:start_date, now..tomorrow)
|
372
|
+
search << op
|
373
|
+
assert_equal("with(:start_date).between('#{now.to_s(:db)}'..'#{tomorrow.to_s(:db)}')", op.evaluate.gsub(/\s+/, ' '))
|
374
|
+
end
|
375
|
+
|
376
|
+
def test_AnyOf
|
377
|
+
search = Search.new('search_product', 'Product', {
|
378
|
+
:properties => {
|
379
|
+
:start_date => {:type => :time, :dynamic => false}
|
380
|
+
},
|
381
|
+
:dynamics => {}
|
382
|
+
})
|
383
|
+
|
384
|
+
now = Time.now
|
385
|
+
tomorrow = now + 1.day
|
386
|
+
|
387
|
+
op = AnyOf.new(:start_date, [now,tomorrow])
|
388
|
+
search << op
|
389
|
+
assert_equal("with(:start_date).any_of(['#{now.to_s(:db)}','#{tomorrow.to_s(:db)}'])", op.evaluate.gsub(/\s+/, ' '))
|
390
|
+
end
|
391
|
+
|
392
|
+
|
393
|
+
def test_IntervalFromNowEqualTo
|
394
|
+
search = Search.new('search_product', 'Product', {
|
395
|
+
:properties => {
|
396
|
+
:start_date => {:type => :time, :dynamic => false}
|
397
|
+
},
|
398
|
+
:dynamics => {}
|
399
|
+
})
|
400
|
+
|
401
|
+
today = Date.today
|
402
|
+
op = IntervalFromNowEqualTo.new(:start_date, 1)
|
403
|
+
search << op
|
404
|
+
assert_match(/^with\(:start_date\)\.equal_to\('#{(today + 1.day).to_s(:db)}/, op.evaluate.gsub(/\s+/, ' '))
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_IntervalFromNowWithout
|
408
|
+
search = Search.new('search_product', 'Product', {
|
409
|
+
:properties => {
|
410
|
+
:start_date => {:type => :time, :dynamic => false}
|
411
|
+
},
|
412
|
+
:dynamics => {}
|
413
|
+
})
|
414
|
+
|
415
|
+
today = Date.today
|
416
|
+
op = IntervalFromNowWithout.new(:start_date, 1)
|
417
|
+
search << op
|
418
|
+
assert_match(/^without\(:start_date, '#{(today + 1.day).to_s(:db)}/, op.evaluate.gsub(/\s+/, ' '))
|
419
|
+
end
|
420
|
+
|
421
|
+
def test_IntervalFromNowGreaterThan
|
422
|
+
search = Search.new('search_product', 'Product', {
|
423
|
+
:properties => {
|
424
|
+
:start_date => {:type => :time, :dynamic => false}
|
425
|
+
},
|
426
|
+
:dynamics => {}
|
427
|
+
})
|
428
|
+
|
429
|
+
today = Date.today
|
430
|
+
op = IntervalFromNowGreaterThan.new(:start_date, 1)
|
431
|
+
search << op
|
432
|
+
assert_match(/^with\(:start_date\).greater_than\('#{(today + 1.day).to_s(:db)}/, op.evaluate.gsub(/\s+/, ' '))
|
433
|
+
end
|
434
|
+
|
435
|
+
def test_IntervalFromNowLessThan
|
436
|
+
search = Search.new('search_product', 'Product', {
|
437
|
+
:properties => {
|
438
|
+
:start_date => {:type => :time, :dynamic => false}
|
439
|
+
},
|
440
|
+
:dynamics => {}
|
441
|
+
})
|
442
|
+
|
443
|
+
today = Date.today
|
444
|
+
op = IntervalFromNowLessThan.new(:start_date, 1)
|
445
|
+
search << op
|
446
|
+
assert_match(/^with\(:start_date\).less_than\('#{(today + 1.day).to_s(:db)}/, op.evaluate.gsub(/\s+/, ' '))
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_IntervalFromNowGreaterThanOrEqual
|
450
|
+
search = Search.new('search_product', 'Product', {
|
451
|
+
:properties => {
|
452
|
+
:start_date => {:type => :time, :dynamic => false}
|
453
|
+
},
|
454
|
+
:dynamics => {}
|
455
|
+
})
|
456
|
+
|
457
|
+
today = Date.today
|
458
|
+
op = IntervalFromNowGreaterThanOrEqual.new(:start_date, 1)
|
459
|
+
search << op
|
460
|
+
assert_match(/^any_of do with\(:start_date\).greater_than\('#{(today + 1.day).to_s(:db)} [\d\:]+'\) with\(:start_date, '#{(today + 1.day).to_s(:db)} [\d\:]+'\) end$/, op.evaluate.gsub(/\s+/, ' '))
|
461
|
+
end
|
462
|
+
|
463
|
+
def test_IntervalFromNowLessThanOrEqual
|
464
|
+
search = Search.new('search_product', 'Product', {
|
465
|
+
:properties => {
|
466
|
+
:start_date => {:type => :time, :dynamic => false}
|
467
|
+
},
|
468
|
+
:dynamics => {}
|
469
|
+
})
|
470
|
+
|
471
|
+
today = Date.today
|
472
|
+
|
473
|
+
op = IntervalFromNowLessThanOrEqual.new(:start_date, 1)
|
474
|
+
search << op
|
475
|
+
assert_match(/^any_of do with\(:start_date\).less_than\('#{(today + 1.day).to_s(:db)} [\d\:]+'\) with\(:start_date, '#{(today + 1.day).to_s(:db)} [\d\:]+'\) end/, op.evaluate.gsub(/\s+/, ' '))
|
476
|
+
end
|
477
|
+
|
478
|
+
def test_IntervalFromNowBetween
|
479
|
+
search = Search.new('search_product', 'Product', {
|
480
|
+
:properties => {
|
481
|
+
:start_date => {:type => :time, :dynamic => false}
|
482
|
+
},
|
483
|
+
:dynamics => {}
|
484
|
+
})
|
485
|
+
|
486
|
+
today = Date.today
|
487
|
+
tomorrow = today + 1.day
|
488
|
+
|
489
|
+
op = IntervalFromNowBetween.new(:start_date, 0..1)
|
490
|
+
search << op
|
491
|
+
assert_match(/^with\(:start_date\).between\('#{today.to_s(:db)} [\d\:]+'..'#{tomorrow.to_s(:db)} [\d\:]+'\)/, op.evaluate.gsub(/\s+/, ' '))
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_IntervalFromNowAnyOf
|
495
|
+
search = Search.new('search_product', 'Product', {
|
496
|
+
:properties => {
|
497
|
+
:start_date => {:type => :time, :dynamic => false}
|
498
|
+
},
|
499
|
+
:dynamics => {}
|
500
|
+
})
|
501
|
+
|
502
|
+
today = Date.today
|
503
|
+
tomorrow = today + 1.day
|
504
|
+
|
505
|
+
op = IntervalFromNowAnyOf.new(:start_date, [0,1])
|
506
|
+
search << op
|
507
|
+
assert_match(/^with\(:start_date\)\.any_of\(\['#{today.to_s(:db)} [\d\:]+','#{tomorrow.to_s(:db)} [\d\:]+'\]\)/, op.evaluate.gsub(/\s+/, ' '))
|
508
|
+
end
|
509
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: de
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Olga Gorun
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-28 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rubytree
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 61
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 8
|
33
|
+
- 1
|
34
|
+
version: 0.8.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activesupport
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 3
|
49
|
+
- 10
|
50
|
+
version: 2.3.10
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rack-test
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
description: |-
|
68
|
+
De (Dynamic Expression) module provides means to build and evaluate
|
69
|
+
dynamic expression of arbitrary complecity and operands/operators nature
|
70
|
+
email:
|
71
|
+
- ogorun@quicklizard.com
|
72
|
+
executables: []
|
73
|
+
|
74
|
+
extensions: []
|
75
|
+
|
76
|
+
extra_rdoc_files: []
|
77
|
+
|
78
|
+
files:
|
79
|
+
- .gitignore
|
80
|
+
- .rvmrc
|
81
|
+
- Gemfile
|
82
|
+
- README
|
83
|
+
- Rakefile
|
84
|
+
- de.gemspec
|
85
|
+
- lib/de.rb
|
86
|
+
- lib/de/boolean.rb
|
87
|
+
- lib/de/boolean/operand.rb
|
88
|
+
- lib/de/boolean/operator.rb
|
89
|
+
- lib/de/de.rb
|
90
|
+
- lib/de/error.rb
|
91
|
+
- lib/de/sunspot_solr.rb
|
92
|
+
- lib/de/sunspot_solr/operand.rb
|
93
|
+
- lib/de/sunspot_solr/operator.rb
|
94
|
+
- lib/de/sunspot_solr/search.rb
|
95
|
+
- lib/de/symmetric_operator.rb
|
96
|
+
- lib/de/version.rb
|
97
|
+
- test/de_boolean_and_test.rb
|
98
|
+
- test/de_boolean_not_test.rb
|
99
|
+
- test/de_boolean_operand_test.rb
|
100
|
+
- test/de_boolean_operator_test.rb
|
101
|
+
- test/de_boolean_or_test.rb
|
102
|
+
- test/de_expression_test.rb
|
103
|
+
- test/de_operand_test.rb
|
104
|
+
- test/de_operator_test.rb
|
105
|
+
- test/de_sunspot_solr_and_test.rb
|
106
|
+
- test/de_sunspot_solr_not_test.rb
|
107
|
+
- test/de_sunspot_solr_or_test.rb
|
108
|
+
- test/de_sunspot_solr_search_test.rb
|
109
|
+
- test/de_sunspot_solr_sunspot_operand_test.rb
|
110
|
+
has_rdoc: true
|
111
|
+
homepage: ""
|
112
|
+
licenses: []
|
113
|
+
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
137
|
+
requirements: []
|
138
|
+
|
139
|
+
rubyforge_project: de
|
140
|
+
rubygems_version: 1.6.2
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: Dynamic Expression
|
144
|
+
test_files: []
|
145
|
+
|