arel_extensions 2.1.4 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +41 -89
  3. data/.gitignore +7 -6
  4. data/.rubocop.yml +37 -0
  5. data/Gemfile +3 -3
  6. data/README.md +1 -0
  7. data/appveyor.yml +73 -0
  8. data/gemfiles/rails3.gemfile +5 -5
  9. data/gemfiles/rails4.gemfile +7 -7
  10. data/gemfiles/rails5_0.gemfile +6 -6
  11. data/gemfiles/rails5_1_4.gemfile +6 -6
  12. data/gemfiles/rails5_2.gemfile +6 -5
  13. data/gemfiles/rails6.gemfile +5 -4
  14. data/gemfiles/rails6_1.gemfile +5 -4
  15. data/gemfiles/rails7.gemfile +5 -4
  16. data/lib/arel_extensions/common_sql_functions.rb +2 -2
  17. data/lib/arel_extensions/helpers.rb +12 -12
  18. data/lib/arel_extensions/math.rb +32 -17
  19. data/lib/arel_extensions/nodes/cast.rb +2 -2
  20. data/lib/arel_extensions/nodes/coalesce.rb +1 -1
  21. data/lib/arel_extensions/nodes/collate.rb +1 -1
  22. data/lib/arel_extensions/nodes/date_diff.rb +6 -6
  23. data/lib/arel_extensions/nodes/locate.rb +1 -1
  24. data/lib/arel_extensions/nodes/repeat.rb +2 -2
  25. data/lib/arel_extensions/nodes/substring.rb +1 -1
  26. data/lib/arel_extensions/nodes/then.rb +1 -1
  27. data/lib/arel_extensions/nodes/trim.rb +2 -2
  28. data/lib/arel_extensions/nodes/union.rb +3 -3
  29. data/lib/arel_extensions/nodes/union_all.rb +2 -2
  30. data/lib/arel_extensions/version.rb +1 -1
  31. data/lib/arel_extensions/visitors/ibm_db.rb +1 -1
  32. data/lib/arel_extensions/visitors/mssql.rb +30 -17
  33. data/lib/arel_extensions/visitors/mysql.rb +15 -10
  34. data/lib/arel_extensions/visitors/oracle.rb +22 -17
  35. data/lib/arel_extensions/visitors/postgresql.rb +17 -12
  36. data/lib/arel_extensions/visitors/sqlite.rb +4 -4
  37. data/lib/arel_extensions/visitors/to_sql.rb +4 -1
  38. data/lib/arel_extensions.rb +10 -0
  39. data/test/arelx_test_helper.rb +1 -1
  40. data/test/real_db_test.rb +5 -5
  41. data/test/support/fake_record.rb +1 -1
  42. data/test/visitors/test_bulk_insert_oracle.rb +3 -3
  43. data/test/visitors/test_bulk_insert_sqlite.rb +1 -1
  44. data/test/visitors/test_bulk_insert_to_sql.rb +1 -1
  45. data/test/visitors/test_to_sql.rb +6 -6
  46. data/test/with_ar/all_agnostic_test.rb +67 -60
  47. data/test/with_ar/insert_agnostic_test.rb +3 -3
  48. data/test/with_ar/test_bulk_sqlite.rb +1 -1
  49. data/version_v1.rb +1 -1
  50. data/version_v2.rb +1 -1
  51. metadata +3 -2
@@ -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
@@ -193,16 +193,16 @@ module ArelExtensions
193
193
  assert_equal 'Test Laure', t(@laure, Arel.quoted('Test ') + @name)
194
194
 
195
195
  skip 'No group_concat in SqlServer before 2017' if @env_db == 'mssql'
196
- assert_equal 'Lucas Sophie', t(User.where(name: ['Lucas', 'Sophie']), @name.group_concat(' '))
197
- assert_equal 'Lucas,Sophie', t(User.where(name: ['Lucas', 'Sophie']), @name.group_concat(','))
198
- assert_equal 'Lucas,Sophie', t(User.where(name: ['Lucas', 'Sophie']), @name.group_concat)
196
+ assert_equal 'Lucas Sophie', t(User.where(name: %w[Lucas Sophie]), @name.group_concat(' '))
197
+ assert_equal 'Lucas,Sophie', t(User.where(name: %w[Lucas Sophie]), @name.group_concat(','))
198
+ assert_equal 'Lucas,Sophie', t(User.where(name: %w[Lucas Sophie]), @name.group_concat)
199
199
 
