arel_extensions 1.3.8 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -1
  3. data/.gitignore +6 -7
  4. data/.rubocop.yml +3 -67
  5. data/.travis/oracle/download.js +152 -0
  6. data/.travis/oracle/download.sh +30 -0
  7. data/.travis/oracle/download_ojdbc.js +116 -0
  8. data/.travis/oracle/install.sh +34 -0
  9. data/.travis/setup_accounts.sh +9 -0
  10. data/.travis/sqlite3/extension-functions.sh +6 -0
  11. data/.travis.yml +223 -0
  12. data/Gemfile +21 -16
  13. data/README.md +90 -282
  14. data/Rakefile +30 -48
  15. data/TODO +1 -0
  16. data/appveyor.yml +22 -60
  17. data/arel_extensions.gemspec +14 -13
  18. data/functions.html +3 -3
  19. data/gemfiles/rails3.gemfile +10 -10
  20. data/gemfiles/rails4.gemfile +29 -0
  21. data/gemfiles/rails5_0.gemfile +29 -0
  22. data/gemfiles/rails5_1_4.gemfile +14 -14
  23. data/gemfiles/rails5_2.gemfile +14 -16
  24. data/init/mssql.sql +4 -4
  25. data/init/mysql.sql +38 -38
  26. data/init/oracle.sql +0 -0
  27. data/init/postgresql.sql +21 -21
  28. data/init/sqlite.sql +0 -0
  29. data/lib/arel_extensions/attributes.rb +3 -4
  30. data/lib/arel_extensions/boolean_functions.rb +14 -53
  31. data/lib/arel_extensions/common_sql_functions.rb +17 -16
  32. data/lib/arel_extensions/comparators.rb +28 -27
  33. data/lib/arel_extensions/date_duration.rb +13 -17
  34. data/lib/arel_extensions/insert_manager.rb +15 -18
  35. data/lib/arel_extensions/math.rb +53 -55
  36. data/lib/arel_extensions/math_functions.rb +39 -46
  37. data/lib/arel_extensions/nodes/abs.rb +1 -0
  38. data/lib/arel_extensions/nodes/blank.rb +2 -1
  39. data/lib/arel_extensions/nodes/case.rb +19 -20
  40. data/lib/arel_extensions/nodes/cast.rb +8 -10
  41. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  42. data/lib/arel_extensions/nodes/coalesce.rb +4 -3
  43. data/lib/arel_extensions/nodes/collate.rb +10 -9
  44. data/lib/arel_extensions/nodes/concat.rb +18 -9
  45. data/lib/arel_extensions/nodes/date_diff.rb +26 -42
  46. data/lib/arel_extensions/nodes/duration.rb +3 -0
  47. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  48. data/lib/arel_extensions/nodes/floor.rb +1 -1
  49. data/lib/arel_extensions/nodes/format.rb +8 -35
  50. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  51. data/lib/arel_extensions/nodes/function.rb +37 -42
  52. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  53. data/lib/arel_extensions/nodes/json.rb +39 -52
  54. data/lib/arel_extensions/nodes/length.rb +0 -5
  55. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  56. data/lib/arel_extensions/nodes/locate.rb +2 -1
  57. data/lib/arel_extensions/nodes/log10.rb +2 -1
  58. data/lib/arel_extensions/nodes/matches.rb +7 -5
  59. data/lib/arel_extensions/nodes/md5.rb +1 -0
  60. data/lib/arel_extensions/nodes/power.rb +5 -5
  61. data/lib/arel_extensions/nodes/rand.rb +1 -0
  62. data/lib/arel_extensions/nodes/repeat.rb +5 -3
  63. data/lib/arel_extensions/nodes/replace.rb +8 -16
  64. data/lib/arel_extensions/nodes/round.rb +6 -5
  65. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  66. data/lib/arel_extensions/nodes/std.rb +21 -18
  67. data/lib/arel_extensions/nodes/substring.rb +16 -8
  68. data/lib/arel_extensions/nodes/then.rb +1 -1
  69. data/lib/arel_extensions/nodes/trim.rb +6 -4
  70. data/lib/arel_extensions/nodes/union.rb +8 -5
  71. data/lib/arel_extensions/nodes/union_all.rb +7 -4
  72. data/lib/arel_extensions/nodes/wday.rb +4 -0
  73. data/lib/arel_extensions/nodes.rb +1 -1
  74. data/lib/arel_extensions/null_functions.rb +5 -19
  75. data/lib/arel_extensions/predications.rb +43 -44
  76. data/lib/arel_extensions/railtie.rb +5 -5
  77. data/lib/arel_extensions/set_functions.rb +7 -5
  78. data/lib/arel_extensions/string_functions.rb +29 -59
  79. data/lib/arel_extensions/tasks.rb +6 -6
  80. data/lib/arel_extensions/version.rb +1 -1
  81. data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
  82. data/lib/arel_extensions/visitors/mssql.rb +180 -375
  83. data/lib/arel_extensions/visitors/mysql.rb +212 -350
  84. data/lib/arel_extensions/visitors/oracle.rb +178 -220
  85. data/lib/arel_extensions/visitors/oracle12.rb +31 -18
  86. data/lib/arel_extensions/visitors/postgresql.rb +173 -256
  87. data/lib/arel_extensions/visitors/sqlite.rb +126 -140
  88. data/lib/arel_extensions/visitors/to_sql.rb +237 -298
  89. data/lib/arel_extensions/visitors.rb +58 -82
  90. data/lib/arel_extensions.rb +31 -182
  91. data/test/database.yml +7 -15
  92. data/test/helper.rb +18 -0
  93. data/test/real_db_test.rb +116 -105
  94. data/test/support/fake_record.rb +3 -3
  95. data/test/test_comparators.rb +17 -14
  96. data/test/visitors/test_bulk_insert_oracle.rb +11 -11
  97. data/test/visitors/test_bulk_insert_sqlite.rb +13 -12
  98. data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
  99. data/test/visitors/test_oracle.rb +55 -55
  100. data/test/visitors/test_to_sql.rb +226 -419
  101. data/test/with_ar/all_agnostic_test.rb +365 -709
  102. data/test/with_ar/insert_agnostic_test.rb +21 -27
  103. data/test/with_ar/test_bulk_sqlite.rb +16 -17
  104. data/test/with_ar/test_math_sqlite.rb +26 -26
  105. data/test/with_ar/test_string_mysql.rb +33 -31
  106. data/test/with_ar/test_string_sqlite.rb +34 -30
  107. metadata +34 -33
  108. data/.github/workflows/ruby.yml +0 -360
  109. data/NEWS.md +0 -32
  110. data/dev/compose.yaml +0 -29
  111. data/gemfiles/rails4_2.gemfile +0 -38
  112. data/gemfiles/rails5.gemfile +0 -29
  113. data/gemfiles/rails6.gemfile +0 -30
  114. data/gemfiles/rails6_1.gemfile +0 -30
  115. data/gemfiles/rails7.gemfile +0 -23
  116. data/gemfiles/rails7_1.gemfile +0 -22
  117. data/gemspecs/arel_extensions-v1.gemspec +0 -27
  118. data/gemspecs/arel_extensions-v2.gemspec +0 -27
  119. data/generate_gems.sh +0 -15
  120. data/lib/arel_extensions/aliases.rb +0 -14
  121. data/lib/arel_extensions/helpers.rb +0 -57
  122. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  123. data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
  124. data/lib/arel_extensions/nodes/rollup.rb +0 -36
  125. data/lib/arel_extensions/nodes/select.rb +0 -10
  126. data/lib/arel_extensions/nodes/sum.rb +0 -7
  127. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  128. data/test/arelx_test_helper.rb +0 -67
  129. data/version_v1.rb +0 -3
  130. data/version_v2.rb +0 -3
