arel_extensions 1.2.12 → 1.2.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61fb95aac9f849a376b1a3bd64463f73493d81b0e0bd6d5c4cca7bbc5f2a6118
4
- data.tar.gz: 25a3276b6c4b5d75ab0096abeffe566908e8fa705e971b374f9ed02bab750fb8
3
+ metadata.gz: 63535bd97d5c08485672454464e4fd96413ba4f5e7660dd45f008b113f6c92ef
4
+ data.tar.gz: 1478ed16cc0a12b70198334394a456c43a33a480ab9d52786a1be75f11016d4a
5
5
  SHA512:
6
- metadata.gz: 66d7b78543425c7428470c3c004b679b8c79264e37f4e00ab359b144f066d64a0b98904db4ce02ba54084e4a798469f27723e9a5c1705e13b1f4bdcda157e8b2
7
- data.tar.gz: baf1f9313562c71596cc7c507fadcb0a87ec77afb40ec5ef0ba51e2880359702e06c04124ae696e9b9defb92445f5bebe134c91d295b9e346651fbdecf9581f7
6
+ metadata.gz: 0c862b43fb3b4f5758fa2454888bd5abbea6dc802cfb401ba5866fc9c3ce05de6aafb5db151b3a85ac63617fba2f773bb5230c5f0a2f4781a8c07ee521e70783
7
+ data.tar.gz: 1114bf913a0e79a0ebf1a9c28c995e3eb428147615bc51861c55de322e0dc3c5968949dce4cf432c525e470fbfa9d49a6d3a371ccdf69fe602a8f2db608c1834
@@ -129,6 +129,8 @@ matrix:
129
129
  jdk: openjdk11
130
130
  - rvm: 2.7.1
131
131
  gemfile: gemfiles/rails4.gemfile
132
+ - rvm : jruby-9.0.5.0
133
+ gemfile: gemfiles/rails4.gemfile
132
134
  - rvm : jruby-9.2.11.1
133
135
  gemfile: gemfiles/rails4.gemfile
134
136
  - rvm: 2.0.0
@@ -36,7 +36,7 @@ class Arel::Nodes::Function
36
36
  include Arel::Expressions
37
37
  end
38
38
 
39
- if Arel::VERSION >= "7.1.0"
39
+ if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("7.1.0")
40
40
  class Arel::Nodes::Case
41
41
  include Arel::Math
42
42
  include Arel::Expressions
@@ -183,3 +183,14 @@ class Arel::Table
183
183
  name.blank? ? self : Arel::Nodes::TableAlias.new(self,name)
184
184
  end
185
185
  end
186
+
187
+ class Arel::Nodes::TableAlias
188
+ def method_missing(*args)
189
+ met = args.shift.to_sym
190
+ if self.relation.respond_to?(met)
191
+ self.relation.send(met,args)
192
+ else
193
+ super(met,*args)
194
+ end
195
+ end
196
+ end
@@ -63,8 +63,28 @@ class Arel::Nodes::Or
63
63
  @children = children
64
64
  end
65
65
 
66
+ def initialize_copy(other)
67
+ super
68
+ @children = other.children.copy if other.children
69
+ end
70
+
71
+
72
+ def left
73
+ children.first
74
+ end
75
+
76
+ def right
77
+ children[1]
78
+ end
79
+
66
80
  def hash
67
81
  children.hash
68
82
  end
69
83
 
84
+ def eql?(other)
85
+ self.class == other.class &&
86
+ children == other.children
87
+ end
88
+ alias :== :eql?
89
+
70
90
  end
@@ -12,7 +12,7 @@ module ArelExtensions
12
12
  db.enable_load_extension(0)
13
13
  rescue => e
14
14
  $load_extension_disabled = true
15
- puts "can not load extensions #{e.inspect}"
15
+ puts "cannot load extensions #{e.inspect}"
16
16
  end
17
17
  end
18
18
  end
@@ -44,7 +44,7 @@ module ArelExtensions
44
44
  begin
45
45
  add_sqlite_functions
46
46
  rescue => e
47
- puts "can not add sqlite functions #{e.inspect}"
47
+ puts "cannot add sqlite functions #{e.inspect}"
48
48
  end
49
49
  end
50
50
  if File.exist?("init/#{env_db}.sql")
@@ -1,7 +1,11 @@
1
1
  module ArelExtensions