200
200
  skip 'No order in group_concat in SqlLite' if $sqlite
201
- assert_equal 'Arthur,Lucas,Sophie', t(User.where(name: ['Lucas', 'Sophie', 'Arthur']), @name.group_concat(',', @name.asc))
202
- assert_equal 'Sophie,Lucas,Arthur', t(User.where(name: ['Lucas', 'Sophie', 'Arthur']), @name.group_concat(',', @name.desc))
203
- assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: ['Lucas', 'Sophie', 'Arthur']), @name.group_concat(',', [@score.asc, @name.asc]))
204
- assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: ['Lucas', 'Sophie', 'Arthur']), @name.group_concat(',', @score.asc, @name.asc))
205
- assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: ['Lucas', 'Sophie', 'Arthur']), @name.group_concat(',', order: [@score.asc, @name.asc]))
201
+ assert_equal 'Arthur,Lucas,Sophie', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', @name.asc))
202
+ assert_equal 'Sophie,Lucas,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', @name.desc))
203
+ assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', [@score.asc, @name.asc]))
204
+ assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', @score.asc, @name.asc))
205
+ assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', order: [@score.asc, @name.asc]))
206
206
  end
207
207
 
208
208
  def test_length
@@ -419,27 +419,32 @@ module ArelExtensions
419
419
  }
420
420
  }
421
421
 
422
- skip "Unsupported timezone conversion for DB=#{ENV['DB']}" if !['mssql', 'mysql', 'oracle', 'postgresql'].include?(ENV['DB'])
422
+ skip "Unsupported timezone conversion for DB=#{ENV['DB']}" if !%w[mssql mysql oracle postgresql].include?(ENV['DB'])
423
+ # TODO: Standarize timezone conversion across all databases.
424
+ # This test case will be refactored and should work the same across all vendors.
425
+ if ENV['DB'] == 'mssql' && /Microsoft SQL Server (\d+)/.match(ActiveRecord::Base.connection.select_value('SELECT @@version'))[1].to_i < 2016
426
+ skip "SQL Server < 2016 is not currently supported"
427
+ end
423
428
 
424
429
  tz = ENV['DB'] == 'mssql' ? time_zones['mssql'] : time_zones['posix']
425
430
 
426
431
  assert_equal '2014/03/03 12:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S', tz['utc']))
427
- assert_equal '2014/03/03 09:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S', { tz['utc'] => tz['sao_paulo'] }))
428
- assert_equal '2014/03/03 02:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S', { tz['utc'] => tz['tahiti'] }))
432
+ assert_equal '2014/03/03 09:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['sao_paulo']}))
433
+ assert_equal '2014/03/03 02:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['tahiti']}))
429
434
 
430
435
  # Skipping conversion from UTC to the desired timezones fails in SQL
431
436
  # Server and Postgres. This is mainly due to the fact that timezone
432
437
  # information is not preserved in the column itself.
433
438
  #
434
439
  # MySQL is happy to consider that times by default are in UTC.
435
- assert_equal '2014/03/03 13:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S', { tz['utc'] => tz['paris'] }))
440
+ assert_equal '2014/03/03 13:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
436
441
  refute_equal '2014/03/03 13:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S', tz['paris'])) if !['mysql'].include?(ENV['DB'])
437
442
 
438
443
  # Winter/Summer time
