arel_extensions 1.2.1 → 1.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d16042c9625c2efb1154a69f7717050b164269d
4
- data.tar.gz: a9760058285052d730a80997691cbb1beeacc985
3
+ metadata.gz: bc05c41fcdcdc0c411f00c62947f80e1004791ae
4
+ data.tar.gz: 9d8ea2d6dfc47f8268e0eee6fd974fceb2a700e8
5
5
  SHA512:
6
- metadata.gz: 42e83c94f94962e39052a624c772b88bdb5200a265b0dc062aed6f0cd76cb039b59797b3b163970742a80ac7db88b4648ebdec40739b153cffc798c9eabe046b
7
- data.tar.gz: 31c805934070166c47f758f49732cd21efa56e1a7b4216edd443ed059e9039652789f431c3faa1cc2e40867849827270b9c485d0fdb790d57263e0e12062df5d
6
+ metadata.gz: ab845f8bd4ad51383c2858542183aedc38cbc1a56158249678fe6f89e5d0aae4b036710fc72d4f5c1b95c33bad430ffbc5844964b31730206c541061cffa1e5f
7
+ data.tar.gz: c3bce90a322ffadcb309f2e183ef4c323bca7ee70c11d5ec75e12b6e1ad0d409757fda40826ee9f5645bb64eaa39063d74b61ac82f8ba097ac2a677ed25748ce
@@ -8,17 +8,17 @@ require 'arel_extensions/predications'
8
8
 
9
9
  module ArelExtensions
10
10
  module Attributes
11
- include ArelExtensions::Math
12
- include ArelExtensions::Comparators
13
- include ArelExtensions::DateDuration
14
- include ArelExtensions::MathFunctions
15
- include ArelExtensions::NullFunctions
16
- include ArelExtensions::StringFunctions
17
- include ArelExtensions::Predications
11
+ include ArelExtensions::Math
12
+ include ArelExtensions::Comparators
13
+ include ArelExtensions::DateDuration
14
+ include ArelExtensions::MathFunctions
15
+ include ArelExtensions::NullFunctions
16
+ include ArelExtensions::StringFunctions
17
+ include ArelExtensions::Predications
18
18
 
19
- def ==(other)
19
+ def ==(other)
20
20
  Arel::Nodes::Equality.new self, Arel::Nodes.build_quoted(other, self)
21
- end
21
+ end
22
22
 
23
23
  def !=(other)
24
24
  Arel::Nodes::NotEqual.new self, Arel::Nodes.build_quoted(other, self)
@@ -101,7 +101,7 @@ module ArelExtensions
101
101
  begin
102
102
  col2 = Arel::Table.engine.connection.schema_cache.columns_hash(other.relation.table_name)[other.name.to_s]
103
103
  rescue Exception
104
- col = nil
104
+ col2 = nil
105
105
  end
106
106
  if (!col2) #if the column doesn't exist in the database
107
107
  ArelExtensions::Nodes::DateSub.new [self, other]
@@ -115,8 +115,10 @@ module ArelExtensions
115
115
  end
116
116
  when Arel::Nodes::Node, DateTime, Time, String, Date
117
117
  ArelExtensions::Nodes::DateDiff.new [self, other]
118
- when Integer
118
+ when ArelExtensions::Nodes::Duration, Integer
119
119
  ArelExtensions::Nodes::DateSub.new [self, other]
120
+ else # ActiveSupport::Duration
121
+ ArelExtensions::Nodes::DateAdd.new [self, -other]
120
122
  end
121
123
  else
122
124
  case other
@@ -66,7 +66,12 @@ module ArelExtensions
66
66
  Arel.sql('INTERVAL %s' % v.inspect.sub(/s\Z/, ''))
67
67
  end
68
68
  else
69
- v
69
+ if ArelExtensions::Nodes::Duration === v
70
+ v.with_interval = true
71
+ v
72
+ else
73
+ v
74
+ end
70
75
  end