2
2
  module Nodes
3
- if Arel::VERSION < "7.1.0"
3
+ if Gem::Version.new(Arel::VERSION) < Gem::Version.new("7.1.0")
4
4
  class Case < Arel::Nodes::Node
5
+ include Arel::Expressions
6
+ include Arel::Math
7
+ include Arel::Predications
8
+ include Arel::OrderPredications
5
9
  attr_accessor :case, :conditions, :default
6
10
 
7
11
  def initialize expression = nil, default = nil
@@ -28,6 +32,8 @@ module ArelExtensions
28
32
 
29
33
  class ArelExtensions::Nodes::Case
30
34
  include Arel::Expressions
35
+ include Arel::Math
36
+ include Arel::Predications
31
37
  include Arel::OrderPredications
32
38
  include ArelExtensions::Math
33
39
  include ArelExtensions::Comparators
@@ -14,7 +14,10 @@ module ArelExtensions
14
14
  @return_type = :decimal
15
15
  when :number
16
16
  @return_type = :number
17
- when 'char', 'varchar', 'text', 'nchar', 'nvarchar', 'ntext'
17
+ when 'char', 'varchar', 'nchar', 'nvarchar'
18
+ @return_type = :string
19
+ when 'text', :text, 'ntext', :ntext
20
+ @as_attr = expr[1].to_sym
18
21
  @return_type = :string
19
22
  when :datetime, 'datetime','smalldatetime'
20
23
  @return_type = :datetime
@@ -157,11 +157,11 @@ module ArelExtensions
157
157
  when Integer
158
158
  object.days
159
159
  when DateTime, Time, Date
160
- raise(ArgumentError, "#{object.class} can not be converted to Integer")
160
+ raise(ArgumentError, "#{object.class} cannot be converted to Integer")
161
161
  when String
162
162
  Arel::Nodes.build_quoted(object)
163
163
  else
164
- raise(ArgumentError, "#{object.class} can not be converted to Integer")
164
+ raise(ArgumentError, "#{object.class} cannot be converted to Integer")
165
165
  end
166
166
  end
167
167
  end
@@ -183,7 +183,7 @@ module ArelExtensions
183
183
  if defined?(ActiveSupport::Duration) && ActiveSupport::Duration === object
184
184
  object.to_i
185
185
  else
186
- raise(ArgumentError, "#{object.class} can not be converted to Number")
186
+ raise(ArgumentError, "#{object.class} cannot be converted to Number")
187
187
  end
188
188
  end
189
189
  end
@@ -1,3 +1,5 @@
1
+ require 'strscan'
2
+
1
3
  module ArelExtensions
2
4
  module Nodes
3
5
  class Format < Function
@@ -6,10 +8,33 @@ module ArelExtensions
6
8
  attr_accessor :col_type, :iso_format
7
9
  def initialize expr
8
10
  col = expr.first
9
- @iso_format = expr[1]
11
+ @iso_format = convert_format(expr[1])
10
12
  @col_type = type_of_attribute(col)
11
13
  super [col, convert_to_string_node(@iso_format)]
12
14
  end
15
+
16
+ private
17
+
18
+ # Address portability issues with some of the formats.
19
+ def convert_format(fmt)
20
+ s = StringScanner.new fmt
21
+ res = StringIO.new
22
+ while !s.eos?
23
+ res <<
24
+ case
25
+ when s.scan(/%D/) then '%m/%d/%y'
26
+ when s.scan(/%F/) then '%Y-%m-%d'
27
+ when s.scan(/%R/) then '%H:%M'
28
+ when s.scan(/%r/) then '%I:%M:%S %p'
29
+ when s.scan(/%T/) then '%H:%M:%S'
30
+ when s.scan(/%v/) then '%e-%b-%Y'
31
+
32
+ when s.scan(/[^%]+/) then s.matched
33
+ when s.scan(/./) then s.matched
34
+ end
35
+ end
36
+ res.string
37
+ end
13
38
  end
14
39
  end
15
40
  end
@@ -10,6 +10,10 @@ module ArelExtensions
10
10
 
11
11
  RETURN_TYPE = :string # by default...
12
12
 
13
+ # Support multibyte string if they are available.
14
+ MBSTRING =
15
+ defined?(ActiveSupport::Multibyte::Chars) ? ActiveSupport::Multibyte::Chars : String
16
+
13
17
  # overrides as to make new Node like AliasPredication