439
- assert_equal '2014/08/03 14:42:00', t(@lucas, (@updated_at + 5.months).format('%Y/%m/%d %H:%M:%S', { tz['utc'] => tz['paris'] }))
444
+ assert_equal '2014/08/03 14:42:00', t(@lucas, (@updated_at + 5.months).format('%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
440
445
  if ENV['DB'] == 'mssql'
441
- assert_equal '2022/02/01 11:42:00', t(@lucas, Arel.quoted('2022-02-01 10:42:00').cast(:datetime).format('%Y/%m/%d %H:%M:%S', { tz['utc'] => tz['paris'] }))
442
- assert_equal '2022/08/01 12:42:00', t(@lucas, Arel.quoted('2022-08-01 10:42:00').cast(:datetime).format('%Y/%m/%d %H:%M:%S', { tz['utc'] => tz['paris'] }))
446
+ assert_equal '2022/02/01 11:42:00', t(@lucas, Arel.quoted('2022-02-01 10:42:00').cast(:datetime).format('%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
447
+ assert_equal '2022/08/01 12:42:00', t(@lucas, Arel.quoted('2022-08-01 10:42:00').cast(:datetime).format('%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
443
448
  else
444
449
  assert_equal '2022/02/01 11:42:00', t(@lucas, Arel.quoted('2022-02-01 10:42:00').cast(:datetime).format('%Y/%m/%d %H:%M:%S', tz['paris']))
445
450
  assert_equal '2022/08/01 12:42:00', t(@lucas, Arel.quoted('2022-08-01 10:42:00').cast(:datetime).format('%Y/%m/%d %H:%M:%S', tz['paris']))
@@ -463,7 +468,7 @@ module ArelExtensions
463
468
  end
464
469
 
465
470
  def test_format_iso_year_of_week
466
- skip "Unsupported ISO year of week for DB=#{ENV['DB']}" if ['mssql', 'sqlite'].include?(ENV['DB'])
471
+ skip "Unsupported ISO year of week for DB=#{ENV['DB']}" if %w[mssql sqlite].include?(ENV['DB'])
467
472
  assert_equal '2014', t(@lucas, @updated_at.format('%G'))
468
473
 
469
474
  {
@@ -480,7 +485,7 @@ module ArelExtensions
480
485
  end
481
486
 
482
487
  def test_format_date_with_names
483
- skip "#{ENV['DB']} does not support a variety of word-based formatting for month and day names" if ['mssql'].include?(ENV['DB'])
488
+ skip "#{ENV['DB']} does not support a variety of word-based formatting for month and day names" if %w[mssql sqlite].include?(ENV['DB'])
484
489
  assert_equal 'Mon, 03 Mar 14', t(@lucas, @updated_at.format('%a, %d %b %y'))
485
490
  assert_equal 'Monday, 03 March 14', t(@lucas, @updated_at.format('%A, %d %B %y'))
486
491
 
@@ -491,9 +496,9 @@ module ArelExtensions
491
496
 
492
497
  def switch_to_lang(lang)
493
498
  languages = {
494
- 'mssql' => { :en => 'English', :fr => 'French' },
495
- 'mysql' => { :en => 'en_US', :fr => 'fr_FR' },
496
- 'postgresql' => { :en => 'en_US.utf8', :fr => 'fr_FR.utf8' }
499
+ 'mssql' => {en: 'English', fr: 'French'},
500
+ 'mysql' => {en: 'en_US', fr: 'fr_FR'},
501
+ 'postgresql' => {en: 'en_US.utf8', fr: 'fr_FR.utf8'}
497
502
  }
498
503
 
499
504
  sql = {
@@ -513,27 +518,29 @@ module ArelExtensions
513
518
  #
514
519
  # Tests should assert one single thing in principle, but until we
515
520
  # refactor this whole thing, we'll have to do tricks of this sort.
516
- switch_to_lang(:en)
517
- case ENV['DB']
518
- when 'mysql', 'postgresql'
519
- assert_equal 'Mon, 03 Mar 14', t(@lucas, @updated_at.format('%a, %d %b %y'))
520
- assert_equal 'Monday, 03 March 14', t(@lucas, @updated_at.format('%A, %d %B %y'))
521
- when 'mssql'
522
- assert_equal 'Monday, 03 March 2014', t(@lucas, @updated_at.format('%A, %d %B %y'))
523
- end
524
- switch_to_lang(:fr)
525
- case ENV['DB']
526
- when 'mysql'
527
- assert_equal 'lun, 03 mar 14', t(@lucas, @updated_at.format('%a, %d %b %y'))
528
- assert_equal 'lundi, 03 mars 14', t(@lucas, @updated_at.format('%A, %d %B %y'))
529
- when 'postgresql'
530
- assert_equal 'Lun., 03 Mars 14', t(@lucas, @updated_at.format('%a, %d %b %y'))
531
- assert_equal 'Lundi, 03 Mars 14', t(@lucas, @updated_at.format('%A, %d %B %y'))
532
- when 'mssql'
533
- assert_equal 'lundi, 03 mars 2014', t(@lucas, @updated_at.format('%A, %d %B %y'))
521
+ begin
522
+ switch_to_lang(:en)
523
+ case ENV['DB']
524
+ when 'mysql', 'postgresql'
525
+ assert_equal 'Mon, 03 Mar 14', t(@lucas, @updated_at.format('%a, %d %b %y'))
526
+ assert_equal 'Monday, 03 March 14', t(@lucas, @updated_at.format('%A, %d %B %y'))
527
+ when 'mssql'
528
+ assert_equal 'Monday, 03 March 2014', t(@lucas, @updated_at.format('%A, %d %B %y'))
529
+ end
530
+ switch_to_lang(:fr)
531
+ case ENV['DB']
532
+ when 'mysql'
533
+ assert_equal 'lun, 03 mar 14', t(@lucas, @updated_at.format('%a, %d %b %y'))
534
+ assert_equal 'lundi, 03 mars 14', t(@lucas, @updated_at.format('%A, %d %B %y'))
535
+ when 'postgresql'
536
+ assert_equal 'Lun., 03 Mars 14', t(@lucas, @updated_at.format('%a, %d %b %y'))
537
+ assert_equal 'Lundi, 03 Mars 14', t(@lucas, @updated_at.format('%A, %d %B %y'))
538
+ when 'mssql'
539
+ assert_equal 'lundi, 03 mars 2014', t(@lucas, @updated_at.format('%A, %d %B %y'))
540
+ end
541
+ ensure
542
+ switch_to_lang(:en)
534
543
  end
535
- ensure
536
- switch_to_lang(:en)
537
544
  end
538
545
 
539
546
  def test_coalesce
@@ -602,8 +609,8 @@ module ArelExtensions
602
609
  def test_datetime_diff
603
610
  assert_equal 0, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 12, 42)).to_i
604
611
  if @env_db == 'oracle' && Arel::VERSION.to_i > 6 # in rails 5, result is multiplied by 24*60*60 = 86400...
605
- assert_equal 42 * 86400, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 12, 41, 18)).to_i
606
- assert_equal(-3600 * 86400, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 13, 42)).to_i)
612
+ assert_equal 42 * 86_400, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 12, 41, 18)).to_i
613
+ assert_equal(-3600 * 86_400, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 13, 42)).to_i)
607
614
  else