71
76
  end
72
77
 
@@ -79,20 +84,30 @@ module ArelExtensions
79
84
  Arel.sql("INTERVAL '%s'" % v.inspect.sub(/s\Z/, '').upcase)
80
85
  end
81
86
  else
82
- return v
87
+ if ArelExtensions::Nodes::Duration === v
88
+ v.with_interval = true
89
+ v
90
+ else
91
+ v
92
+ end
83
93
  end
84
94
  end
85
95
 
86
96
  def oracle_value(v = nil)
87
97
  v ||= self.expressions.last
88
98
  if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === v
89
- if @date_type == :date
90
- Arel.sql("INTERVAL '%s' DAY" % v.inspect.to_i)
91
- elsif @date_type == :datetime
92
- Arel.sql("INTERVAL '%s' SECOND" % v.to_i)
99
+ if @date_type == :ruby_date
100
+ Arel.sql("(INTERVAL '1' DAY) * %s" % v.inspect.to_i )
101
+ else
102
+ Arel.sql("(INTERVAL '1' SECOND) * %s" % v.to_i)
93
103
  end
94
104
  else
95
- v
105
+ if ArelExtensions::Nodes::Duration === v
106
+ v.with_interval = true
107
+ v
108
+ else
109
+ v
110
+ end
96
111
  end
97
112
  end
98
113
 
@@ -100,7 +115,7 @@ module ArelExtensions
100
115
  v ||= self.expressions.last
101
116
  if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === v
102
117
  if @date_type == :date
103
- v.inspect.to_i
118
+ v.to_i / (24*3600)
104
119
  elsif @date_type == :datetime
105
120
  v.to_i
106
121
  end
@@ -118,7 +133,21 @@ module ArelExtensions
118
133
  Arel.sql('second')
119
134
  end
120
135
  else
121
- v
136
+ if ArelExtensions::Nodes::Duration === v
137
+ v.with_interval = true
138
+ case v.left
139
+ when 'd','m','y'
140
+ Arel.sql('day')
141
+ when 'h','mn','s'
142
+ Arel.sql('second')
143
+ when /i\z/
144
+ Arel.sql(Arel::Visitors::MSSQL::DATE_MAPPING[v.left[0..-2]])
145
+ else
146
+ Arel.sql(Arel::Visitors::MSSQL::DATE_MAPPING[v.left])
147
+ end
148
+ else
149
+ nil
150
+ end
122
151
  end
123
152
  end
124
153
 
@@ -153,7 +182,11 @@ module ArelExtensions
153
182
  when String
154
183
  object.to_i
155
184
  else
156
- raise(ArgumentError, "#{object.class} can not be converted to Number")
185
+ if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === object
186
+ object.to_i
187
+ else
188
+ raise(ArgumentError, "#{object.class} can not be converted to Number")
189
+ end
157
190
  end
158
191
  end
159
192
 
@@ -3,10 +3,13 @@ module ArelExtensions
3
3
  class Duration < Function
4
4
  RETURN_TYPE = :number
5
5
 
6
+ attr_accessor :with_interval
7
+
6
8
  def initialize left, right, aliaz = nil
7
9
  tab = Array.new
8
10
  tab << left
9
11
  tab << right
12
+ @with_interval = left.end_with?('i')
10
13
  super(tab, aliaz)
11
14
  end
12
15
 
@@ -132,6 +132,9 @@ module ArelExtensions
132
132
 
133
133
  def convert_to_number(object)
134
134
  case object
135
+ when ArelExtensions::Nodes::Duration
136
+ object.with_interval = true
137
+ object
135
138
  when Arel::Attributes::Attribute, Arel::Nodes::Node
136
139
  object
137
140
  when Integer
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "1.2.1".freeze
2
+ VERSION = "1.2.2".freeze
3
3
  end
@@ -84,23 +84,38 @@ module ArelExtensions
84
84
  end
