arel_extensions 2.0.4 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +54 -86
  3. data/README.md +1 -1
  4. data/Rakefile +13 -2
  5. data/arel_extensions.gemspec +1 -1
  6. data/gemfiles/rails4.gemfile +1 -1
  7. data/gemfiles/rails6.gemfile +1 -1
  8. data/generate_gems.sh +4 -3
  9. data/lib/arel_extensions.rb +33 -19
  10. data/lib/arel_extensions/attributes.rb +0 -1
  11. data/lib/arel_extensions/boolean_functions.rb +39 -12
  12. data/lib/arel_extensions/insert_manager.rb +7 -5
  13. data/lib/arel_extensions/nodes/abs.rb +0 -0
  14. data/lib/arel_extensions/nodes/case.rb +1 -1
  15. data/lib/arel_extensions/nodes/ceil.rb +0 -0
  16. data/lib/arel_extensions/nodes/coalesce.rb +0 -0
  17. data/lib/arel_extensions/nodes/concat.rb +0 -0
  18. data/lib/arel_extensions/nodes/duration.rb +0 -0
  19. data/lib/arel_extensions/nodes/find_in_set.rb +0 -0
  20. data/lib/arel_extensions/nodes/floor.rb +0 -0
  21. data/lib/arel_extensions/nodes/function.rb +0 -0
  22. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  23. data/lib/arel_extensions/nodes/length.rb +0 -0
  24. data/lib/arel_extensions/nodes/locate.rb +0 -0
  25. data/lib/arel_extensions/nodes/rand.rb +0 -0
  26. data/lib/arel_extensions/nodes/replace.rb +0 -0
  27. data/lib/arel_extensions/nodes/round.rb +0 -0
  28. data/lib/arel_extensions/nodes/soundex.rb +0 -0
  29. data/lib/arel_extensions/nodes/substring.rb +0 -0
  30. data/lib/arel_extensions/nodes/trim.rb +0 -0
  31. data/lib/arel_extensions/nodes/union.rb +0 -0
  32. data/lib/arel_extensions/nodes/wday.rb +0 -0
  33. data/lib/arel_extensions/predications.rb +22 -19
  34. data/lib/arel_extensions/set_functions.rb +2 -2
  35. data/lib/arel_extensions/string_functions.rb +13 -0
  36. data/lib/arel_extensions/version.rb +1 -1
  37. data/lib/arel_extensions/visitors.rb +1 -1
  38. data/lib/arel_extensions/visitors/ibm_db.rb +1 -1
  39. data/lib/arel_extensions/visitors/mysql.rb +24 -9
  40. data/lib/arel_extensions/visitors/oracle.rb +7 -8
  41. data/lib/arel_extensions/visitors/postgresql.rb +1 -1
  42. data/lib/arel_extensions/visitors/sqlite.rb +11 -7
  43. data/lib/arel_extensions/visitors/to_sql.rb +31 -38
  44. data/test/arelx_test_helper.rb +28 -0
  45. data/test/support/fake_record.rb +4 -0
  46. data/test/test_comparators.rb +8 -7
  47. data/test/visitors/test_bulk_insert_oracle.rb +4 -3
  48. data/test/visitors/test_bulk_insert_sqlite.rb +4 -3
  49. data/test/visitors/test_bulk_insert_to_sql.rb +3 -3
  50. data/test/visitors/test_oracle.rb +41 -41
  51. data/test/visitors/test_to_sql.rb +359 -206
  52. data/test/with_ar/all_agnostic_test.rb +18 -8
  53. data/test/with_ar/insert_agnostic_test.rb +1 -1
  54. data/test/with_ar/test_bulk_sqlite.rb +4 -3
  55. data/test/with_ar/test_math_sqlite.rb +1 -1
  56. data/test/with_ar/test_string_mysql.rb +1 -1
  57. data/test/with_ar/test_string_sqlite.rb +1 -1
  58. data/version_v1.rb +1 -1
  59. data/version_v2.rb +1 -1
  60. metadata +3 -3
  61. data/test/helper.rb +0 -18
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'arelx_test_helper'
2
2
  require 'date'
3
3
 
4
4
  module ArelExtensions
@@ -290,6 +290,7 @@ module ArelExtensions
290
290
 
291
291
  skip "Sqlite does not seem to support regexp_replace" if $sqlite
292
292
  skip "SQL Server does not know about REGEXP without extensions" if @env_db == 'mssql'
293
+ skip "Travis mysql version does not support REGEXP_REPLACE" if @env_db == 'mysql'
293
294
  assert_equal "LXcXs", t(@lucas, @name.replace(/[ua]/, "X"))
294
295
  assert_equal "LXcXs", t(@lucas, @name.regexp_replace(/[ua]/, "X"))
295
296
  assert_equal "LXcXs", t(@lucas, @name.regexp_replace('[ua]', "X"))
@@ -479,15 +480,17 @@ module ArelExtensions
479
480
  # TODO; cast types
480
481
  def test_cast_types
481
482
  assert_equal "5", t(@lucas, @age.cast(:string))
483
+ skip "jdbc adapters does not work properly here (v52 works fine)" if RUBY_PLATFORM =~ /java/i
482
484
  if @env_db == 'mysql' || @env_db == 'postgresql' || @env_db == 'oracle' || @env_db == 'mssql'
483
- 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'
484
- 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'
485
+ 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'
486
+ assert_equal 1, t(@laure,Arel.when(@duration.cast(:time).eq("12:42:21")).then(1).else(0)) unless @env_db == 'oracle'
485
487
  assert_equal "20.16", t(@laure,@score.cast(:string)).gsub(/[0]*\z/,'')