@@ -1,23 +1,20 @@
1
- require 'arelx_test_helper'
1
+ require 'helper'
2
2
  require 'date'
3
3
 
4
4
  module ArelExtensions
5
- module WithAr
5
+ module WthAr
6
+
6
7
  class InsertManagerTest < Minitest::Test
7
- def connect_db
8
+ def setup_db
8
9
  ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
9
- if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx') || (RUBY_PLATFORM == 'java')) # not supported
10
- @env_db = (RUBY_PLATFORM == 'java' ? 'jdbc-sqlite' : 'sqlite')
11
- skip "Platform not supported (DB: #{ENV['DB']}, RUBY_ENGINE: #{RUBY_ENGINE}, RUBY_PLATFORM: #{RUBY_PLATFORM})"
10
+ if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx") || (RUBY_PLATFORM == 'java')) # not supported
11
+ @env_db = (RUBY_PLATFORM == 'java' ? "jdbc-sqlite" : 'sqlite')
12
+ skip "Platform not supported"
12
13
  else
13
14
  @env_db = ENV['DB']
14
15
  end
15
16
  ActiveRecord::Base.establish_connection(@env_db.try(:to_sym) || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
16
- if ActiveRecord::VERSION::MAJOR >= 7
17
- ActiveRecord.default_timezone = :utc
18
- else
19
- ActiveRecord::Base.default_timezone = :utc
20
- end
17
+ ActiveRecord::Base.default_timezone = :utc
21
18
  @cnx = ActiveRecord::Base.connection
22
19
  Arel::Table.engine = ActiveRecord::Base
23
20
  if File.exist?("init/#{@env_db}.sql")
@@ -26,17 +23,14 @@ module ArelExtensions
26
23
  @cnx.execute(sql) rescue $stderr << "can't create functions\n"
27
24
  end
28
25
  end
29
- end
30
-
31
- def setup_db
32
- @cnx.drop_table(:user_tests) rescue nil
26
+ @cnx.drop_table(:user_tests) rescue nil
33
27
  @cnx.create_table :user_tests do |t|
34
28
  t.column :age, :integer
35
29
  t.column :name, :string
36
30
  t.column :comments, :text
37
31
  t.column :created_at, :date
38
32
  t.column :updated_at, :datetime
39
- t.column :score, :decimal, precision: 20, scale: 10
33
+ t.column :score, :decimal, :precision => 20, :scale => 10
40
34
  end
41
35
  if @env_db == 'oracle'
42
36
  @cnx.execute(%q[CREATE OR REPLACE trigger user_tests_trg
@@ -55,18 +49,17 @@ END;])
55
49
  end
56
50
 
57
51
  def setup
58
- connect_db
59
52
  setup_db
60
53
  @table = Arel::Table.new(:user_tests)
61
- @cols = %w[id name comments created_at]
54
+ @cols = ['id', 'name', 'comments', 'created_at']
62
55
  @data = [
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
- [25, 'nom2', 'sdfdsfdsfsdf', '2016-01-02']
56
+ [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'],
57
+ [25, 'nom2', "sdfdsfdsfsdf", '2016-01-02']
65
58
  ]
66
- @cols2 = %w[name comments created_at]
59
+ @cols2 = ['name', 'comments', 'created_at']
67
60
  @data2 = [
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
- %w[nom4 sdfdsfdsfsdf 2016-01-04]
61
+ ['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'],
62
+ ['nom4', "sdfdsfdsfsdf", '2016-01-04']
70
63
  ]
71
64
  end
72
65
 
@@ -76,15 +69,16 @@ END;])
76
69
 