85
85
 
86
86
 
87
+
87
88
  def visit_ArelExtensions_Nodes_DateDiff o, collector
88
- collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
89
- 'DATEDIFF(second'
90
- else
91
- 'DATEDIFF(day'
92
- end
93
- collector << Arel::Visitors::MSSQL::COMMA
94
- collector = visit o.right, collector
95
- collector << Arel::Visitors::MSSQL::COMMA
96
- collector = visit o.left, collector
97
- collector << ')'
89
+ if o.right_node_type == :ruby_date || o.right_node_type == :ruby_time || o.right_node_type == :date || o.right_node_type == :datetime || o.right_node_type == :time
90
+ collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
91
+ 'DATEDIFF(second'
92
+ else
93
+ 'DATEDIFF(day'
94
+ end
95
+ collector << Arel::Visitors::MSSQL::COMMA
96
+ collector = visit o.right, collector
97
+ collector << Arel::Visitors::MSSQL::COMMA
98
+ collector = visit o.left, collector
99
+ collector << ')'
100
+ else
101
+ da = ArelExtensions::Nodes::DateAdd.new([])
102
+ collector << "DATEADD("
103
+ collector = visit da.mssql_datepart(o.right), collector
104
+ collector << Arel::Visitors::MSSQL::COMMA
105
+ collector << "-("
106
+ collector = visit da.mssql_value(o.right), collector
107
+ collector << ")"
108
+ collector << Arel::Visitors::MSSQL::COMMA
109
+ collector = visit o.left, collector
110
+ collector << ")"
111
+ collector
112
+ end
98
113
  collector
99
114
  end
100
115
 
101
116
  def visit_ArelExtensions_Nodes_DateAdd o, collector
102
117
  collector << "DATEADD("
103
- collector << o.mssql_datepart(o.right)
118
+ collector = visit o.mssql_datepart(o.right), collector
104
119
  collector << Arel::Visitors::MSSQL::COMMA
105
120
  collector = visit o.mssql_value(o.right), collector
106
121
  collector << Arel::Visitors::MSSQL::COMMA
@@ -110,14 +125,19 @@ module ArelExtensions
110
125
  end
111
126
 
112
127
  def visit_ArelExtensions_Nodes_Duration o, collector
113
- conv = ['h', 'mn', 's'].include?(o.left)
114
- collector << 'DATEPART('
115
- collector << Arel::Visitors::MSSQL::DATE_MAPPING[o.left]
116
- collector << Arel::Visitors::MSSQL::COMMA
117
- collector << 'CONVERT(datetime,' if conv
118
- collector = visit o.right, collector
119
- collector << ')' if conv
120
- collector << ")"
128
+ if o.with_interval && o.left.end_with?('i')
129
+ collector = visit o.right, collector
130
+ else
131
+ left = o.left.end_with?('i') ? o.left[0..-2] : o.left
132
+ conv = ['h', 'mn', 's'].include?(o.left)
133
+ collector << 'DATEPART('
134
+ collector << Arel::Visitors::MSSQL::DATE_MAPPING[left]
135
+ collector << Arel::Visitors::MSSQL::COMMA
136
+ collector << 'CONVERT(datetime,' if conv
137
+ collector = visit o.right, collector
138
+ collector << ')' if conv
139
+ collector << ")"
140
+ end
121
141
  collector
122
142
  end
123
143
 
@@ -216,15 +216,31 @@ module ArelExtensions
216
216
  end
217
217
 
218
218
  def visit_ArelExtensions_Nodes_DateDiff o, collector
