arel_extensions 1.3.4 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +2 -1
  3. data/.rubocop.yml +4 -31
  4. data/.travis/oracle/download.js +152 -0
  5. data/.travis/oracle/download.sh +30 -0
  6. data/.travis/oracle/download_ojdbc.js +116 -0
  7. data/.travis/oracle/install.sh +34 -0
  8. data/.travis/setup_accounts.sh +9 -0
  9. data/.travis/sqlite3/extension-functions.sh +6 -0
  10. data/.travis.yml +223 -0
  11. data/Gemfile +21 -16
  12. data/README.md +14 -125
  13. data/Rakefile +30 -41
  14. data/TODO +1 -0
  15. data/appveyor.yml +44 -0
  16. data/arel_extensions.gemspec +14 -14
  17. data/functions.html +3 -3
  18. data/gemfiles/rails3.gemfile +10 -10
  19. data/gemfiles/rails4.gemfile +14 -14
  20. data/gemfiles/rails5_0.gemfile +14 -14
  21. data/gemfiles/rails5_1_4.gemfile +14 -14
  22. data/gemfiles/rails5_2.gemfile +14 -15
  23. data/init/mssql.sql +4 -4
  24. data/init/mysql.sql +38 -38
  25. data/init/oracle.sql +0 -0
  26. data/init/postgresql.sql +21 -21
  27. data/init/sqlite.sql +0 -0
  28. data/lib/arel_extensions/attributes.rb +3 -4
  29. data/lib/arel_extensions/boolean_functions.rb +14 -53
  30. data/lib/arel_extensions/common_sql_functions.rb +16 -15
  31. data/lib/arel_extensions/comparators.rb +28 -27
  32. data/lib/arel_extensions/date_duration.rb +14 -13
  33. data/lib/arel_extensions/insert_manager.rb +15 -18
  34. data/lib/arel_extensions/math.rb +44 -31
  35. data/lib/arel_extensions/math_functions.rb +39 -46
  36. data/lib/arel_extensions/nodes/abs.rb +1 -0
  37. data/lib/arel_extensions/nodes/blank.rb +2 -1
  38. data/lib/arel_extensions/nodes/case.rb +16 -16
  39. data/lib/arel_extensions/nodes/cast.rb +6 -8
  40. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  41. data/lib/arel_extensions/nodes/coalesce.rb +3 -2
  42. data/lib/arel_extensions/nodes/collate.rb +10 -9
  43. data/lib/arel_extensions/nodes/concat.rb +18 -9
  44. data/lib/arel_extensions/nodes/date_diff.rb +22 -38
  45. data/lib/arel_extensions/nodes/duration.rb +3 -0
  46. data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
  47. data/lib/arel_extensions/nodes/floor.rb +1 -1
  48. data/lib/arel_extensions/nodes/format.rb +8 -35
  49. data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
  50. data/lib/arel_extensions/nodes/function.rb +37 -42
  51. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  52. data/lib/arel_extensions/nodes/json.rb +39 -48
  53. data/lib/arel_extensions/nodes/length.rb +0 -5
  54. data/lib/arel_extensions/nodes/levenshtein_distance.rb +1 -1
  55. data/lib/arel_extensions/nodes/locate.rb +1 -0
  56. data/lib/arel_extensions/nodes/log10.rb +2 -1
  57. data/lib/arel_extensions/nodes/matches.rb +7 -5
  58. data/lib/arel_extensions/nodes/md5.rb +1 -0
  59. data/lib/arel_extensions/nodes/power.rb +5 -5
  60. data/lib/arel_extensions/nodes/rand.rb +1 -0
  61. data/lib/arel_extensions/nodes/repeat.rb +4 -2
  62. data/lib/arel_extensions/nodes/replace.rb +8 -16
  63. data/lib/arel_extensions/nodes/round.rb +6 -5
  64. data/lib/arel_extensions/nodes/soundex.rb +15 -15
  65. data/lib/arel_extensions/nodes/std.rb +21 -18
  66. data/lib/arel_extensions/nodes/substring.rb +16 -8
  67. data/lib/arel_extensions/nodes/trim.rb +5 -3
  68. data/lib/arel_extensions/nodes/union.rb +8 -5
  69. data/lib/arel_extensions/nodes/union_all.rb +7 -4
  70. data/lib/arel_extensions/nodes/wday.rb +4 -0
  71. data/lib/arel_extensions/nodes.rb +1 -1
  72. data/lib/arel_extensions/null_functions.rb +7 -5
  73. data/lib/arel_extensions/predications.rb +43 -44
  74. data/lib/arel_extensions/railtie.rb +5 -5
  75. data/lib/arel_extensions/set_functions.rb +7 -5
  76. data/lib/arel_extensions/string_functions.rb +29 -58
  77. data/lib/arel_extensions/tasks.rb +6 -6
  78. data/lib/arel_extensions/version.rb +1 -1
  79. data/lib/arel_extensions/visitors/ibm_db.rb +31 -24
  80. data/lib/arel_extensions/visitors/mssql.rb +184 -269
  81. data/lib/arel_extensions/visitors/mysql.rb +206 -271
  82. data/lib/arel_extensions/visitors/oracle.rb +175 -191
  83. data/lib/arel_extensions/visitors/oracle12.rb +31 -18
  84. data/lib/arel_extensions/visitors/postgresql.rb +170 -244
  85. data/lib/arel_extensions/visitors/sqlite.rb +124 -138
  86. data/lib/arel_extensions/visitors/to_sql.rb +237 -269
  87. data/lib/arel_extensions/visitors.rb +59 -75
  88. data/lib/arel_extensions.rb +31 -149
  89. data/test/database.yml +7 -15
  90. data/test/helper.rb +18 -0
  91. data/test/real_db_test.rb +113 -102
  92. data/test/support/fake_record.rb +3 -3
  93. data/test/test_comparators.rb +17 -14
  94. data/test/visitors/test_bulk_insert_oracle.rb +10 -10
  95. data/test/visitors/test_bulk_insert_sqlite.rb +12 -11
  96. data/test/visitors/test_bulk_insert_to_sql.rb +12 -10
  97. data/test/visitors/test_oracle.rb +55 -55
  98. data/test/visitors/test_to_sql.rb +226 -419
  99. data/test/with_ar/all_agnostic_test.rb +357 -567
  100. data/test/with_ar/insert_agnostic_test.rb +19 -25
  101. data/test/with_ar/test_bulk_sqlite.rb +15 -16
  102. data/test/with_ar/test_math_sqlite.rb +26 -26
  103. data/test/with_ar/test_string_mysql.rb +33 -31
  104. data/test/with_ar/test_string_sqlite.rb +34 -30
  105. metadata +23 -29
  106. data/.github/workflows/ruby.yml +0 -389
  107. data/gemfiles/rails6.gemfile +0 -29
  108. data/gemfiles/rails6_1.gemfile +0 -29
  109. data/gemfiles/rails7.gemfile +0 -22
  110. data/gemspecs/arel_extensions-v1.gemspec +0 -28
  111. data/gemspecs/arel_extensions-v2.gemspec +0 -28
  112. data/generate_gems.sh +0 -15
  113. data/lib/arel_extensions/aliases.rb +0 -14
  114. data/lib/arel_extensions/helpers.rb +0 -51
  115. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
  116. data/lib/arel_extensions/nodes/sum.rb +0 -7
  117. data/lib/arel_extensions/visitors/convert_format.rb +0 -37
  118. data/test/arelx_test_helper.rb +0 -71
  119. data/version_v1.rb +0 -3
  120. 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
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
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
- ['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
@@ -29,21 +27,22 @@ module ArelExtensions
29
27
  @table = Arel::Table.new(:users)
30
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.4
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: 2022-03-24 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
@@ -44,30 +44,30 @@ dependencies:
44
44
  name: rdoc
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
47
+ - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 6.3.1
49
+ version: '4.0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">="
54
+ - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 6.3.1
56
+ version: '4.0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rake
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 12.3.3
63
+ version: '11'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: 12.3.3
70
+ version: '11'
71
71
  description: Adds new features to Arel
72
72
  email:
73
73
  - yann.azoury@faveod.com
@@ -81,15 +81,22 @@ extra_rdoc_files:
81
81
  - functions.html
82
82
  files:
83
83
  - ".codeclimate.yml"
84
- - ".github/workflows/ruby.yml"
85
84
  - ".gitignore"
86
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"
87
93
  - Gemfile
88
94
  - MIT-LICENSE.txt
89
95
  - README.md
90
96
  - Rakefile
91
97
  - SQL_Challenges.md
92
98
  - TODO
99
+ - appveyor.yml
93
100
  - arel_extensions.gemspec
94
101
  - functions.html
95
102
  - gemfiles/rails3.gemfile
@@ -97,31 +104,22 @@ files:
97
104
  - gemfiles/rails5_0.gemfile
98
105
  - gemfiles/rails5_1_4.gemfile
99
106
  - gemfiles/rails5_2.gemfile
100
- - gemfiles/rails6.gemfile
101
- - gemfiles/rails6_1.gemfile
102
- - gemfiles/rails7.gemfile
103
- - gemspecs/arel_extensions-v1.gemspec
104
- - gemspecs/arel_extensions-v2.gemspec
105
- - generate_gems.sh
106
107
  - init/mssql.sql
107
108
  - init/mysql.sql
108
109
  - init/oracle.sql
109
110
  - init/postgresql.sql
110
111
  - init/sqlite.sql
111
112
  - lib/arel_extensions.rb
112
- - lib/arel_extensions/aliases.rb
113
113
  - lib/arel_extensions/attributes.rb
114
114
  - lib/arel_extensions/boolean_functions.rb
115
115
  - lib/arel_extensions/common_sql_functions.rb
116
116
  - lib/arel_extensions/comparators.rb
117
117
  - lib/arel_extensions/date_duration.rb
118
- - lib/arel_extensions/helpers.rb
119
118
  - lib/arel_extensions/insert_manager.rb
120
119
  - lib/arel_extensions/math.rb
121
120
  - lib/arel_extensions/math_functions.rb
122
121
  - lib/arel_extensions/nodes.rb
123
122
  - lib/arel_extensions/nodes/abs.rb
124
- - lib/arel_extensions/nodes/aggregate_function.rb
125
123
  - lib/arel_extensions/nodes/blank.rb
126
124
  - lib/arel_extensions/nodes/case.rb
127
125
  - lib/arel_extensions/nodes/cast.rb
@@ -153,7 +151,6 @@ files:
153
151
  - lib/arel_extensions/nodes/soundex.rb
154
152
  - lib/arel_extensions/nodes/std.rb
155
153
  - lib/arel_extensions/nodes/substring.rb
156
- - lib/arel_extensions/nodes/sum.rb
157
154
  - lib/arel_extensions/nodes/then.rb
158
155
  - lib/arel_extensions/nodes/trim.rb
159
156
  - lib/arel_extensions/nodes/union.rb
@@ -167,7 +164,6 @@ files:
167
164
  - lib/arel_extensions/tasks.rb
168
165
  - lib/arel_extensions/version.rb
169
166
  - lib/arel_extensions/visitors.rb
170
- - lib/arel_extensions/visitors/convert_format.rb
171
167
  - lib/arel_extensions/visitors/ibm_db.rb
172
168
  - lib/arel_extensions/visitors/mssql.rb
173
169
  - lib/arel_extensions/visitors/mysql.rb
@@ -176,8 +172,8 @@ files:
176
172
  - lib/arel_extensions/visitors/postgresql.rb
177
173
  - lib/arel_extensions/visitors/sqlite.rb
178
174
  - lib/arel_extensions/visitors/to_sql.rb
179
- - test/arelx_test_helper.rb
180
175
  - test/database.yml
176
+ - test/helper.rb
181
177
  - test/real_db_test.rb
182
178
  - test/support/alter_system_user_password.sql
183
179
  - test/support/create_oracle_enhanced_users.sql
@@ -194,8 +190,6 @@ files:
194
190
  - test/with_ar/test_math_sqlite.rb
195
191
  - test/with_ar/test_string_mysql.rb
196
192
  - test/with_ar/test_string_sqlite.rb
197
- - version_v1.rb
198
- - version_v2.rb
199
193
  homepage: https://github.com/Faveod/arel-extensions
200
194
  licenses:
201
195
  - MIT
@@ -213,11 +207,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
207
  version: '0'
214
208
  required_rubygems_version: !ruby/object:Gem::Requirement
215
209
  requirements:
216
- - - ">="
210
+ - - ">"
217
211
  - !ruby/object:Gem::Version
218
- version: '0'
212
+ version: 1.3.1
219
213
  requirements: []
220
- rubygems_version: 3.2.3
214
+ rubygems_version: 3.0.2
221
215
  signing_key:
222
216
  specification_version: 4
223
217
  summary: Extending Arel