608
615
  assert_equal 42, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 12, 41, 18)).to_i
609
616
  assert_equal(-3600, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 13, 42)).to_i)
@@ -658,12 +665,12 @@ module ArelExtensions
658
665
  # TODO; cast types
659
666
  def test_cast_types
660
667
  assert_equal '5', t(@lucas, @age.cast(:string))
661
- skip 'jdbc adapters does not work properly here (v52 works fine)' if RUBY_PLATFORM =~ /java/i
668
+ skip 'jdbc adapters does not work properly here (v52 works fine)' if RUBY_PLATFORM.match?(/java/i)
662
669
  if @env_db == 'mysql' || @env_db == 'postgresql' || @env_db == 'oracle' || @env_db == 'mssql'
663
670
  assert_equal 1, t(@laure, Arel.when(@duration.cast(:time).cast(:string).eq('12:42:21')).then(1).else(0)) unless @env_db == 'oracle' || @env_db == 'mssql'
664
671
  assert_equal 1, t(@laure, Arel.when(@duration.cast(:time).eq('12:42:21')).then(1).else(0)) unless @env_db == 'oracle'
665
- assert_equal '20.16', t(@laure, @score.cast(:string)).gsub(/[0]*\z/, '')
666
- assert_equal '20.161', t(@laure, @score.cast(:string) + 1).gsub(/[0]*1\z/, '1')
672
+ assert_equal '20.16', t(@laure, @score.cast(:string)).gsub(/0*\z/, '')
673
+ assert_equal '20.161', t(@laure, @score.cast(:string) + 1).gsub(/0*1\z/, '1')
667
674
  assert_equal 21.16, t(@laure, @score.cast(:string).cast(:decimal) + 1)
668
675
  assert_equal 21, t(@laure, @score.cast(:string).cast(:int) + 1)
669
676
 