14
18
 
15
19
  def return_type
@@ -63,7 +67,7 @@ module ArelExtensions
63
67
  Arel::Nodes.build_quoted(object, self)
64
68
  when Time
65
69
  Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
66
- when String, Symbol
70
+ when MBSTRING, String, Symbol
67
71
  Arel::Nodes.build_quoted(object.to_s)
68
72
  when Date
69
73
  Arel::Nodes.build_quoted(object.to_s, self)
@@ -74,7 +78,7 @@ module ArelExtensions
74
78
  when Array
75
79
  Arel::Nodes::Grouping.new(object.map{|r| convert_to_node(e)})
76
80
  else
77
- raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
81
+ raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
78
82
  end
79
83
  end
80
84
 
@@ -97,8 +101,8 @@ module ArelExtensions
97
101
  Arel::Nodes.build_quoted(object, self)
98
102
  when Time
99
103
  Arel::Nodes.build_quoted(object.strftime('%H:%M:%S'), self)
100
- when String
101
- Arel::Nodes.build_quoted(object)
104
+ when MBSTRING, String
105
+ Arel::Nodes.build_quoted(object.to_s)
102
106
  when Date
103
107
  Arel::Nodes.build_quoted(object, self)
104
108
  when NilClass
@@ -106,7 +110,7 @@ module ArelExtensions
106
110
  when ActiveSupport::Duration
107
111
  Arel::Nodes.build_quoted(object.to_i.to_s)
108
112
  else
109
- raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
113
+ raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
110
114
  end
111
115
  end
112
116
 
@@ -116,12 +120,12 @@ module ArelExtensions
116
120
  object
117
121
  when DateTime, Time
118
122
  Arel::Nodes.build_quoted(Date.new(object.year, object.month, object.day), self)
119
- when String
120
- Arel::Nodes.build_quoted(Date.parse(object), self)
123
+ when MBSTRING, String
124
+ Arel::Nodes.build_quoted(Date.parse(object.to_s), self)
121
125
  when Date
122
126
  Arel::Nodes.build_quoted(object, self)
123
127
  else
124
- raise(ArgumentError, "#{object.class} can not be converted to Date")
128
+ raise(ArgumentError, "#{object.class} cannot be converted to Date")
125
129
  end
126
130
  end
127
131
 
@@ -131,12 +135,12 @@ module ArelExtensions
131
135
  object
132
136
  when DateTime, Time
133
137
  Arel::Nodes.build_quoted(object, self)
134
- when String
135
- Arel::Nodes.build_quoted(Time.parse(object), self)
138
+ when MBSTRING, String
139
+ Arel::Nodes.build_quoted(Time.parse(object.to_s), self)
136
140
  when Date
137
141
  Arel::Nodes.build_quoted(Time.utc(object.year, object.month, object.day, 0, 0, 0), self)
138
142
  else
139
- raise(ArgumentError, "#{object.class} can not be converted to Datetime")
143
+ raise(ArgumentError, "#{object.class} cannot be converted to Datetime")
140
144
  end
141
145
  end
142
146
 
@@ -154,7 +158,7 @@ module ArelExtensions
154
158
  when NilClass
155
159
  0
156
160
  else
157
- raise(ArgumentError, "#{object.class} can not be converted to NUMBER arg")
161
+ raise(ArgumentError, "#{object.class} cannot be converted to NUMBER arg")
158
162
  end
159
163
  end
160
164
 
@@ -26,6 +26,44 @@ module ArelExtensions
26
26
  [@dict].hash
27
27
  end
28
28
 