219
- collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
220
- 'TIMESTAMPDIFF(SECOND, '
221
- else
222
- 'DATEDIFF('
223
- end
224
- collector = visit o.right, collector
225
- collector << Arel::Visitors::MySQL::COMMA
226
- collector = visit o.left, collector
227
- collector << ")"
219
+ if o.right_node_type == :ruby_date || o.right_node_type == :ruby_time || o.right_node_type == :date || o.right_node_type == :datetime || o.right_node_type == :time
220
+ collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
221
+ 'TIMESTAMPDIFF(SECOND, '
222
+ else
223
+ 'DATEDIFF('
224
+ end
225
+ collector = visit o.right, collector
226
+ collector << Arel::Visitors::MySQL::COMMA
227
+ collector = visit o.left, collector
228
+ collector << ")"
229
+ else
230
+ collector << '('
231
+ collector = visit o.left, collector
232
+ collector << ' - '
233
+ if o.right.is_a?(ArelExtensions::Nodes::Duration)
234
+ o.right.with_interval = true
235
+ collector = visit o.right, collector
236
+ else
237
+ collector << '('
238
+ collector = visit o.right, collector
239
+ collector << ')'
240
+ end
241
+ collector << ')'
242
+ collector
243
+ end
228
244
  collector
229
245
  end
230
246
 
@@ -244,9 +260,23 @@ module ArelExtensions
244
260
  collector = visit o.right, collector
245
261
  collector << ") + 1) % 7"
246
262
  else
263
+ if o.with_interval
264
+ case o.left
265
+ when 'd','m','y'
266
+ interval = 'DAY'
267
+ when 'h','mn','s'
268
+ interval = 'SECOND'
269
+ when /i\z/
270
+ interval = Arel::Visitors::MySQL::DATE_MAPPING[o.left[0..-2]]
271
+ else
272
+ interval = nil
273
+ end
274
+ end
275
+ collector << " INTERVAL " if o.with_interval && interval
247
276
  collector << "#{Arel::Visitors::MySQL::DATE_MAPPING[o.left]}("
248
277
  collector = visit o.right, collector
249
278
  collector << ")"
279
+ collector << " #{interval} " if o.with_interval && interval
250
280
  end
251
281
  collector
252
282
  end
@@ -298,8 +328,6 @@ module ArelExtensions
298
328
  as_attr = Arel::Nodes::SqlLiteral.new('datetime')
299
329
  when :date
300
330
  as_attr = Arel::Nodes::SqlLiteral.new('date')
301
- when :time
302
- as_attr = Arel::Nodes::SqlLiteral.new('time')
303
331
  when :binary
304
332
  as_attr = Arel::Nodes::SqlLiteral.new('binary')
305
333
  else
@@ -180,26 +180,38 @@ module ArelExtensions
180
180
  def visit_ArelExtensions_Nodes_DateDiff o, collector
181
181
  lc = o.left_node_type == :ruby_date || o.left_node_type == :ruby_time
182
182
  rc = o.right_node_type == :ruby_date || o.right_node_type == :ruby_time
183
- collector << '('
184
- collector << 'TO_DATE(' if lc
185
- collector = visit o.left, collector
186
- collector << ')' if lc
187
- collector << " - "
188
- collector << 'TO_DATE(' if rc
189
- collector = visit o.right, collector
190
- collector << ')' if rc
191
- collector << ')'
192
- if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
193
- collector << ' * (CASE WHEN (TRUNC('
183
+ if rc || o.right_node_type == :date || o.right_node_type == :datetime || o.right_node_type == :time
184
+ collector << '('
194
185
  collector << 'TO_DATE(' if lc
195
186
  collector = visit o.left, collector
196
187
  collector << ')' if lc