77
70
  # Math Functions
78
71
  def test_bulk_insert
79
- insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(Arel::Table.engine).into(@table)
72
+ insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(Arel::Table.engine).into(@table)
80
73
  insert_manager.bulk_insert(@cols, @data)
81
74
  @cnx.execute(insert_manager.to_sql)
82
- assert_equal 2, User.count, 'insertions failed'
83
- insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(Arel::Table.engine).into(@table)
75
+ assert_equal 2, User.count, "insertions failed"
76
+ insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(Arel::Table.engine).into(@table)
84
77
  insert_manager.bulk_insert(@cols2, @data2)
85
78
  @cnx.execute(insert_manager.to_sql)
86
- assert_equal 4, User.count, 'insertions failed'
79
+ assert_equal 4, User.count, "insertions failed"
87
80
  end
81
+
88
82
  end
89
83
  end
90
84
  end
@@ -1,20 +1,18 @@
1
- require 'arelx_test_helper'
1
+ require 'helper'
2
2
 
3
3
  module ArelExtensions
4
- module WithAr
4
+ module WthAr
5
+
5
6
  describe 'the sqlite visitor' do
7
+
6
8
  before do
7
9
  ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
8
10
  ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
9
- if ActiveRecord::VERSION::MAJOR >= 7
10
- ActiveRecord.default_timezone = :utc
11
- else
12
- ActiveRecord::Base.default_timezone = :utc
13
- end
11
+ ActiveRecord::Base.default_timezone = :utc
14
12
  @cnx = ActiveRecord::Base.connection
15
13
  Arel::Table.engine = ActiveRecord::Base
16
14
  @cnx.drop_table(:users) rescue nil
17
- @cnx.drop_table(:products) rescue nil
15
+ @cnx.drop_table(:products) rescue nil
18
16
  @cnx.create_table :users do |t|
19
17
  t.column :age, :integer
20
18
  t.column :name, :string
@@ -27,23 +25,24 @@ module ArelExtensions
27
25
  t.column :price, :decimal
28
26
  end
29
27
  @table = Arel::Table.new(:users)
30
- @cols = %w[id name comments created_at]
28
+ @cols = ['id', 'name', 'comments', 'created_at']
31
29
  @data = [
32
- [23, 'nom1', 'sdfdsfdsfsdf', '2016-01-01'],
33
- [25, 'nom2', 'sdfdsfdsfsdf', '2016-01-01']
30
+ [23, 'nom1', "sdfdsfdsfsdf", '2016-01-01'],
31
+ [25, 'nom2', "sdfdsfdsfsdf", '2016-01-01']
34
32
  ]
35
33
  end
36
34
  after do
37
35
  @cnx.drop_table(:users)
38
36
  end
39
37
 
40
- it 'should import large set of data' do
41
- insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new.into(@table) : Arel::InsertManager.new(ActiveRecord::Base).into(@table)
38
+ it "should import large set of data" do
39
+ insert_manager = Arel::VERSION.to_i > 6 ? Arel::InsertManager.new().into(@table) : Arel::InsertManager.new(ActiveRecord::Base).into(@table)
42
40
  insert_manager.bulk_insert(@cols, @data)