@@ -747,8 +754,8 @@ module ArelExtensions
747
754
  assert_equal 3, User.select('*').from((@ut.project(@age).where(@age.eq(20)) + @ut.project(@age).where(@age.eq(23)) + @ut.project(@age).where(@age.eq(21))).as('my_union')).length
748
755
  assert_equal 2, User.select('*').from((@ut.project(@age).where(@age.eq(20)) + @ut.project(@age).where(@age.eq(20)) + @ut.project(@age).where(@age.eq(21))).as('my_union')).length
749
756
 
750
- assert_equal 3, User.find_by_sql((@ut.project(@age).where(@age.gt(22)).union_all(@ut.project(@age).where(@age.lt(0)))).to_sql).length
751
- assert_equal 3, User.find_by_sql((@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(20))).union_all(@ut.project(@age).where(@age.eq(21)))).to_sql).length
757
+ assert_equal 3, User.find_by_sql(@ut.project(@age).where(@age.gt(22)).union_all(@ut.project(@age).where(@age.lt(0))).to_sql).length
758
+ assert_equal 3, User.find_by_sql(@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(20))).union_all(@ut.project(@age).where(@age.eq(21))).to_sql).length
752
759
  assert_equal 3, User.select('*').from((@ut.project(@age).where(@age.gt(22)).union_all(@ut.project(@age).where(@age.lt(0)))).as('my_union')).length
753
760
  assert_equal 3, User.select('*').from((@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(23))).union_all(@ut.project(@age).where(@age.eq(21)))).as('my_union')).length
754
761
  assert_equal 3, User.select('*').from((@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(20))).union_all(@ut.project(@age).where(@age.eq(21)))).as('my_union')).length
@@ -786,10 +793,10 @@ module ArelExtensions
786
793
  assert_includes ['$ 6,56e1 €', '$ 6,56e+01 €'], t(@arthur, @score.format_number('$ %.2e €', 'fr_FR'))
787
794
  assert_includes ['$ 6,56E1 €', '$ 6,56E+01 €'], t(@arthur, @score.format_number('$ %.2E €', 'fr_FR'))
788
795
  assert_includes ['$ 6,562E1 €', '$ 6,562E+01 €'], t(@arthur, @score.format_number('$ %.3E €', 'fr_FR'))
789
- assert_equal '123 456 765,6', t(@arthur, (@score + 123456700).format_number('%.1f', 'sv_SE')).gsub("\u00A0", ' ') # some DBMS put no-break space here (it makes sense thus)
790
- assert_equal '123456765,6', t(@arthur, (@score + 123456700).format_number('%.1f', 'fr_FR')).gsub("\u00A0", '') # because SqlServer does it like no one else
791
- assert_equal '123,456,765.6', t(@arthur, (@score + 123456700).format_number('%.1f', 'en_US'))
792
- assert_equal ' 123,456,765.6', t(@arthur, (@score + 123456700).format_number('%16.1f', 'en_US'))
796
+ assert_equal '123 456 765,6', t(@arthur, (@score + 123_456_700).format_number('%.1f', 'sv_SE')).tr("\u00A0", ' ') # some DBMS put no-break space here (it makes sense thus)
797
+ assert_equal '123456765,6', t(@arthur, (@score + 123_456_700).format_number('%.1f', 'fr_FR')).delete("\u00A0") # because SqlServer does it like no one else
798
+ assert_equal '123,456,765.6', t(@arthur, (@score + 123_456_700).format_number('%.1f', 'en_US'))
799
+ assert_equal ' 123,456,765.6', t(@arthur, (@score + 123_456_700).format_number('%16.1f', 'en_US'))
793
800
  assert_equal '$ 0,00 €', t(@arthur, @score.when(65.62).then(Arel.sql('null')).else(1).format_number('$ %.2f €', 'fr_FR'))
794
801
  assert_equal '$ 0,00 €', t(@arthur, (@score - 65.62).format_number('$ %.2f €', 'fr_FR'))
795
802
  end
@@ -811,7 +818,7 @@ module ArelExtensions
811
818
  assert_equal '1', t(@arthur, Arel.when(@comments.ai_matches('arrete')).then('1').else('0'))
812
819
  assert_equal '1', t(@arthur, Arel.when(@comments.ai_matches('àrrétè')).then('1').else('0'))