197
- collector << Arel::Visitors::Oracle::COMMA
198
- collector << "'DDD') = "
199
- collector << 'TO_DATE(' if lc
188
+ collector << " - "
189
+ collector << 'TO_DATE(' if rc
190
+ collector = visit o.right, collector
191
+ collector << ')' if rc
192
+ collector << ')'
193
+ if (o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time)
194
+ collector << ' * (CASE WHEN (TRUNC('
195
+ collector << 'TO_DATE(' if lc
196
+ collector = visit o.left, collector
197
+ collector << ')' if lc
198
+ collector << Arel::Visitors::Oracle::COMMA
199
+ collector << "'DDD') = "
200
+ collector << 'TO_DATE(' if lc
201
+ collector = visit o.left, collector
202
+ collector << ')' if lc
203
+ collector << ') THEN 1 ELSE 86400 END)' # converts to seconds
204
+ end
205
+ else
206
+ collector << '('
200
207
  collector = visit o.left, collector
201
- collector << ')' if lc
202
- collector << ') THEN 1 ELSE 86400 END)' # converts to seconds
208
+ collector << ' - ('
209
+ if o.right.is_a?(ArelExtensions::Nodes::Duration)
210
+ o.right.with_interval = true
211
+ end
212
+ collector = visit o.right, collector
213
+ collector << '))'
214
+ collector
203
215
  end
204
216
  collector
205
217
  end
@@ -212,10 +224,28 @@ module ArelExtensions
212
224
  collector << Arel::Visitors::Oracle::COMMA
213
225
  collector = visit Arel::Nodes.build_quoted(Arel::Visitors::Oracle::DATE_MAPPING[o.left]), collector
214
226
  else
227
+ right = case o.left
228
+ when 'd','m','y'
229
+ interval = 'DAY'
230
+ o.right.cast(:date)
231
+ when 'h','mn','s'
232
+ interval = 'SECOND'
233
+ o.right.cast(:datetime)
234
+ when /i\z/
235
+ interval = Arel::Visitors::Oracle::DATE_MAPPING[o.left[0..-2]]
236
+ collector << '('
237
+ collector = visit o.right, collector
238
+ collector << ") * (INTERVAL '1' #{interval})"
239
+ return collector
240
+ else
241
+ interval = nil
242
+ o.right
243
+ end
215
244
  collector << "EXTRACT(#{Arel::Visitors::Oracle::DATE_MAPPING[o.left]} FROM "
216
- collector = visit o.right, collector
245
+ collector = visit right, collector
217
246
  end
218
247
  collector << ")"
248
+ collector << " * (INTERVAL '1' #{interval})" if interval && o.with_interval
219
249
  collector
220
250
  end
221
251
 
@@ -387,7 +417,7 @@ module ArelExtensions
387
417
  def visit_ArelExtensions_Nodes_DateAdd o, collector
388
418
  collector << '('
389
419
  collector = visit o.left, collector
390
- collector << (o.right.value >= 0 ? ' + ' : ' - ')
420
+ collector << ' + '# (o.right.value >= 0 ? ' + ' : ' - ')
391
421
  collector = visit o.oracle_value(o.right), collector
392
422
  collector << ')'
393
423
  collector
@@ -205,30 +205,56 @@ module ArelExtensions
205
205
 
206
206
  def visit_ArelExtensions_Nodes_DateAdd o, collector
207
207
  collector = visit o.left, collector
208
- collector << (o.right.value >= 0 ? ' + ' : ' - ')
208
+ collector << ' + ' #(o.right.value >= 0 ? ' + ' : ' - ')
209
209
  collector = visit o.postgresql_value(o.right), collector
210
210
  collector
211
211
  end
212
212
 
213
213
  def visit_ArelExtensions_Nodes_DateDiff o, collector