29
+ def convert_to_json_node(n)
30
+ case n
31
+ when JsonNode
32
+ n.dict
33
+ when Array
34
+ n.map{|e|
35
+ (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_json_node(e)
36
+ }
37
+ when Hash
38
+ n.reduce({}){|acc,v|
39
+ acc[convert_to_json_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_json_node(v[1])
40
+ acc
41
+ }
42
+ when String, Numeric, TrueClass, FalseClass
43
+ convert_to_node(n)
44
+ when Date
45
+ convert_to_node(n.strftime("%Y-%m-%d"))
46
+ when DateTime, Time
47
+ convert_to_node(n.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"))
48
+ when NilClass
49
+ Arel.sql('null')
50
+ else
51
+ convert_to_node(n)
52
+ end
53
+ end
54
+
55
+ def type_of_node(v)
56
+ if v.is_a?(Arel::Attributes::Attribute)
57
+ self.type_of_attribute(v)
58
+ elsif v.respond_to?(:return_type)
59
+ v.return_type
60
+ elsif v.nil?
61
+ :nil
62
+ else
63
+ :string
64
+ end
65
+ end
66
+
29
67
  end
30
68
 
31
69
  class Json < JsonNode
@@ -33,32 +71,9 @@ module ArelExtensions
33
71
  def initialize *expr
34
72
  @dict =
35
73
  if expr.length == 1
36
- case exp = expr.first
37
- when JsonNode
38
- exp.dict
39
- when Array
40
- exp.map{|e|
41
- (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_node(e)
42
- }
43
- when Hash
44
- exp.reduce({}){|acc,v|
45
- acc[convert_to_node(v[0])] = (v[1].is_a?(Array) || v[1].is_a?(Hash)) ? Json.new(v[1]) : convert_to_node(v[1])
46
- acc
47
- }
48
- when String, Numeric, TrueClass, FalseClass
49
- convert_to_node(exp)
50
- when NilClass
51
- Arel.sql('null')
52
- else
53
- if (exp.is_a?(Arel::Attributes::Attribute) && type_of_attribute(exp) == :string) \
54
- || (exp.return_type == :string)
55
- convert_to_node(exp)
56
- else
57
- [convert_to_node(exp)]
58
- end
59
- end
74
+ convert_to_json_node(expr.first)
60
75
  else
61
- expr.map{|e| (e.is_a?(Array) || e.is_a?(Hash)) ? Json.new(e) : convert_to_node(e) }
76
+ expr.map{|e| convert_to_json_node(e) }
62
77
  end
63
78
  super
64
79
  end
@@ -26,7 +26,7 @@ module ArelExtensions
26
26
  case other
27
27
  when Range
28
28
  self.between(other)
29
- when Arel::Nodes::Grouping
29
+ when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
30
30
  Arel::Nodes::In.new(self, quoted_node(other))
31
31
  when Enumerable
32
32
  nils, values = other.partition{ |v| v.nil? }
@@ -54,7 +54,7 @@ module ArelExtensions
54
54
  case other
55
55
  when Range
56
56
  Arel::Nodes::Not.new(self.between(other))
57
- when Arel::Nodes::Grouping
57
+ when Arel::Nodes::Grouping, ArelExtensions::Nodes::Union, ArelExtensions::Nodes::UnionAll
58
58
  Arel::Nodes::NotIn.new(self, quoted_node(other))
59
59
  when Enumerable
60
60
  nils, values = other.partition{ |v| v.nil? }
@@ -94,7 +94,7 @@ module ArelExtensions
94
94
  when ActiveSupport::Duration
95
95
  object.to_i
96
96
  else
97
- raise(ArgumentError, "#{object.class} can not be converted to CONCAT arg")
97
+ raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
98
98
  end
99
99
  end
100
100
  end
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "1.2.12".freeze
2
+ VERSION = "1.2.17".freeze
3
3
  end
@@ -447,9 +447,9 @@ module ArelExtensions
447
447
  collector
448
448
  end
449
449
 
450
- # JSON if implemented only after 10.2.3 in MariaDb and 5.7 in MySql
450
+ # JSON if implemented only after 10.2.3 (aggregations after 10.5.0) in MariaDb and 5.7 (aggregations after 5.7.22) in MySql
451
451
  def json_supported?
452
- version_supported?('10.2.3', '5.7.0')
452
+ version_supported?('10.5.0', '5.7.22')
453
453
  end
454
454
 
455
455
  def window_supported?
@@ -257,6 +257,16 @@ module ArelExtensions
257
257
  collector = visit o.left, collector
258
258
  collector << ")"
259
259
  return collector
260
+ when :text
261
+ collector << "TO_CLOB("
262
+ collector = visit o.left, collector
263
+ collector << ")"
264
+ return collector
265
+ when :ntext
266
+ collector << "TO_NCLOB("
267
+ collector = visit o.left, collector
268
+ collector << ")"
269
+ return collector
260
270
  when :time
261
271
  if (o.left.respond_to?(:return_type) && o.left.return_type == :string) || o.left.is_a?(Arel::Nodes::Quoted)
262
272
  collector << "TO_DATE("
@@ -350,6 +350,8 @@ module ArelExtensions
350
350
  as_attr = case o.as_attr
351
351
  when :string
352
352
  Arel::Nodes::SqlLiteral.new('varchar')
353
+ when :text, :ntext
354
+ Arel::Nodes::SqlLiteral.new('text')
353
355
  when :time
354
356
  Arel::Nodes::SqlLiteral.new('time')
355
357
  when :int
@@ -364,16 +364,6 @@ module ArelExtensions
364
364
  collector
365
365
  end
366
366
 
367
-
368
- alias_method :old_visit_Arel_Nodes_SelectStatement, :visit_Arel_Nodes_SelectStatement
369
- def visit_Arel_Nodes_SelectStatement o, collector
370
- if !collector.value.blank? && o.limit.blank?
371
- o = o.dup
372
- o.orders = []
373
- end
374
- old_visit_Arel_Nodes_SelectStatement(o,collector)
375
- end
376
-
377
367
  alias_method :old_visit_Arel_Nodes_As, :visit_Arel_Nodes_As
378
368
  def visit_Arel_Nodes_As o, collector
379
369
  if o.left.is_a?(Arel::Nodes::Binary)
@@ -295,6 +295,8 @@ module ArelExtensions
295
295
  as_attr = Arel::Nodes::SqlLiteral.new('time')
296
296
  when :binary
297
297
  as_attr = Arel::Nodes::SqlLiteral.new('binary')
298
+ when :text, :ntext
299
+ as_attr = Arel::Nodes::SqlLiteral.new('text')
298
300
  else
299
301
  as_attr = Arel::Nodes::SqlLiteral.new(o.as_attr.to_s)
300
302
  end
@@ -585,6 +587,26 @@ module ArelExtensions
585
587
  collector
586
588
  end
587
589
 
590
+ def json_value(o,v)
591
+ case o.type_of_node(v)
592
+ when :string
593
+ Arel.when(v.is_null).then(Arel::Nodes.build_quoted("null")).else(Arel::Nodes.build_quoted('"') + v.replace('\\','\\\\').replace('"','\"') + '"')
594
+ when :date
595
+ s = v.format('%Y-%m-%d')
596
+ Arel.when(s.is_null).then(Arel::Nodes.build_quoted("null")).else(Arel::Nodes.build_quoted('"') + s + '"')
597
+ when :datetime
598
+ s = v.format('%Y-%m-%dT%H:%M:%S')
599
+ Arel.when(s.is_null).then(Arel::Nodes.build_quoted("null")).else(Arel::Nodes.build_quoted('"') + s + '"')
600
+ when :time
601
+ s = v.format('%H:%M:%S')
602
+ Arel.when(s.is_null).then(Arel::Nodes.build_quoted("null")).else(Arel::Nodes.build_quoted('"') + s + '"')
603
+ when :nil
604
+ Arel::Nodes.build_quoted("null")
605
+ else
606
+ ArelExtensions::Nodes::Cast.new([v, :string]).coalesce("null")
607
+ end
608
+ end
609
+
588
610
  def visit_ArelExtensions_Nodes_Json o,collector
589
611
  case o.dict
590
612
  when Array
@@ -593,11 +615,7 @@ module ArelExtensions
593
615
  if i != 0
594
616
  res += ', '
595
617
  end
596
- if (v.is_a?(Arel::Attributes::Attribute) && o.type_of_attribute(v) == :string) || (v.return_type == :string)
597
- res = res + '"' + v + '"'
598
- else
599
- res += v
600
- end
618
+ res += json_value(o,v)
601
619
  end
602
620
  res += ']'
603
621
  collector = visit res, collector
@@ -607,12 +625,8 @@ module ArelExtensions
607
625
  if i != 0
608
626
  res += ', '
609
627
  end
610
- res += Arel::Nodes.build_quoted('"')+k + '": '
611
- if (v.is_a?(Arel::Attributes::Attribute) && o.type_of_attribute(v) == :string) || (v.respond_to?(:return_type) && v.return_type == :string)
612
- res = res + '"' + v + '"'
613
- else
614
- res += v
615
- end
628
+ res += Arel::Nodes.build_quoted('"') + ArelExtensions::Nodes::Cast.new([k, :string]).coalesce("").replace('\\','\\\\').replace('"','\"') + '": '
629
+ res += json_value(o,v)
616
630
  end
617
631
  res += '}'
618
632
  collector = visit res, collector
@@ -624,7 +638,7 @@ module ArelExtensions
624
638
 
625
639
  def visit_ArelExtensions_Nodes_JsonGroup o, collector
626
640
  if o.as_array
627
- res = Arel::Nodes.build_quoted('[') + (o.orders ? o.dict.group_concat(', ',o.orders) : o.dict.group_concat(', ')) + ']'
641
+ res = Arel::Nodes.build_quoted('[') + (o.orders ? o.dict.group_concat(', ', order: Array(o.orders)) : o.dict.group_concat(', ')).coalesce('') + ']'
628
642
  collector = visit res, collector
629
643
  else
630
644
  res = Arel::Nodes.build_quoted('{')
@@ -633,13 +647,9 @@ module ArelExtensions
633
647
  if i != 0
634
648
  res = res + ', '
635
649
  end
636
- kv = Arel::Nodes.build_quoted('"')+k + '": '
637
- if (v.is_a?(Arel::Attributes::Attribute) && o.type_of_attribute(v) == :string) || (v.respond_to?(:return_type) && v.return_type == :string)
638
- kv = kv + '"' + v + '"'
639
- else
640
- kv += v
641
- end
642
- res = res + kv.group_concat(', ',orders)
650
+ kv = Arel::Nodes.build_quoted('"') + ArelExtensions::Nodes::Cast.new([k, :string]).coalesce("").replace('\\','\\\\').replace('"','\"') + '": '
651
+ kv += json_value(o,v)
652
+ res = res + kv.group_concat(', ', order: Array(orders)).coalesce('')
643
653
  end
644
654
  res = res + '}'
645
655
  collector = visit res, collector
@@ -21,7 +21,7 @@ def setup_db
21
21
  db.enable_load_extension(0)
22
22
  rescue => e
23
23
  $load_extension_disabled = true
24
- $stderr << "can not load extensions #{e.inspect}\n"
24
+ $stderr << "cannot load extensions #{e.inspect}\n"
25
25
  end
26
26
  end
27
27
  #function find_in_set
@@ -463,6 +463,13 @@ module ArelExtensions
463
463
  .must_be_like %{(LOCATE('test', "users"."name") + 1) ASC}
464
464
  end
465
465
 
466
+ it "should be possible to call Table function on TableAlias" do
467
+ t = @table
468
+ a = t.alias("aliased_users")
469
+ _(compile(a.join(t).join_sources))
470
+ .must_be_like %{INNER JOIN \"users\"}
471
+ end
472
+
466
473
  describe "logical functions" do
467
474
 
468
475
  it "should know about truth" do
@@ -356,6 +356,7 @@ module ArelExtensions
356
356
  assert_equal '2016-05-23', t(@lucas, @created_at.format('%Y-%m-%d'))
357
357
  skip "SQL Server does not accept any format" if @env_db == 'mssql'
358
358
  assert_equal '2014/03/03 12:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S'))
359
+ assert_equal '12:42%', t(@lucas, @updated_at.format('%R%%'))
359
360
  end
360
361
 
361
362
  def test_coalesce
@@ -581,6 +582,7 @@ module ArelExtensions
581
582
  # Case clause
582
583
  def test_case
583
584
  assert_equal 4, User.find_by_sql(@ut.project(@score.when(20.16).then(1).else(0).as('score_bin')).to_sql).sum(&:score_bin)
585
+ assert_equal 4, User.where(@score.when(20.16).then(1).else(0).eq(1)).count
584
586
  assert_equal 2, t(@arthur, @score.when(65.62,1).else(0)+1)
585
587
  assert_equal 0, t(@arthur, @score.when(65.62,1).else(0)-1)
586
588
  assert_equal "11", t(@arthur, @score.when(65.62).then("1").else("0")+"1")
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "1.2.12".freeze
2
+ VERSION = "1.2.17".freeze
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "2.0.8".freeze
2
+ VERSION = "2.0.13".freeze
3
3
  end
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.12
4
+ version: 1.2.17
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: 2020-04-30 00:00:00.000000000 Z
13
+ date: 2020-10-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: arel