arel_extensions 2.1.4 → 2.1.6

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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +162 -222
  3. data/.gitignore +7 -6
  4. data/.rubocop.yml +37 -0
  5. data/Gemfile +3 -3
  6. data/NEWS.md +15 -0
  7. data/README.md +119 -75
  8. data/appveyor.yml +82 -0
  9. data/arel_extensions.gemspec +0 -1
  10. data/gemfiles/rails3.gemfile +5 -5
  11. data/gemfiles/rails4_2.gemfile +38 -0
  12. data/gemfiles/{rails5_0.gemfile → rails5.gemfile} +6 -6
  13. data/gemfiles/rails5_1_4.gemfile +6 -6
  14. data/gemfiles/rails5_2.gemfile +6 -5
  15. data/gemfiles/rails6.gemfile +5 -4
  16. data/gemfiles/rails6_1.gemfile +5 -4
  17. data/gemfiles/rails7.gemfile +5 -4
  18. data/gemspecs/arel_extensions-v1.gemspec +0 -1
  19. data/gemspecs/arel_extensions-v2.gemspec +0 -1
  20. data/lib/arel_extensions/common_sql_functions.rb +2 -2
  21. data/lib/arel_extensions/helpers.rb +12 -12
  22. data/lib/arel_extensions/math.rb +32 -17
  23. data/lib/arel_extensions/nodes/case.rb +4 -3
  24. data/lib/arel_extensions/nodes/cast.rb +2 -2
  25. data/lib/arel_extensions/nodes/coalesce.rb +1 -1
  26. data/lib/arel_extensions/nodes/collate.rb +1 -1
  27. data/lib/arel_extensions/nodes/date_diff.rb +6 -6
  28. data/lib/arel_extensions/nodes/locate.rb +1 -1
  29. data/lib/arel_extensions/nodes/repeat.rb +2 -2
  30. data/lib/arel_extensions/nodes/rollup.rb +36 -0
  31. data/lib/arel_extensions/nodes/select.rb +10 -0
  32. data/lib/arel_extensions/nodes/substring.rb +1 -1
  33. data/lib/arel_extensions/nodes/then.rb +1 -1
  34. data/lib/arel_extensions/nodes/trim.rb +2 -2
  35. data/lib/arel_extensions/nodes/union.rb +3 -3
  36. data/lib/arel_extensions/nodes/union_all.rb +2 -2
  37. data/lib/arel_extensions/null_functions.rb +16 -0
  38. data/lib/arel_extensions/string_functions.rb +1 -0
  39. data/lib/arel_extensions/version.rb +1 -1
  40. data/lib/arel_extensions/visitors/ibm_db.rb +1 -1
  41. data/lib/arel_extensions/visitors/mssql.rb +123 -17
  42. data/lib/arel_extensions/visitors/mysql.rb +78 -11
  43. data/lib/arel_extensions/visitors/oracle.rb +39 -17
  44. data/lib/arel_extensions/visitors/postgresql.rb +17 -12
  45. data/lib/arel_extensions/visitors/sqlite.rb +4 -4
  46. data/lib/arel_extensions/visitors/to_sql.rb +4 -1
  47. data/lib/arel_extensions/visitors.rb +8 -0
  48. data/lib/arel_extensions.rb +26 -0
  49. data/test/arelx_test_helper.rb +1 -1
  50. data/test/real_db_test.rb +5 -5
  51. data/test/support/fake_record.rb +1 -1
  52. data/test/visitors/test_bulk_insert_oracle.rb +3 -3
  53. data/test/visitors/test_bulk_insert_sqlite.rb +1 -1
  54. data/test/visitors/test_bulk_insert_to_sql.rb +1 -1
  55. data/test/visitors/test_to_sql.rb +6 -6
  56. data/test/with_ar/all_agnostic_test.rb +177 -70
  57. data/test/with_ar/insert_agnostic_test.rb +3 -3
  58. data/test/with_ar/test_bulk_sqlite.rb +1 -1
  59. data/version_v1.rb +1 -1
  60. data/version_v2.rb +1 -1
  61. metadata +8 -18
  62. data/gemfiles/rails4.gemfile +0 -29
@@ -14,6 +14,52 @@ module ArelExtensions
14
14
  '%M' => '%i', '%S' => '%S', '%L' => '', '%N' => '%f', '%z' => ''