813
820
  assert_equal '0', t(@arthur, Arel.when(@comments.ai_matches('arretez')).then('1').else('0'))
814
- if !['oracle', 'postgresql', 'mysql'].include?(@env_db) # AI => CI
821
+ if !%w[oracle postgresql mysql].include?(@env_db) # AI => CI
815
822
  assert_equal '0', t(@arthur, Arel.when(@comments.ai_matches('Arrete')).then('1').else('0'))
816
823
  assert_equal '0', t(@arthur, Arel.when(@comments.ai_matches('Arrêté')).then('1').else('0'))
817
824
  end
@@ -915,7 +922,7 @@ module ArelExtensions
915
922
  end
916
923
 
917
924
  def test_alias_shortened
918
- if ['postgresql', 'oracle'].include?(@env_db)
925
+ if %w[postgresql oracle].include?(@env_db)
919
926
  new_alias = Arel.shorten('azerty' * 15)
920
927
  at = User.arel_table.alias('azerty' * 15)
921
928
  assert_equal "\"user_tests\" \"#{new_alias}\"".downcase, User.arel_table.alias('azerty' * 15).to_sql.downcase
@@ -956,23 +963,23 @@ module ArelExtensions
956
963
  skip "Can't be tested on travis"
957
964
  # creation
958
965
  assert_equal 'Arthur', t(@arthur, Arel.json(@name))
959
- assert_equal ['Arthur', 'Arthur'], parse_json(t(@arthur, Arel.json(@name, @name)))
966
+ assert_equal %w[Arthur Arthur], parse_json(t(@arthur, Arel.json(@name, @name)))
960
967
  assert_equal ({'Arthur' => 'Arthur', 'Arthur2' => 'ArthurArthur'}), parse_json(t(@arthur, Arel.json({@name => @name, @name + '2' => @name + @name})))
961
968
  assert_equal ({'Arthur' => 'Arthur', 'Arthur2' => 1}), parse_json(t(@arthur, Arel.json({@name => @name, @name + '2' => 1})))
962
- assert_equal ([{'age' => 21}, {'name' => 'Arthur', 'score' => 65.62}]), parse_json(t(@arthur, Arel.json([{age: @age}, {name: @name, score: @score}])))
969
+ assert_equal [{'age' => 21}, {'name' => 'Arthur', 'score' => 65.62}], parse_json(t(@arthur, Arel.json([{age: @age}, {name: @name, score: @score}])))
963
970
 
964
971
  # aggregate
965
972
  assert_equal ({'5' => 'Lucas', '15' => 'Sophie', '23' => 'Myung', '25' => 'Laure'}),
966
973
  parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16), Arel.json({@age => @name}).group(false)))
967
974
  assert_equal ({'5' => 'Lucas', '15' => 'Sophie', '23' => 'Myung', '25' => 'Laure', 'Laure' => 25, 'Lucas' => 5, 'Myung' => 23, 'Sophie' => 15}),
968
975
  parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16), Arel.json({@age => @name, @name => @age}).group(false)))
969
- assert_equal ([{'5' => 'Lucas'}, { '15' => 'Sophie'}, { '23' => 'Myung'}, { '25' => 'Laure'}]),
976
+ assert_equal [{'5' => 'Lucas'}, {'15' => 'Sophie'}, {'23' => 'Myung'}, {'25' => 'Laure'}],
970
977
  parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score), Arel.json({@age => @name}).group(true, [@age])))
971
978
 
972
979
  # puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score, Arel.json({@age => @name}).group(true,[@age])).to_sql
973
980
  # puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score, Arel.json({@age => @name}).group(true,[@age])).to_a
974
981
 
975
- skip 'Not Yet Implemented' if $sqlite || ['oracle', 'mssql'].include?(@env_db)
982
+ skip 'Not Yet Implemented' if $sqlite || %w[oracle mssql].include?(@env_db)
976
983
  # get
977
984
  h1 = Arel.json({@name => @name + @name, @name + '2' => 1})
978
985
  assert_equal 'ArthurArthur', parse_json(t(@arthur, h1.get(@name)))
@@ -981,13 +988,13 @@ module ArelExtensions
981
988
  assert_equal 21, parse_json(t(@arthur, h2.get(0).get('age')))