486
488
  assert_equal "20.161", t(@laure,@score.cast(:string)+1).gsub(/[0]*1\z/,'1')
487
489
  assert_equal 21.16, t(@laure,@score.cast(:string).cast(:decimal)+1)
488
490
  assert_equal 21, t(@laure,@score.cast(:string).cast(:int)+1)
489
491
 
490
492
  assert_equal String, t(@lucas,@updated_at.cast(:string)).class
493
+
491
494
  assert_equal Date, t(@lucas,@updated_at.cast(:date)).class unless @env_db == 'oracle' # DateTime
492
495
  assert_equal Time, t(@lucas,@updated_at.cast(:string).cast(:datetime)).class
493
496
  assert_equal Time, t(@lucas,@updated_at.cast(:time)).class
@@ -724,6 +727,13 @@ module ArelExtensions
724
727
  #assert_equal true , @test.where(@age.not_in([nil,1,2])).blank?
725
728
  end
726
729
 
730
+ def test_in_on_grouping
731
+ skip "We should modify the visitor of IN to make it work" if $sqlite || @env_db == 'mssql'
732
+ assert_equal 2 , User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23),Arel.tuple('Arthur',21))).count
733
+ assert_equal 1 , User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23))).count
734
+ assert_equal 0 , User.where(Arel.tuple(@name,@age).in([])).count
735
+ end
736
+
727
737
  def test_alias_shortened
728
738
  if ['postgresql','oracle'].include?(@env_db)
729
739
  new_alias = Arel.shorten('azerty' * 15)
@@ -748,11 +758,11 @@ module ArelExtensions
748
758
  assert (479.82048 - t(User.where(nil), @score.variance(unbiased: false))).abs < 0.01
749
759
  assert ( 23.23355 - t(User.where(nil), @score.std)).abs < 0.01
750
760
  assert ( 21.90480 - t(User.where(nil), @score.std(unbiased: false))).abs < 0.01
751
- skip "Not Yet Implemented" if !['postgresql'].include?(@env_db)
752
- assert_equal 2, User.select(@score.std(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map(&:res).uniq.length
753
- assert_equal 2, User.select(@score.variance(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map(&:res).uniq.length
754
- assert_equal 2, User.select(@score.sum(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map(&:res).uniq.length
755
- assert_equal 2, User.select(@comments.group_concat(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map(&:res).uniq.length
761
+ skip "Not Yet Implemented" #if !['postgresql'].include?(@env_db)
762
+ assert_equal 2, User.select(@score.std(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
763
+ assert_equal 2, User.select(@score.variance(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
764
+ assert_equal 2, User.select(@score.sum(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
765
+ assert_equal 2, User.select(@comments.group_concat(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
756
766
  end
757
767
 
758
768
  def test_levenshtein_distance
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'arelx_test_helper'
2
2
  require 'date'
3
3
 
4
4
  module ArelExtensions
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'arelx_test_helper'
2
2
 
3
3
  module ArelExtensions
4
4
  module WthAr
@@ -38,8 +38,9 @@ module ArelExtensions
38
38
  it "should import large set of data" do
39
39
  insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(ActiveRecord::Base).into(@table)
40
40
  insert_manager.bulk_insert(@cols, @data)
41
- sql = insert_manager.to_sql
42
- sql.must_be_like %Q[INSERT INTO "users" ("id", "name", "comments", "created_at") SELECT 23 AS 'id', 'nom1' AS 'name', 'sdfdsfdsfsdf' AS 'comments', '2016-01-01' AS 'created_at' UNION ALL SELECT 25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
41
+ _(insert_manager.to_sql)
42
+ .must_be_like %Q[INSERT INTO "users" ("id", "name", "comments", "created_at")
43
+ SELECT 23 AS 'id', 'nom1' AS 'name', 'sdfdsfdsfsdf' AS 'comments', '2016-01-01' AS 'created_at' UNION ALL SELECT 25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
43
44
  end
44
45
 
45
46
  end
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'arelx_test_helper'
2
2
 
3
3
  module ArelExtensions
4
4
  module WthAr
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'arelx_test_helper'
2
2
  require 'date'
3
3
 
4
4
  module ArelExtensions
@@ -1,4 +1,4 @@
1
- require 'helper'
1
+ require 'arelx_test_helper'
2
2
  require 'date'
3
3
 
4
4
  module ArelExtensions
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "1.2.8".freeze
2
+ VERSION = "1.2.12".freeze
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module ArelExtensions
2
- VERSION = "2.0.4".freeze
2
+ VERSION = "2.0.8".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.0.4
4
+ version: 2.0.8
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-22 00:00:00.000000000 Z
13
+ date: 2020-04-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -177,8 +177,8 @@ files:
177
177
  - lib/arel_extensions/visitors/postgresql.rb
178
178
  - lib/arel_extensions/visitors/sqlite.rb
179
179
  - lib/arel_extensions/visitors/to_sql.rb
180
+ - test/arelx_test_helper.rb
180
181
  - test/database.yml
181
- - test/helper.rb
182
182
  - test/real_db_test.rb
183
183
  - test/support/alter_system_user_password.sql
184
184
  - test/support/create_oracle_enhanced_users.sql
@@ -1,18 +0,0 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
- require 'fileutils'
4
- require 'arel'
5
- require 'active_record'
6
-
7
- require 'arel_extensions'
8
-
9
- require 'support/fake_record'
10
- Arel::Table.engine = FakeRecord::Base.new
11
-
12
- $arel_silence_type_casting_deprecation = true
13
-
14
- class Object
15
- def must_be_like other
16
- gsub(/\s+/, ' ').strip.must_equal other.gsub(/\s+/, ' ').strip
17
- end
18
- end