15
15
  }.freeze
16
16
 
17
+ # This helper method did not exist in rails < 5.2
18
+ if !Arel::Visitors::MySQL.method_defined?(:collect_nodes_for)
19
+ def collect_nodes_for(nodes, collector, spacer, connector = ", ")
20
+ if nodes&.any?
21
+ collector << spacer
22
+ inject_join nodes, collector, connector
23
+ end
24
+ end
25
+ end
26
+
27
+ # The whole purpose of this override is to fix the behavior of RollUp.
28
+ # All other databases treat RollUp sanely, execpt MySQL which requires
29
+ # that it figures as the last element of a GROUP BY.
30
+ def visit_Arel_Nodes_SelectCore(o, collector)
31
+ collector << "SELECT"
32
+
33
+ collector = collect_optimizer_hints(o, collector) if self.respond_to?(:collect_optimizer_hinsts)
34
+ collector = maybe_visit o.set_quantifier, collector
35
+
36
+ collect_nodes_for o.projections, collector, " "
37
+
38
+ if o.source && !o.source.empty?
39
+ collector << " FROM "
40
+ collector = visit o.source, collector
41
+ end
42
+
43
+ # The actual work
44
+ groups = o.groups
45
+ rollup = groups.select { |g| g.expr.class == Arel::Nodes::RollUp }.map { |r| r.expr.value }
46
+ if rollup && !rollup.empty?
47
+ groups = o.groups.reject { |g| g.expr.class == Arel::Nodes::RollUp }
48
+ groups << Arel::Nodes::RollUp.new(rollup)
49
+ end
50
+ # FIN
51
+
52
+ collect_nodes_for o.wheres, collector, " WHERE ", " AND "
53
+ collect_nodes_for groups, collector, " GROUP BY " # Look ma, I'm viring a group
54
+ collect_nodes_for o.havings, collector, " HAVING ", " AND "
55
+ collect_nodes_for o.windows, collector, " WINDOW "
56
+
57
+ if o.respond_to?(:comment)
58
+ maybe_visit o.comment, collector
59
+ else
60
+ collector
61
+ end
62
+ end
17
63
 
18
64
  # Math functions
19
65
  def visit_ArelExtensions_Nodes_Log10 o, collector
@@ -126,7 +172,7 @@ module ArelExtensions
126
172
  collector << 'CONCAT('