982
989
  assert_nil t(@arthur, h2.get('age'))
983
990
  # set
984
- assert_equal ({'Arthur' => ['toto', 'tata'], 'Arthur2' => 1}), parse_json(t(@arthur, h1.set(@name, ['toto', 'tata'])))
991
+ assert_equal ({'Arthur' => %w[toto tata], 'Arthur2' => 1}), parse_json(t(@arthur, h1.set(@name, %w[toto tata])))
985
992
  assert_equal ({'Arthur' => 'ArthurArthur', 'Arthur2' => 1, 'Arthur3' => 2}), parse_json(t(@arthur, h1.set(@name + '3', 2)))
986
993
  assert_equal ({'Arthur' => 'ArthurArthur', 'Arthur2' => 1, 'Arthur3' => nil}), parse_json(t(@arthur, h1.set(@name + '3', nil)))
987
994
  assert_equal ({'Arthur' => 'ArthurArthur', 'Arthur2' => 1, 'Arthur3' => {'a' => 2}}), parse_json(t(@arthur, h1.set(@name + '3', {a: 2})))
988
995
  # merge
989
- assert_equal ({'Arthur' => ['toto', 'tata'], 'Arthur2' => 1, 'Arthur3' => 2}), parse_json(t(@arthur, h1.merge({@name => ['toto', 'tata']}, {@name + '3' => 2})))
990
- assert_equal ({'Arthur' => ['toto', 'tata'], 'Arthur2' => 1, 'Arthur3' => 2}), parse_json(t(@arthur, h1.merge({@name => ['toto', 'tata'], @name + '3' => 2})))
996
+ assert_equal ({'Arthur' => %w[toto tata], 'Arthur2' => 1, 'Arthur3' => 2}), parse_json(t(@arthur, h1.merge({@name => %w[toto tata]}, {@name + '3' => 2})))
997
+ assert_equal ({'Arthur' => %w[toto tata], 'Arthur2' => 1, 'Arthur3' => 2}), parse_json(t(@arthur, h1.merge({@name => %w[toto tata], @name + '3' => 2})))
991
998
  assert_equal ({'Arthur' => 'ArthurArthur', 'Arthur2' => 1}), parse_json(t(@arthur, h1.merge({})))
992
999
  end
993
1000
 
@@ -58,15 +58,15 @@ END;])
58
58
  connect_db
59
59
  setup_db
60
60
  @table = Arel::Table.new(:user_tests)
61
- @cols = ['id', 'name', 'comments', 'created_at']
61
+ @cols = %w[id name comments created_at]
62
62
  @data = [
63
63
  [23, 'nom1', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor.', '2016-01-01'],
64
64
  [25, 'nom2', 'sdfdsfdsfsdf', '2016-01-02']
65
65
  ]
66
- @cols2 = ['name', 'comments', 'created_at']
66
+ @cols2 = %w[name comments created_at]
67
67
  @data2 = [
68
68
  ['nom3', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor.', '2016-01-01'],
69
- ['nom4', 'sdfdsfdsfsdf', '2016-01-04']
69
+ %w[nom4 sdfdsfdsfsdf 2016-01-04]
70
70
  ]
71
71
  end
72
72
 
@@ -27,7 +27,7 @@ module ArelExtensions
27
27
  t.column :price, :decimal
28
28
  end
29
29
  @table = Arel::Table.new(:users)
30
- @cols = ['id', 'name', 'comments', 'created_at']
30
+ @cols = %w[id name comments created_at]
31
31
  @data = [
32
32
  [23, 'nom1', 'sdfdsfdsfsdf', '2016-01-01'],
33
33
  [25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
data/version_v1.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '1.3.4'.freeze
2
+ VERSION = '1.3.5'.freeze
3
3
  end
data/version_v2.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = '2.1.4'.freeze
2
+ VERSION = '2.1.5'.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: 2.1.4
4
+ version: 2.1.5
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: 2022-03-24 00:00:00.000000000 Z
13
+ date: 2022-07-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -90,6 +90,7 @@ files:
90
90
  - Rakefile
91
91
  - SQL_Challenges.md
92
92
  - TODO
93
+ - appveyor.yml
93
94
  - arel_extensions.gemspec
94
95
  - functions.html
95
96
  - gemfiles/rails3.gemfile