43
- _(insert_manager.to_sql)
44
- .must_be_like %Q[INSERT INTO "users" ("id", "name", "comments", "created_at")
45
- 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
+ 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']
46
43
  end
44
+
47
45
  end
46
+
48
47
  end
49
- end
48
+ end
@@ -1,20 +1,18 @@
1
- require 'arelx_test_helper'
1
+ require 'helper'
2
2
 
3
3
  module ArelExtensions
4
- module WithAr
4
+ module WthAr
5
+
5
6
  describe 'the sqlite visitor can do maths' do
7
+
6
8
  before do
7
9
  ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
8
10
  ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
9
- if ActiveRecord::VERSION::MAJOR >= 7
10
- ActiveRecord.default_timezone = :utc
11
- else
12
- ActiveRecord::Base.default_timezone = :utc
13
- end
11
+ ActiveRecord::Base.default_timezone = :utc
14
12
  Arel::Table.engine = ActiveRecord::Base
15
13
  @cnx = ActiveRecord::Base.connection
16
- @cnx.drop_table(:users) rescue nil
17
- @cnx.drop_table(:products) rescue nil
14
+ @cnx.drop_table(:users) rescue nil
15
+ @cnx.drop_table(:products) rescue nil
18
16
  @cnx.create_table :users do |t|
19
17
  t.column :age, :integer
20
18
  t.column :name, :string
@@ -28,15 +26,15 @@ module ArelExtensions
28
26
  end
29
27
  class User < ActiveRecord::Base
30
28
  end
31
- d = Date.new(2016, 5, 23)
32
- User.create age: 5, name: 'Lucas', created_at: d, score: 20.16
33
- User.create age: 15, name: 'Sophie', created_at: d, score: 20.16
34
- User.create age: 20, name: 'Camille', created_at: d, score: 20.16
35
- User.create age: 21, name: 'Arthur', created_at: d, score: 65.62
36
- User.create age: 23, name: 'Myung', created_at: d, score: 20.16
37
- @laure = User.create age: 25, name: 'Laure', created_at: d, score: 20.16
38
- User.create age: nil, name: 'Test', created_at: d, score: 1.62
39
- @neg = User.create age: -20, name: 'Negatif', created_at: d, score: 0.17
29
+ d = Date.new(2016, 5,23)
30
+ User.create :age => 5, :name => "Lucas", :created_at => d, :score => 20.16
31
+ User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
32
+ User.create :age => 20, :name => "Camille", :created_at => d, :score => 20.16
33
+ User.create :age => 21, :name => "Arthur", :created_at => d, :score => 65.62
34
+ User.create :age => 23, :name => "Myung", :created_at => d, :score => 20.16
35
+ @laure = User.create :age => 25, :name => "Laure", :created_at => d, :score =>20.16
36
+ User.create :age => nil, :name => "Test", :created_at => d, :score => 1.62
37
+ @neg = User.create :age => -20, :name => "Negatif", :created_at => d, :score => 0.17
40
38
  @table = Arel::Table.new(:users)
41
39
  @age = @table[:age]
42
40
  end
@@ -45,20 +43,22 @@ module ArelExtensions
45
43
  @cnx.drop_table(:products)
46
44
  end
47
45
 
48
- it 'should do maths' do
49
- # ABS
50
- assert_equal 20, User.where(id: @neg.id).select(@age.abs.as('res')).first.res
51
- assert_equal 14, User.where(id: @laure.id).select((@age - 39).abs.as('res')).first.res
46
+ it "should do maths" do
47
+ #ABS
48
+ assert_equal 20, User.where(:id => @neg.id).select(@age.abs.as("res")).first.res
49
+ assert_equal 14, User.where(:id => @laure.id).select((@age - 39).abs.as("res")).first.res
52
50
 
53
- # CEIL # require extensions
51
+ #CEIL # require extensions
54
52
 
55
53
  # RAND
56
- # puts User.where(@table[:score].eq(20.16)).order(Arel.rand).limit(50).to_sql if User.where(@table[:score].eq(20.16)).order(Arel.rand).limit(50).count == 0
57
- # assert_equal 5, User.where(@table[:score].eq(20.16)).order(Arel.rand).limit(50).count
54
+ # puts User.where(@table[:score].eq(20.16)).order(Arel.rand).limit(50).to_sql if User.where(@table[:score].eq(20.16)).order(Arel.rand).limit(50).count == 0
55
+ # assert_equal 5, User.where(@table[:score].eq(20.16)).order(Arel.rand).limit(50).count
58
56
  assert 42 != User.select(Arel.rand.as('res')).first.res
59
57
  assert 0 <= User.select(Arel.rand.abs.as('res')).first.res
60
58
  assert_equal 8, User.order(Arel.rand).limit(50).count
61
59
  end
60
+
62
61
  end
62
+
63
63
  end
64
- end
64
+ end
@@ -1,18 +1,16 @@
1
- require 'arelx_test_helper'
1
+ require 'helper'
2
2
  require 'date'
3
3
 
4
4
  module ArelExtensions
5
- module WithAr
5
+ module WthAr
6
+
6
7
  describe 'the mysql visitor can do string operations' do
8
+
7
9
  before do
8
10
  ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
9
11
  ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-mysql" : :mysql))
10
- if ActiveRecord::VERSION::MAJOR >= 7
11
- ActiveRecord.default_timezone = :utc
12
- else
13
- ActiveRecord::Base.default_timezone = :utc
14
- end
15
- begin
12
+ ActiveRecord::Base.default_timezone = :utc
13
+ begin
16
14
  @cnx = ActiveRecord::Base.connection
17
15
  rescue => e
18
16
  puts "\n#{e.inspect}"
@@ -21,7 +19,7 @@ module ArelExtensions
21
19
  end
22
20
  Arel::Table.engine = ActiveRecord::Base
23
21
  @cnx.drop_table(:users) rescue nil
24
- @cnx.drop_table(:products) rescue nil
22
+ @cnx.drop_table(:products) rescue nil
25
23
  @cnx.create_table :users do |t|
26
24
  t.column :age, :integer
27
25
  t.column :name, :string
@@ -35,16 +33,16 @@ module ArelExtensions
35
33
  end
36
34
  class User < ActiveRecord::Base
37
35
  end
38
- d = Date.new(2016, 5, 23)
39
- @lucas = User.create age: 5, name: 'Lucas', created_at: d, score: 20.16
40
- sophie = User.create age: 15, name: 'Sophie', created_at: d, score: 20.16
41
- @sophie = User.where(id: sophie.id)
42
- User.create age: 20, name: 'Camille', created_at: d, score: 20.16
43
- User.create age: 21, name: 'Arthur', created_at: d, score: 65.62
44
- User.create age: 23, name: 'Myung', created_at: d, score: 20.16
45
- @laure = User.create age: 25, name: 'Laure', created_at: d, score: 20.16
46
- User.create age: nil, name: 'Test', created_at: d, score: 1.62
47
- @neg = User.create age: -20, name: 'Negatif', created_at: d, score: 0.17
36
+ d = Date.new(2016, 5,23)
37
+ @lucas = User.create :age => 5, :name => "Lucas", :created_at => d, :score => 20.16
38
+ sophie = User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
39
+ @sophie = User.where(:id => sophie.id)
40
+ User.create :age => 20, :name => "Camille", :created_at => d, :score => 20.16
41
+ User.create :age => 21, :name => "Arthur", :created_at => d, :score => 65.62
42
+ User.create :age => 23, :name => "Myung", :created_at => d, :score => 20.16
43
+ @laure = User.create :age => 25, :name => "Laure", :created_at => d, :score =>20.16
44
+ User.create :age => nil, :name => "Test", :created_at => d, :score => 1.62
45
+ @neg = User.create :age => -20, :name => "Negatif", :created_at => d, :score => 0.17
48
46
  @table = Arel::Table.new(:users)
49
47
  @name = @table[:name]
50
48
  end
@@ -52,24 +50,28 @@ module ArelExtensions
52
50
  @cnx.drop_table(:users)
53
51
  end
54
52
 
55
- it 'should do string operations' do
53
+ it "should do string operations" do
56
54
  # concat
57
55
  d = Date.new(1997, 6, 15)
58
- assert_equal 'SophiePhan', @sophie.select((@name + 'Phan').as('res')).first.res
59
- assert_equal 'Sophie2', @sophie.select((@name + 2).as('res')).first.res
60
- assert_equal 'Sophie1997-06-15', @sophie.select((@name + d).as('res')).first.res
61
- assert_equal 'Sophie15', @sophie.select((User.arel_table[:name] + User.arel_table[:age]).as('res')).first.res
62
- assert_equal 'SophieSophie', @sophie.select((User.arel_table[:name] + User.arel_table[:name]).as('res')).first.res
63
- assert_equal 'Sophie2016-05-23', @sophie.select((User.arel_table[:name] + User.arel_table[:created_at]).as('res')).first.res
64
- # concat Integer
56
+ assert_equal "SophiePhan", @sophie.select((@name + "Phan").as("res")).first.res
57
+ assert_equal "Sophie2", @sophie.select((@name + 2).as("res")).first.res
58
+ assert_equal "Sophie1997-06-15", @sophie.select((@name + d).as("res")).first.res
59
+ assert_equal "Sophie15", @sophie.select((User.arel_table[:name] + User.arel_table[:age]).as("res")).first.res
60
+ assert_equal "SophieSophie", @sophie.select((User.arel_table[:name] + User.arel_table[:name]).as("res")).first.res
61
+ assert_equal "Sophie2016-05-23", @sophie.select((User.arel_table[:name] + User.arel_table[:created_at]).as("res")).first.res
62
+ #concat Integer
65
63
  assert_equal 1, User.where((User.arel_table[:age] + 10).eq(33)).count
66
- assert_equal 1, User.where((User.arel_table[:age] + '1').eq(6)).count
64
+ assert_equal 1, User.where((User.arel_table[:age] + "1").eq(6)).count
67
65
  assert_equal 1, User.where((User.arel_table[:age] + User.arel_table[:age]).eq(10)).count
68
66
 
69
67
  # Replace
70
- assert_equal 'LucaX', User.where(id: @lucas).select(@name.replace('s', 'X').as('res')).first.res
71
- assert_equal 'replace', User.where(id: @lucas).select(@name.replace(@name, 'replace').as('res')).first.res
68
+ assert_equal "LucaX", User.where(:id => @lucas).select(@name.replace("s","X").as("res")).first.res
69
+ assert_equal "replace", User.where(:id => @lucas).select(@name.replace(@name,"replace").as("res")).first.res
70
+
71
+ #
72
72
  end
73
+
73
74
  end
75
+
74
76
  end
75
- end
77
+ end
@@ -1,20 +1,18 @@
1
- require 'arelx_test_helper'
1
+ require 'helper'
2
2
  require 'date'
3
3
 
4
4
  module ArelExtensions
5
- module WithAr
5
+ module WthAr
6
+
6
7
  describe 'the sqlite visitor can do string operations' do
8
+
7
9
  before do
8
10
  ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
9
11
  ActiveRecord::Base.establish_connection(ENV['DB'] || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
10
- if ActiveRecord::VERSION::MAJOR >= 7
11
- ActiveRecord.default_timezone = :utc
12
- else
13
- ActiveRecord::Base.default_timezone = :utc
14
- end
12
+ ActiveRecord::Base.default_timezone = :utc
15
13
  @cnx = ActiveRecord::Base.connection
16
14
  Arel::Table.engine = ActiveRecord::Base
17
- @cnx.drop_table(:users) rescue nil
15
+ @cnx.drop_table(:users) rescue nil
18
16
  @cnx.create_table :users do |t|
19
17
  t.column :age, :integer
20
18
  t.column :name, :string
@@ -28,16 +26,16 @@ module ArelExtensions
28
26
  end
29
27
  class User < ActiveRecord::Base
30
28
  end
31
- d = Date.new(2016, 5, 23)
32
- @lucas = User.create! age: 5, name: 'Lucas', created_at: d, score: 20.16
33
- sophie = User.create age: 15, name: 'Sophie', created_at: d, score: 20.16
34
- @sophie = User.where(id: sophie.id)
35
- User.create! age: 20, name: 'Camille', created_at: d, score: 20.16
36
- User.create! age: 21, name: 'Arthur', created_at: d, score: 65.62
37
- User.create! age: 23, name: 'Myung', created_at: d, score: 20.16
38
- @laure = User.create age: 25, name: 'Laure', created_at: d, score: 20.16
39
- User.create! age: nil, name: 'Test', created_at: d, score: 1.62
40
- @neg = User.create age: -20, name: 'Negatif', created_at: d, score: 0.17
29
+ d = Date.new(2016, 5,23)
30
+ @lucas = User.create! :age => 5, :name => "Lucas", :created_at => d, :score => 20.16
31
+ sophie = User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
32
+ @sophie = User.where(:id => sophie.id)
33
+ User.create! :age => 20, :name => "Camille", :created_at => d, :score => 20.16
34
+ User.create! :age => 21, :name => "Arthur", :created_at => d, :score => 65.62
35
+ User.create! :age => 23, :name => "Myung", :created_at => d, :score => 20.16
36
+ @laure = User.create :age => 25, :name => "Laure", :created_at => d, :score =>20.16
37
+ User.create! :age => nil, :name => "Test", :created_at => d, :score => 1.62
38
+ @neg = User.create :age => -20, :name => "Negatif", :created_at => d, :score => 0.17
41
39
  @table = Arel::Table.new(:users)
42
40
  @name = @table[:name]
43
41
  end
@@ -45,24 +43,30 @@ module ArelExtensions
45
43
  @cnx.drop_table(:users)
46
44
  end
47
45
 
48
- it 'should do string operations' do
46
+ it "should do string operations" do
49
47
  # concat
50
48
  d = Date.new(1997, 6, 15)
51
- assert_equal 'SophiePhan', @sophie.select((@name + 'Phan').as('res')).first.res
52
- assert_equal 'Sophie2', @sophie.select((@name + 2).as('res')).first.res
53
- assert_equal 'Sophie1997-06-15', @sophie.select((@name + d).as('res')).first.res
54
- assert_equal 'Sophie15', @sophie.select((User.arel_table[:name] + User.arel_table[:age]).as('res')).first.res
55
- assert_equal 'SophieSophie', @sophie.select((User.arel_table[:name] + User.arel_table[:name]).as('res')).first.res
56
- assert_equal 'Sophie2016-05-23', @sophie.select((User.arel_table[:name] + User.arel_table[:created_at]).as('res')).first.res
57
- # concat Integer
49
+ assert_equal "SophiePhan", @sophie.select((@name + "Phan").as("res")).first.res
50
+ assert_equal "Sophie2", @sophie.select((@name + 2).as("res")).first.res
51
+ assert_equal "Sophie1997-06-15", @sophie.select((@name + d).as("res")).first.res
52
+ assert_equal "Sophie15", @sophie.select((User.arel_table[:name] + User.arel_table[:age]).as("res")).first.res
53
+ assert_equal "SophieSophie", @sophie.select((User.arel_table[:name] + User.arel_table[:name]).as("res")).first.res
54
+ assert_equal "Sophie2016-05-23", @sophie.select((User.arel_table[:name] + User.arel_table[:created_at]).as("res")).first.res
55
+ #concat Integer
58
56
  assert_equal 1, User.where((User.arel_table[:age] + 10).eq(33)).count
59
- assert_equal 1, User.where((User.arel_table[:age] + '1').eq(6)).count
57
+ assert_equal 1, User.where((User.arel_table[:age] + "1").eq(6)).count
60
58
  assert_equal 1, User.where((User.arel_table[:age] + User.arel_table[:age]).eq(10)).count
61
59
 
60
+
61
+
62
62
  # Replace
63
- assert_equal 'LucaX', User.where(id: @lucas).select(@name.replace('s', 'X').as('res')).first.res
64
- assert_equal 'replace', User.where(id: @lucas).select(@name.replace(@name, 'replace').as('res')).first.res
63
+ assert_equal "LucaX", User.where(:id => @lucas).select(@name.replace("s","X").as("res")).first.res
64
+ assert_equal "replace", User.where(:id => @lucas).select(@name.replace(@name,"replace").as("res")).first.res
65
+
66
+ #
65
67
  end
68
+
66
69
  end
70
+
67
71
  end
68
- end
72
+ 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.3.8
4
+ version: 2.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yann Azoury
@@ -10,22 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-11-14 00:00:00.000000000 Z
13
+ date: 2019-08-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: arel
16
+ name: activerecord
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '6.0'
21
+ version: 6.0.0.rc2
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '6.0'
28
+ version: 6.0.0.rc2
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: minitest
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -40,20 +40,34 @@ dependencies:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '5.9'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rdoc
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '4.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '4.0'
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: rake
45
59
  requirement: !ruby/object:Gem::Requirement
46
60
  requirements:
47
61
  - - "~>"
48
62
  - !ruby/object:Gem::Version
49
- version: 12.3.3
63
+ version: '11'
50
64
  type: :development
51
65
  prerelease: false
52
66
  version_requirements: !ruby/object:Gem::Requirement
53
67
  requirements:
54
68
  - - "~>"
55
69
  - !ruby/object:Gem::Version
56
- version: 12.3.3
70
+ version: '11'
57
71
  description: Adds new features to Arel
58
72
  email:
59
73
  - yann.azoury@faveod.com
@@ -67,51 +81,45 @@ extra_rdoc_files:
67
81
  - functions.html
68
82
  files:
69
83
  - ".codeclimate.yml"
70
- - ".github/workflows/ruby.yml"
71
84
  - ".gitignore"
72
85
  - ".rubocop.yml"
86
+ - ".travis.yml"
87
+ - ".travis/oracle/download.js"
88
+ - ".travis/oracle/download.sh"
89
+ - ".travis/oracle/download_ojdbc.js"
90
+ - ".travis/oracle/install.sh"
91
+ - ".travis/setup_accounts.sh"
92
+ - ".travis/sqlite3/extension-functions.sh"
73
93
  - Gemfile
74
94
  - MIT-LICENSE.txt
75
- - NEWS.md
76
95
  - README.md
77
96
  - Rakefile
78
97
  - SQL_Challenges.md
79
98
  - TODO
80
99
  - appveyor.yml
81
100
  - arel_extensions.gemspec
82
- - dev/compose.yaml
83
101
  - functions.html
84
102
  - gemfiles/rails3.gemfile
85
- - gemfiles/rails4_2.gemfile
86
- - gemfiles/rails5.gemfile
103
+ - gemfiles/rails4.gemfile
104
+ - gemfiles/rails5_0.gemfile
87
105
  - gemfiles/rails5_1_4.gemfile
88
106
  - gemfiles/rails5_2.gemfile
89
- - gemfiles/rails6.gemfile
90
- - gemfiles/rails6_1.gemfile
91
- - gemfiles/rails7.gemfile
92
- - gemfiles/rails7_1.gemfile
93
- - gemspecs/arel_extensions-v1.gemspec
94
- - gemspecs/arel_extensions-v2.gemspec
95
- - generate_gems.sh
96
107
  - init/mssql.sql
97
108
  - init/mysql.sql
98
109
  - init/oracle.sql
99
110
  - init/postgresql.sql
100
111
  - init/sqlite.sql
101
112
  - lib/arel_extensions.rb
102
- - lib/arel_extensions/aliases.rb
103
113
  - lib/arel_extensions/attributes.rb
104
114
  - lib/arel_extensions/boolean_functions.rb
105
115
  - lib/arel_extensions/common_sql_functions.rb
106
116
  - lib/arel_extensions/comparators.rb
107
117
  - lib/arel_extensions/date_duration.rb
108
- - lib/arel_extensions/helpers.rb
109
118
  - lib/arel_extensions/insert_manager.rb
110
119
  - lib/arel_extensions/math.rb
111
120
  - lib/arel_extensions/math_functions.rb
112
121
  - lib/arel_extensions/nodes.rb
113
122
  - lib/arel_extensions/nodes/abs.rb
114
- - lib/arel_extensions/nodes/aggregate_function.rb
115
123
  - lib/arel_extensions/nodes/blank.rb
116
124
  - lib/arel_extensions/nodes/case.rb
117
125
  - lib/arel_extensions/nodes/cast.rb
@@ -125,7 +133,6 @@ files:
125
133
  - lib/arel_extensions/nodes/find_in_set.rb
126
134
  - lib/arel_extensions/nodes/floor.rb
127
135
  - lib/arel_extensions/nodes/format.rb
128
- - lib/arel_extensions/nodes/formatted_date.rb
129
136
  - lib/arel_extensions/nodes/formatted_number.rb
130
137
  - lib/arel_extensions/nodes/function.rb
131
138
  - lib/arel_extensions/nodes/is_null.rb
@@ -140,13 +147,10 @@ files:
140
147
  - lib/arel_extensions/nodes/rand.rb
141
148
  - lib/arel_extensions/nodes/repeat.rb
142
149
  - lib/arel_extensions/nodes/replace.rb
143
- - lib/arel_extensions/nodes/rollup.rb
144
150
  - lib/arel_extensions/nodes/round.rb
145
- - lib/arel_extensions/nodes/select.rb
146
151
  - lib/arel_extensions/nodes/soundex.rb
147
152
  - lib/arel_extensions/nodes/std.rb
148
153
  - lib/arel_extensions/nodes/substring.rb
149
- - lib/arel_extensions/nodes/sum.rb
150
154
  - lib/arel_extensions/nodes/then.rb
151
155
  - lib/arel_extensions/nodes/trim.rb
152
156
  - lib/arel_extensions/nodes/union.rb
@@ -160,7 +164,6 @@ files:
160
164
  - lib/arel_extensions/tasks.rb
161
165
  - lib/arel_extensions/version.rb
162
166
  - lib/arel_extensions/visitors.rb
163
- - lib/arel_extensions/visitors/convert_format.rb
164
167
  - lib/arel_extensions/visitors/ibm_db.rb
165
168
  - lib/arel_extensions/visitors/mssql.rb
166
169
  - lib/arel_extensions/visitors/mysql.rb
@@ -169,8 +172,8 @@ files:
169
172
  - lib/arel_extensions/visitors/postgresql.rb
170
173
  - lib/arel_extensions/visitors/sqlite.rb
171
174
  - lib/arel_extensions/visitors/to_sql.rb
172
- - test/arelx_test_helper.rb
173
175
  - test/database.yml
176
+ - test/helper.rb
174
177
  - test/real_db_test.rb
175
178
  - test/support/alter_system_user_password.sql
176
179
  - test/support/create_oracle_enhanced_users.sql
@@ -187,8 +190,6 @@ files:
187
190
  - test/with_ar/test_math_sqlite.rb
188
191
  - test/with_ar/test_string_mysql.rb
189
192
  - test/with_ar/test_string_sqlite.rb
190
- - version_v1.rb
191
- - version_v2.rb
192
193
  homepage: https://github.com/Faveod/arel-extensions
193
194
  licenses:
194
195
  - MIT
@@ -206,11 +207,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
207
  version: '0'
207
208
  required_rubygems_version: !ruby/object:Gem::Requirement
208
209
  requirements:
209
- - - ">="
210
+ - - ">"
210
211
  - !ruby/object:Gem::Version
211
- version: '0'
212
+ version: 1.3.1
212
213
  requirements: []
213
- rubygems_version: 3.3.5
214
+ rubygems_version: 3.0.2
214
215
  signing_key:
215
216
  specification_version: 4
216
217
  summary: Extending Arel