127
173
  o.expressions.each_with_index { |arg, i|
128
174
  collector << COMMA if i != 0
129
- if (arg.is_a?(Numeric)) || (arg.is_a?(Arel::Attributes::Attribute))
175
+ if arg.is_a?(Numeric) || arg.is_a?(Arel::Attributes::Attribute)
130
176
  collector << 'CAST('
131
177
  collector = visit arg, collector
132
178
  collector << ' AS char)'
@@ -138,6 +184,11 @@ module ArelExtensions
138
184
  collector
139
185
  end
140
186
 
187
+ def visit_Arel_Nodes_RollUp(o, collector)
188
+ visit o.expr, collector
189
+ collector << " WITH ROLLUP"
190
+ end
191
+
141
192
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
142
193
  collector << 'GROUP_CONCAT('
143
194
  collector = visit o.left, collector
@@ -201,7 +252,18 @@ module ArelExtensions
201
252
  end
202
253
 
203
254
  def visit_ArelExtensions_Nodes_Format o, collector
204
- case o.col_type
255
+ # One use case we met is
256
+ # `case…when…then(valid_date).else(Arel.null).format(…)`.
257
+ #
258
+ # In this case, `o.col_type` is `nil` but we have a legitimate type in
259
+ # the expression to be formatted. The following is a best effort to
260
+ # infer the proper type.
261
+ type =
262
+ o.col_type.nil? && !o.expressions[0].return_type.nil? \
263
+ ? o.expressions[0].return_type \
264
+ : o.col_type
265
+
266
+ case type
205
267
  when :date, :datetime, :time
206
268
  fmt = ArelExtensions::Visitors::strftime_to_format(o.iso_format, DATE_FORMAT_DIRECTIVES)
207
269
  collector << 'DATE_FORMAT('
@@ -398,15 +460,20 @@ module ArelExtensions
398
460
  Arel::Nodes::NamedFunction.new('FORMAT', [col.abs] + params)
399
461
  end
400
462
 
401
- repeated_char = (o.width == 0) ? Arel.quoted('') : ArelExtensions::Nodes::Case.new.
402
- when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0).
403
- then(Arel.quoted(
404
- o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
405
- ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
406
- ).
407
- else('')
408
- before = (!o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
409
- middle = (o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
463
+ repeated_char =
464
+ if o.width == 0
465
+ Arel.quoted('')
466
+ else
467
+ Arel
468
+ .when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0)
469
+ .then(Arel.quoted(
470
+ o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
471
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
472
+ )
473
+ .else('')
474
+ end
475
+ before = !o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
476
+ middle = o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
410
477
  after = o.flags.include?('-') ? repeated_char : ''
411
478
  full_number = ArelExtensions::Nodes::Concat.new([
412
479
  before,
@@ -11,7 +11,7 @@ module ArelExtensions
11
11
  '%H' => 'HH24', '%k' => '', '%I' => 'HH', '%l' => '', '%P' => 'am', '%p' => 'AM', # hours
12
12
  '%M' => 'MI', '%S' => 'SS', '%L' => 'MS', '%N' => 'US', '%z' => 'tz' # seconds, subseconds
13
13
  }
14
- NUMBER_COMMA_MAPPING = { 'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', ' }
14
+ NUMBER_COMMA_MAPPING = {'en_US' => '.,', 'fr_FR' => ',', 'sv_SE' => ', '}
15
15
 
16
16
  def visit_ArelExtensions_Nodes_Log10 o, collector
17
17
  collector << 'LOG('
@@ -126,6 +126,11 @@ module ArelExtensions
126
126
  collector
127
127
  end
128
128
 
129
+ def visit_Arel_Nodes_RollUp(o, collector)
130
+ collector << "ROLLUP"
131
+ grouping_array_or_grouping_element o, collector
132
+ end
133
+
129
134
  def visit_ArelExtensions_Nodes_GroupConcat o, collector
130
135
  collector << '(LISTAGG('
131
136
  collector = visit o.left, collector
@@ -455,7 +460,7 @@ module ArelExtensions
455
460
  src_tz, dst_tz = o.time_zone.first
456
461
  collector << ' as timestamp) at time zone '
457
462
  collector = visit Arel.quoted(src_tz), collector
458
- collecto < ' at time zone '
463
+ collector < ' at time zone '
459
464
  collector = visit Arel.quoted(dst_tz), collector
460
465
  when String
461
466
  collector << ' as timestamp) at time zone '
@@ -587,7 +592,7 @@ module ArelExtensions
587
592
  alias_method(:old_visit_Arel_Nodes_TableAlias, :visit_Arel_Nodes_TableAlias) rescue nil
588
593
  def visit_Arel_Nodes_TableAlias o, collector
589
594
  if o.name.length > 30
590
- o = Arel::Table.new(o.table_name).alias(Base64.urlsafe_encode64(Digest::MD5.new.digest(o.name)).tr('=', '').tr('-', '_'))
595
+ o = Arel::Table.new(o.table_name).alias(Arel.shorten(o.name))
591
596
  end
592
597
  old_visit_Arel_Nodes_TableAlias(o, collector)
593
598
  end
@@ -601,7 +606,7 @@ module ArelExtensions
601
606
  else
602
607
  collector = visit o.left, collector
603
608
  end
604
- quote = o.right.to_s =~ /(\A["].*["]\z)|\A[a-zA-Z_]*\z/ ? '' : '"'
609
+ quote = /(\A".*"\z)|\A[a-zA-Z_]*\z/.match?(o.right.to_s) ? '' : '"'
605
610
  collector << " AS #{quote}"
606
611
  collector = visit o.right, collector
607
612
  collector << "#{quote}"
@@ -627,10 +632,10 @@ module ArelExtensions
627
632
  comma_in_format = o.precision == 0 ? '' : 'D'
628
633
  nines_after = (1..o.precision - 1).map{'9'}.join('') + '0'
629
634
  if comma.length == 1
630
- options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '" + comma + " '")
635
+ options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '#{comma} '")
631
636
  nines_before = ('999' * 4 + '990')
632
637
  else
633
- options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '" + comma + "'")
638
+ options = Arel.quoted("NLS_NUMERIC_CHARACTERS = '#{comma}'")
634
639
  nines_before = ('999G' * 4 + '990')
635
640
  end
636
641
  sign = Arel.when(col < 0).
@@ -643,7 +648,7 @@ module ArelExtensions
643
648
  if o.scientific_notation
644
649
  number = Arel::Nodes::NamedFunction.new('TO_CHAR', [
645
650
  Arel.quoted(col.abs),
646
- Arel.quoted('FM' + nines_before + comma_in_format + nines_after + 'EEEE'),
651
+ Arel.quoted("FM#{nines_before}#{comma_in_format}#{nines_after}EEEE"),
647
652
  options
648
653
  ])
649
654
  if o.type == 'e'
@@ -652,20 +657,25 @@ module ArelExtensions
652
657
  else
653
658
  number = Arel::Nodes::NamedFunction.new('TO_CHAR', [
654
659
  Arel.quoted(col.abs),
655
- Arel.quoted('FM' + nines_before + comma_in_format + nines_after),
660
+ Arel.quoted("FM#{nines_before}#{comma_in_format}#{nines_after}"),
656
661
  options
657
662
  ])
658
663
  end
659
664
 
660
- repeated_char = (o.width == 0) ? Arel.quoted('') : ArelExtensions::Nodes::Case.new.
661
- when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0).
662
- then(Arel.quoted(
663
- o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
664
- ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
665
- ).
666
- else('')
667
- before = (!o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
668
- middle = (o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
665
+ repeated_char =
666
+ if o.width == 0
667
+ Arel.quoted('')
668
+ else
669
+ Arel
670
+ .when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0)
671
+ .then(Arel.quoted(
672
+ o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
673
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
674
+ )
675
+ .else('')
676
+ end
677
+ before = !o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
678
+ middle = o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
669
679
  after = o.flags.include?('-') ? repeated_char : ''
670
680
  full_number = ArelExtensions::Nodes::Concat.new([
671
681
  before,
@@ -700,6 +710,18 @@ module ArelExtensions
700
710
  collector << ')'
701
711
  collector
702
712
  end
713
+
714
+ # Utilized by GroupingSet, Cube & RollUp visitors to
715
+ # handle grouping aggregation semantics
716
+ def grouping_array_or_grouping_element(o, collector)
717
+ if o.expr.is_a? Array
718
+ collector << "( "
719
+ visit o.expr, collector
720
+ collector << " )"
721
+ else
722
+ visit o.expr, collector
723
+ end
724
+ end
703
725
  end
704
726
  end
705
727
  end
@@ -425,32 +425,37 @@ module ArelExtensions
425
425
  Arel::Nodes::NamedFunction.new('TRIM', [
426
426
  Arel::Nodes::NamedFunction.new('TO_CHAR', [
427
427
  Arel.when(col.not_eq 0).then(col.abs / Arel.quoted(10).pow(col.abs.log10.floor)).else(1),
428
- Arel.quoted('FM' + nines_before + '"' + comma + '"V' + nines_after)
428
+ Arel.quoted("FM#{nines_before}\"#{comma}\"V#{nines_after}")
429
429
  ])]),
430
430
  o.type,
431
431
  Arel::Nodes::NamedFunction.new('TRIM', [
432
432
  Arel::Nodes::NamedFunction.new('TO_CHAR', [
433
433
  Arel.when(col.not_eq 0).then(col.abs.log10.floor).else(0),
434
- Arel.quoted('FM' + nines_before)
434
+ Arel.quoted("FM#{nines_before}")
435
435
  ])])
436
436
  ])
437
437
  else
438
438
  Arel::Nodes::NamedFunction.new('TRIM', [
439
439
  Arel::Nodes::NamedFunction.new('TO_CHAR', [
440
440
  Arel.quoted(col.abs),
441
- Arel.quoted('FM' + nines_before + '"' + comma + '"V' + nines_after)
441
+ Arel.quoted("FM#{nines_before}\"#{comma}\"V#{nines_after}")
442
442
  ])])
443
443
  end
444
444
 
445
- repeated_char = (o.width == 0) ? Arel.quoted('') : ArelExtensions::Nodes::Case.new.
446
- when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0).
447
- then(Arel.quoted(
448
- o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
449
- ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
450
- ).
451
- else('')
452
- before = (!o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
453
- middle = (o.flags.include?('0')) && (!o.flags.include?('-')) ? repeated_char : ''
445
+ repeated_char =
446
+ if o.width == 0
447
+ Arel.quoted('')
448
+ else
449
+ Arel
450
+ .when(Arel.quoted(o.width).abs - (number.length + sign_length) > 0)
451
+ .then(Arel.quoted(
452
+ o.flags.include?('-') ? ' ' : (o.flags.include?('0') ? '0' : ' ')
453
+ ).repeat(Arel.quoted(o.width).abs - (number.length + sign_length))
454
+ )
455
+ .else('')
456
+ end
457
+ before = !o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
458
+ middle = o.flags.include?('0') && !o.flags.include?('-') ? repeated_char : ''
454
459
  after = o.flags.include?('-') ? repeated_char : ''
455
460
  full_number = ArelExtensions::Nodes::Concat.new([
456
461
  before,
@@ -325,16 +325,16 @@ module ArelExtensions
325
325
 
326
326
  def get_time_converted element
327
327
  if element.is_a?(Time)
328
- return Arel::Nodes::NamedFunction.new('STRFTIME', [element, '%H:%M:%S'])
328
+ Arel::Nodes::NamedFunction.new('STRFTIME', [element, '%H:%M:%S'])
329
329
  elsif element.is_a?(Arel::Attributes::Attribute)
330
330
  col = Arel.column_of(element.relation.table_name, element.name.to_s)
331
331
  if col && (col.type == :time)
332
- return Arel::Nodes::NamedFunction.new('STRFTIME', [element, '%H:%M:%S'])
332
+ Arel::Nodes::NamedFunction.new('STRFTIME', [element, '%H:%M:%S'])
333
333
  else
334
- return element
334
+ element
335
335
  end
336
336
  else
337
- return element
337
+ element
338
338
  end
339
339
  end
340
340
 
@@ -649,7 +649,10 @@ module ArelExtensions
649
649
 
650
650
  def visit_ArelExtensions_Nodes_JsonGroup o, collector
651
651
  if o.as_array
652
- res = Arel.quoted('[') + (o.orders ? o.dict.group_concat(', ', order: Array(o.orders)) : o.dict.group_concat(', ')).coalesce('') + ']'
652
+ res =
653
+ Arel.quoted('[') \
654
+ + (o.orders ? o.dict.group_concat(', ', order: Array(o.orders)) : o.dict.group_concat(', ')).coalesce('') \
655
+ + ']'
653
656
  collector = visit res, collector
654
657
  else
655
658
  res = Arel.quoted('{')
@@ -19,6 +19,14 @@ if defined?(Arel::Visitors::SQLServer)
19
19
  end
20
20
  end
21
21
 
22
+ if defined?(Arel::Visitors::DepthFirst)
23
+ class Arel::Visitors::DepthFirst
24
+ def visit_Arel_SelectManager o
25
+ visit o.ast
26
+ end
27
+ end
28
+ end
29
+
22
30
  if defined?(Arel::Visitors::MSSQL)
23
31
  class Arel::Visitors::MSSQL
24
32
  include ArelExtensions::Visitors::MSSQL
@@ -1,4 +1,5 @@
1
1
  require 'arel'
2
+ require 'base64'
2
3
 
3
4
  require 'arel_extensions/railtie' if defined?(Rails::Railtie)
4
5
 
@@ -77,6 +78,8 @@ require 'arel_extensions/nodes/case'
77
78
  require 'arel_extensions/nodes/soundex'
78
79
  require 'arel_extensions/nodes/cast'
79
80
  require 'arel_extensions/nodes/json'
81
+ require 'arel_extensions/nodes/rollup'
82
+ require 'arel_extensions/nodes/select'
80
83
 
81
84
  # It seems like the code in lib/arel_extensions/visitors.rb that is supposed
82
85
  # to inject ArelExtension is not enough. Different versions of the sqlserver
@@ -131,6 +134,10 @@ module Arel
131
134
  ArelExtensions::Nodes::Rand.new
132
135
  end
133
136
 
137
+ def self.rollup(*args)
138
+ Arel::Nodes::RollUp.new(args)
139
+ end
140
+
134
141
  def self.shorten s
135
142
  Base64.urlsafe_encode64(Digest::MD5.new.digest(s)).tr('=', '').tr('-', '_')
136
143
  end
@@ -268,3 +275,22 @@ class Arel::Nodes::TableAlias
268
275
  end
269
276
  end
270
277
  end
278
+
279
+
280
+ class Arel::Attributes::Attribute
281
+ def to_sql(engine = Arel::Table.engine)
282
+ collector = Arel::Collectors::SQLString.new
283
+ collector = engine.connection.visitor.accept self, collector
284
+ collector.value
285
+ end
286
+
287
+ def rollup
288
+ Arel::Nodes::RollUp.new([self])
289
+ end
290
+ end
291
+
292
+ class Arel::Nodes::Node
293
+ def rollup
294
+ Arel::Nodes::RollUp.new([self])
295
+ end
296
+ end
@@ -7,7 +7,7 @@ require 'active_record'
7
7
  require 'support/fake_record'
8
8
 
9
9
  def colored(color, msg)
10
- ENV['TERM'] =~ /^xterm|-256color$/ ? "\x1b[#{color}m#{msg}\x1b[89m\x1b[0m" : "#{msg}"
10
+ /^xterm|-256color$/.match?(ENV['TERM']) ? "\x1b[#{color}m#{msg}\x1b[89m\x1b[0m" : "#{msg}"
11
11
  end
12
12
 
13
13
  YELLOW = '33'
data/test/real_db_test.rb CHANGED
@@ -14,7 +14,7 @@ def setup_db
14
14
  ActiveRecord::Base.default_timezone = :utc
15
15
  end
16
16
  @cnx = ActiveRecord::Base.connection
17
- if ActiveRecord::Base.connection.adapter_name =~ /sqlite/i
17
+ if /sqlite/i.match?(ActiveRecord::Base.connection.adapter_name)
18
18
  $sqlite = true
19
19
  db = @cnx.raw_connection
20
20
  if !$load_extension_disabled
@@ -82,7 +82,7 @@ class ListTest < Minitest::Test
82
82
  end
83
83
 
84
84
  def test_coalesce
85
- if @cnx.adapter_name =~ /pgsql/i
85
+ if /pgsql/i.match?(@cnx.adapter_name)
86
86
  assert_equal 100, User.where(User.arel_table[:name].eq('Test')).select((User.arel_table[:age].coalesce(100)).as('res')).first.res
87
87
  assert_equal 'Camille', User.where(User.arel_table[:name].eq('Camille')).select((User.arel_table[:name].coalesce('Null', 'default')).as('res')).first.res
88
88
  else
@@ -128,7 +128,7 @@ class ListTest < Minitest::Test
128
128
  end
129
129
 
130
130
  def test_isnull
131
- if ActiveRecord::Base.connection.adapter_name =~ /pgsql/i
131
+ if /pgsql/i.match?(ActiveRecord::Base.connection.adapter_name)
132
132
  assert_equal 100, User.where(User.arel_table[:name].eq('Test')).select((User.arel_table[:age].isnull(100)).as('res')).first.res
133
133
  else
134
134
  assert_equal 'default', User.where(User.arel_table[:name].eq('Test')).select((User.arel_table[:age].isnull('default')).as('res')).first.res
@@ -196,8 +196,8 @@ class ListTest < Minitest::Test
196
196
  end
197
197
 
198
198
  def test_replace
199
- assert_equal 'LucaX', User.where(User.arel_table[:name].eq('Lucas')).select(((User.arel_table[:name]).replace('s', 'X')).as('res')).first.res
200
- assert_equal 'replace', User.where(User.arel_table[:name].eq('Lucas')).select(((User.arel_table[:name]).replace(User.arel_table[:name], 'replace')).as('res')).first.res
199
+ assert_equal 'LucaX', User.where(User.arel_table[:name].eq('Lucas')).select((User.arel_table[:name].replace('s', 'X')).as('res')).first.res
200
+ assert_equal 'replace', User.where(User.arel_table[:name].eq('Lucas')).select((User.arel_table[:name].replace(User.arel_table[:name], 'replace')).as('res')).first.res
201
201
  end
202
202
 
203
203
  def test_round
@@ -66,7 +66,7 @@ module FakeRecord
66
66
  end
67
67
 
68
68
  def in_clause_length
69
- 10000
69
+ 10_000
70
70
  end
71
71
 
72
72
  def quote thing, column = nil
@@ -7,10 +7,10 @@ module ArelExtensions
7
7
  @conn = FakeRecord::Base.new
8
8
  @visitor = Arel::Visitors::Oracle.new @conn.connection
9
9
  @table = Arel::Table.new(:users)
10
- @cols = ['name', 'comments', 'created_at']
10
+ @cols = %w[name comments created_at]
11
11
  @data = [
12
- ['nom1', 'sdfdsfdsfsdf', '2016-01-01'],
13
- ['nom2', 'sdfdsfdsfsdf', '2016-01-01']
12
+ %w[nom1 sdfdsfdsfsdf 2016-01-01],
13
+ %w[nom2 sdfdsfdsfsdf 2016-01-01]
14
14
  ]
15
15
  end
16
16
 
@@ -8,7 +8,7 @@ module ArelExtensions
8
8
  @visitor = Arel::Visitors::SQLite.new @conn.connection
9
9
  @table = Arel::Table.new(:users)
10
10
  Arel::Table.engine = @conn
11
- @cols = ['id', 'name', 'comments', 'created_at']
11
+ @cols = %w[id name comments created_at]
12
12
  @data = [
13
13
  [23, 'nom1', 'sdfdsfdsfsdf', '2016-01-01'],
14
14
  [25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
@@ -8,7 +8,7 @@ module ArelExtensions
8
8
  Arel::Table.engine = @conn
9
9
  @visitor = Arel::Visitors::ToSql.new @conn.connection
10
10
  @table = Arel::Table.new(:users)
11
- @cols = ['id', 'name', 'comments', 'created_at']
11
+ @cols = %w[id name comments created_at]
12
12
  @data = [
13
13
  [23, 'nom1', 'sdfdsfdsfsdf', '2016-01-01'],
14
14
  [25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
@@ -11,7 +11,7 @@ module ArelExtensions
11
11
  # test become flaky.
12
12
  #
13
13
  # The first time `Arel::Table.engine` is called
14
- # from `ArelExtenstions::column_of_via_arel_table(table_name, column_name)`
14
+ # from `ArelExtensions.column_of_via_arel_table(table_name, column_name)`
15
15
  # in `lib/arel_extensions/helpers.rb`
16
16
  # will almost always fail. It's important to note that when the test
17
17
  # fails, it's always on 1 test case, and every subsequent test that
@@ -273,13 +273,13 @@ module ArelExtensions
273
273
  c = @table.project(@table[:name])
274
274
  _(compile(c.union_all(c)))
275
275
  .must_be_like %{(SELECT "users"."name" FROM "users") UNION ALL (SELECT "users"."name" FROM "users")}
276
- _((c.union_all(c)).to_sql)
276
+ _(c.union_all(c).to_sql)
277
277
  .must_be_like %{(SELECT "users"."name" FROM "users") UNION ALL (SELECT "users"."name" FROM "users")}
278
- _((c.union_all(c.union_all(c))).to_sql)
278
+ _(c.union_all(c.union_all(c)).to_sql)
279
279
  .must_be_like %{(SELECT "users"."name" FROM "users") UNION ALL (SELECT "users"."name" FROM "users") UNION ALL (SELECT "users"."name" FROM "users")}
280
- _(((c.union_all(c)).union_all(c)).to_sql)
280
+ _((c.union_all(c)).union_all(c).to_sql)
281
281
  .must_be_like %{(SELECT "users"."name" FROM "users") UNION ALL (SELECT "users"."name" FROM "users") UNION ALL (SELECT "users"."name" FROM "users")}
282
- _((c.union_all(c).union_all(c)).to_sql)
282
+ _(c.union_all(c).union_all(c).to_sql)
283
283
  .must_be_like %{(SELECT "users"."name" FROM "users") UNION ALL (SELECT "users"."name" FROM "users") UNION ALL (SELECT "users"."name" FROM "users")}
284
284
  _((c.union_all(c)).as('union_table').to_sql)
285
285
  .must_be_like %{((SELECT "users"."name" FROM "users") UNION ALL (SELECT "users"."name" FROM "users")) union_table}
@@ -576,7 +576,7 @@ module ArelExtensions
576
576
  end
577
577
  end
578
578
 
579
- puts 'AREL VERSION : ' + Arel::VERSION.to_s
579
+ puts "AREL VERSION: #{Arel::VERSION}"
580
580
  end
581
581
  end
582
582
  end