214
- collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
215
- "DATEDIFF('second', "
216
- else
217
- "DATEDIFF('day', "
218
- end
219
- collector = visit o.right, collector
220
- collector << (o.right_node_type == :date ? '::date' : '::timestamp')
221
- collector << Arel::Visitors::PostgreSQL::COMMA
222
- collector = visit o.left, collector
223
- collector << (o.left_node_type == :date ? '::date' : '::timestamp')
224
- collector << ")"
214
+ if o.right_node_type == :ruby_date || o.right_node_type == :ruby_time || o.right_node_type == :date || o.right_node_type == :datetime || o.right_node_type == :time
215
+ collector << if o.left_node_type == :ruby_time || o.left_node_type == :datetime || o.left_node_type == :time
216
+ "DATEDIFF('second', "
217
+ else
218
+ "DATEDIFF('day', "
219
+ end
220
+ collector = visit o.right, collector
221
+ collector << (o.right_node_type == :date ? '::date' : '::timestamp')
222
+ collector << Arel::Visitors::PostgreSQL::COMMA
223
+ collector = visit o.left, collector
224
+ collector << (o.left_node_type == :date ? '::date' : '::timestamp')
225
+ collector << ")"
226
+ else
227
+ collector << '('
228
+ collector = visit o.left, collector
229
+ collector << ' - ('
230
+ if o.right.is_a?(ArelExtensions::Nodes::Duration)
231
+ o.right.with_interval = true
232
+ end
233
+ collector = visit o.right, collector
234
+ collector << '))'
235
+ end
225
236
  collector
226
237
  end
227
238
 
228
239
  def visit_ArelExtensions_Nodes_Duration o, collector
240
+ if o.with_interval
241
+ interval = case o.left
242
+ when 'd','m','y'
243
+ 'DAY'
244
+ when 'h','mn','s'
245
+ 'SECOND'
246
+ when /i\z/
247
+ collector << "("
248
+ collector = visit o.right, collector
249
+ collector << ")"
250
+ collector << " * (INTERVAL '1' #{Arel::Visitors::PostgreSQL::DATE_MAPPING[o.left[0..-2]]})"
251
+ return collector
252
+ end
253
+ end
229
254
  collector << "EXTRACT(#{Arel::Visitors::PostgreSQL::DATE_MAPPING[o.left]} FROM "
230
255
  collector = visit o.right, collector
231
256
  collector << ")"
257
+ collector << " * (INTERVAL '1' #{interval})" if interval && o.with_interval
232
258
  collector
233
259
  end
234
260
 
@@ -89,6 +89,10 @@ module Arel
89
89
  ArelExtensions::Nodes::Case.new.when(condition)
90
90
  end
91
91
 
92
+ def self.duration s, expr
93
+ ArelExtensions::Nodes::Duration.new(s.to_s+'i',expr)
94
+ end
95
+
92
96
  end
93
97
 
94
98
  Arel::Attributes::Attribute.class_eval do
@@ -391,7 +391,7 @@ module ArelExtensions
391
391
  assert_equal 23, t(@laure, @created_at.day).to_i
392
392
  assert_equal 0, User.where(@created_at.day.eq("05")).count
393
393
 
394
- skip "manage DATE" if @env_db == 'oracle'
394
+ #skip "manage DATE" if @env_db == 'oracle'
395
395
  #Hour
396
396
  assert_equal 0, t(@laure, @created_at.hour).to_i
397
397
  assert_equal 12, t(@lucas, @updated_at.hour).to_i
@@ -416,24 +416,51 @@ module ArelExtensions
416
416
  else
417
417
  assert_includes [nil, 0, 'f', false], t(@lucas, (@updated_at - Time.utc(2014, 3, 3, 12, 41, 18)) < -1)
418
418
  end
419
- if @env_db == 'mysql'
420
- date1 = Date.new(2016, 5, 23)
421
- durPos = 10.years
422
- durNeg = -10.years
423
- date2 = date1 + durPos
424
- date3 = date1 - durPos
425
- # Pull Request #5 tests
426
- assert_includes [date2,"2026-05-23"], t(@test,(@created_at + durPos))
427
- assert_includes [date3,"2006-05-23"], t(@test,(@created_at + durNeg))
428
- # we test with the ruby object or the string because some adapters don't return an object Date
429
- end
430
419
  end
420
+
421
+ skip "not yet implemented" if $sqlite
422
+
423
+ date1 = Date.new(2016, 5, 23)
424
+ durPos = 10.years
425
+ durNeg = -10.years
426
+ date2 = date1 + durPos
427
+ date3 = date1 - durPos
428
+ date4 = date1 + 23.days
429
+ date5 = date1 - 23.days
430
+
431
+ datetime1 = Time.utc(2014, 3, 3, 12, 42, 0)
432
+ # Pull Request #5 tests
433
+ #puts (@created_at + durPos).cast(:date).to_sql
434
+ assert_includes [date2,"2026-05-23"], t(@test,(@created_at + durPos).cast(:date))
435
+ assert_includes [date3,"2006-05-23"], t(@test,(@created_at + durNeg).cast(:date))
436
+
437
+ #puts (@created_at + @created_at.day).cast(:date).to_sql
438
+ assert_includes [date4,"2016-06-15"], t(@test,(@created_at + @created_at.day).cast(:date))
439
+ #puts (@created_at - @created_at.day).cast(:date).to_sql
440
+ assert_includes [date5,"2016-04-30"], t(@test,(@created_at - @created_at.day).cast(:date))
441
+
442
+ assert_includes [datetime1 + 42.seconds,"2014-03-03 12:42:42 UTC"], t(@lucas,(@updated_at + @updated_at.minute))
443
+ assert_includes [datetime1 - 42.seconds,"2014-03-03 12:41:18 UTC"], t(@lucas,(@updated_at - @updated_at.minute))
444
+
445
+ # (@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))).to_sql
446
+ assert_includes [datetime1 + (12*60+42).seconds,"2014-03-03 12:54:42 UTC"],
447
+ t(@lucas,(@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))))
448
+
449
+ assert_includes [datetime1 + (12*60+42).minutes,"2014-03-04 01:24:00 UTC"],
450
+ t(@lucas,(@updated_at + Arel.duration('mn',(@updated_at.hour*60 + @updated_at.minute))))
451
+
452
+ assert_includes ["2024-03-03"], t(@lucas,(@updated_at + durPos).format('%Y-%m-%d'))
453
+ #puts (@updated_at - durPos).to_sql
454
+ assert_includes ["2004-03-03"], t(@lucas,(@updated_at - durPos).format('%Y-%m-%d'))
455
+
456
+
457
+ # we test with the ruby object or the string because some adapters don't return an object Date
458
+ # end
431
459
  end
432
460
 
433
461
  # TODO; cast types
434
462
  def test_cast_types
435
463
  assert_equal "5", t(@lucas, @age.cast(:string))
436
- updated_at = Time.utc(2014, 3, 3, 12, 42, 0)
437
464
  if @env_db == 'mysql' || @env_db == 'postgresql' || @env_db == 'oracle' || @env_db == 'mssql'
438
465
  assert_equal 1, t(@laure,ArelExtensions::Nodes::Case.new.when(@duration.cast(:time).cast(:string).eq("12:42:21")).then(1).else(0)) unless @env_db == 'oracle' || @env_db == 'mssql'
439
466
  assert_equal 1, t(@laure,ArelExtensions::Nodes::Case.new.when(@duration.cast(:time).eq("12:42:21")).then(1).else(0)) unless @env_db == 'oracle'
@@ -536,7 +563,7 @@ module ArelExtensions
536
563
 
537
564
  def test_format_numbers
538
565
  #score of Arthur = 65.62
539
- skip " Works with SQLite if the version used knows printf" if @env_db = $sqlite
566
+ skip " Works with SQLite if the version used knows printf" if $sqlite
540
567
 
541
568
  assert_equal "Wrong Format" , t(@arthur, @score.format_number("$ %...234.6F €","fr_FR"))
542
569
  assert_equal "AZERTY65,62" , t(@arthur, @score.format_number("AZERTY%.2f","fr_FR"))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arel_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yann Azoury
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-04-16 00:00:00.000000000 Z
13
+ date: 2019-05-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: arel