arel_extensions 1.2.15 → 1.2.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +102 -0
  3. data/.travis.yml +2 -0
  4. data/Gemfile +10 -10
  5. data/Rakefile +4 -4
  6. data/arel_extensions.gemspec +1 -1
  7. data/gemfiles/rails3.gemfile +9 -9
  8. data/gemfiles/rails4.gemfile +13 -13
  9. data/gemfiles/rails5_0.gemfile +13 -13
  10. data/gemfiles/rails5_1_4.gemfile +13 -13
  11. data/gemfiles/rails5_2.gemfile +13 -13
  12. data/gemfiles/rails6.gemfile +13 -13
  13. data/gemfiles/rails6_1.gemfile +30 -0
  14. data/gemspecs/arel_extensions-v1.gemspec +28 -0
  15. data/{gemspec_v2 → gemspecs}/arel_extensions-v2.gemspec +0 -0
  16. data/generate_gems.sh +4 -3
  17. data/lib/arel_extensions.rb +11 -5
  18. data/lib/arel_extensions/attributes.rb +0 -0
  19. data/lib/arel_extensions/boolean_functions.rb +21 -5
  20. data/lib/arel_extensions/common_sql_functions.rb +2 -4
  21. data/lib/arel_extensions/comparators.rb +11 -14
  22. data/lib/arel_extensions/date_duration.rb +4 -5
  23. data/lib/arel_extensions/insert_manager.rb +16 -17
  24. data/lib/arel_extensions/math.rb +8 -9
  25. data/lib/arel_extensions/math_functions.rb +22 -20
  26. data/lib/arel_extensions/nodes/abs.rb +0 -1
  27. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -1
  28. data/lib/arel_extensions/nodes/blank.rb +0 -1
  29. data/lib/arel_extensions/nodes/case.rb +3 -4
  30. data/lib/arel_extensions/nodes/cast.rb +4 -2
  31. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  32. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  33. data/lib/arel_extensions/nodes/coalesce.rb +0 -1
  34. data/lib/arel_extensions/nodes/collate.rb +0 -1
  35. data/lib/arel_extensions/nodes/concat.rb +2 -4
  36. data/lib/arel_extensions/nodes/date_diff.rb +7 -8
  37. data/lib/arel_extensions/nodes/duration.rb +0 -1
  38. data/lib/arel_extensions/nodes/find_in_set.rb +0 -1
  39. data/lib/arel_extensions/nodes/floor.rb +1 -1
  40. data/lib/arel_extensions/nodes/format.rb +27 -1
  41. data/lib/arel_extensions/nodes/formatted_number.rb +0 -1
  42. data/lib/arel_extensions/nodes/function.rb +24 -17
  43. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  44. data/lib/arel_extensions/nodes/json.rb +11 -17
  45. data/lib/arel_extensions/nodes/length.rb +0 -1
  46. data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
  47. data/lib/arel_extensions/nodes/locate.rb +0 -1
  48. data/lib/arel_extensions/nodes/log10.rb +1 -2
  49. data/lib/arel_extensions/nodes/matches.rb +0 -2
  50. data/lib/arel_extensions/nodes/md5.rb +0 -1
  51. data/lib/arel_extensions/nodes/power.rb +0 -1
  52. data/lib/arel_extensions/nodes/rand.rb +0 -1
  53. data/lib/arel_extensions/nodes/repeat.rb +0 -2
  54. data/lib/arel_extensions/nodes/replace.rb +0 -2
  55. data/lib/arel_extensions/nodes/round.rb +0 -1
  56. data/lib/arel_extensions/nodes/soundex.rb +0 -1
  57. data/lib/arel_extensions/nodes/std.rb +4 -5
  58. data/lib/arel_extensions/nodes/substring.rb +0 -1
  59. data/lib/arel_extensions/nodes/sum.rb +0 -0
  60. data/lib/arel_extensions/nodes/then.rb +0 -0
  61. data/lib/arel_extensions/nodes/trim.rb +0 -2
  62. data/lib/arel_extensions/nodes/union.rb +0 -2
  63. data/lib/arel_extensions/nodes/union_all.rb +0 -2
  64. data/lib/arel_extensions/nodes/wday.rb +0 -4
  65. data/lib/arel_extensions/null_functions.rb +3 -5
  66. data/lib/arel_extensions/predications.rb +5 -6
  67. data/lib/arel_extensions/railtie.rb +5 -5
  68. data/lib/arel_extensions/set_functions.rb +0 -2
  69. data/lib/arel_extensions/string_functions.rb +21 -22
  70. data/lib/arel_extensions/tasks.rb +1 -1
  71. data/lib/arel_extensions/version.rb +1 -1
  72. data/lib/arel_extensions/visitors.rb +68 -60
  73. data/lib/arel_extensions/visitors/convert_format.rb +37 -0
  74. data/lib/arel_extensions/visitors/ibm_db.rb +4 -11
  75. data/lib/arel_extensions/visitors/mssql.rb +49 -44
  76. data/lib/arel_extensions/visitors/mysql.rb +65 -67
  77. data/lib/arel_extensions/visitors/oracle.rb +58 -55
  78. data/lib/arel_extensions/visitors/oracle12.rb +1 -14
  79. data/lib/arel_extensions/visitors/postgresql.rb +41 -34
  80. data/lib/arel_extensions/visitors/sqlite.rb +23 -18
  81. data/lib/arel_extensions/visitors/to_sql.rb +59 -47
  82. data/test/arelx_test_helper.rb +0 -2
  83. data/test/database.yml +2 -0
  84. data/test/real_db_test.rb +27 -42
  85. data/test/support/fake_record.rb +1 -1
  86. data/test/test_comparators.rb +0 -4
  87. data/test/visitors/test_bulk_insert_oracle.rb +0 -1
  88. data/test/visitors/test_bulk_insert_sqlite.rb +0 -2
  89. data/test/visitors/test_oracle.rb +1 -2
  90. data/test/visitors/test_to_sql.rb +16 -25
  91. data/test/with_ar/all_agnostic_test.rb +141 -139
  92. data/test/with_ar/insert_agnostic_test.rb +0 -2
  93. data/test/with_ar/test_bulk_sqlite.rb +0 -4
  94. data/test/with_ar/test_math_sqlite.rb +4 -8
  95. data/test/with_ar/test_string_mysql.rb +1 -5
  96. data/test/with_ar/test_string_sqlite.rb +1 -5
  97. data/version_v1.rb +1 -1
  98. data/version_v2.rb +1 -1
  99. metadata +8 -4
@@ -22,7 +22,5 @@ module Minitest::Assertions
22
22
  end
23
23
 
24
24
  module Minitest::Expectations
25
-
26
25
  infect_an_assertion :assert_like, :must_be_like
27
-
28
26
  end
data/test/database.yml CHANGED
@@ -10,6 +10,8 @@ mysql:
10
10
  adapter: mysql2
11
11
  database: arext_test
12
12
  username: travis
13
+ host: 127.0.0.1
14
+ port: 3306
13
15
  encoding: utf8
14
16
  jdbc-mysql:
15
17
  adapter: jdbcmysql
data/test/real_db_test.rb CHANGED
@@ -21,10 +21,10 @@ def setup_db
21
21
  db.enable_load_extension(0)
22
22
  rescue => e
23
23
  $load_extension_disabled = true
24
- $stderr << "can not load extensions #{e.inspect}\n"
24
+ $stderr << "cannot load extensions #{e.inspect}\n"
25
25
  end
26
26
  end
27
- #function find_in_set
27
+ # function find_in_set
28
28
  db.create_function("find_in_set", 1) do |func, value1, value2|
29
29
  func.result = value1.index(value2)
30
30
  end
@@ -44,15 +44,13 @@ def teardown_db
44
44
  end
45
45
 
46
46
  class User < ActiveRecord::Base
47
-
48
47
  end
49
48
 
50
49
  class ListTest < Minitest::Test
51
-
52
50
  def setup
53
51
  d = Date.new(2016,05,23)
54
52
  setup_db
55
- User.create :age => 5, :name => "Lucas", :created_at => d , :score => 20.16
53
+ User.create :age => 5, :name => "Lucas", :created_at => d, :score => 20.16
56
54
  User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
57
55
  User.create :age => 20, :name => "Camille", :created_at => d, :score => 20.16
58
56
  User.create :age => 21, :name => "Arthur", :created_at => d, :score => 65.62
@@ -90,30 +88,28 @@ class ListTest < Minitest::Test
90
88
  end
91
89
 
92
90
  def test_Comparator
93
- assert_equal 2,User.where(User.arel_table[:age] < 6 ).count
94
- assert_equal 2,User.where(User.arel_table[:age] <=10 ).count
95
- assert_equal 3,User.where(User.arel_table[:age] > 20 ).count
96
- assert_equal 4,User.where(User.arel_table[:age] >=20 ).count
97
- assert_equal 1,User.where(User.arel_table[:age] > 5 ).where(User.arel_table[:age] < 20 ).count
91
+ assert_equal 2,User.where(User.arel_table[:age] < 6).count
92
+ assert_equal 2,User.where(User.arel_table[:age] <=10).count
93
+ assert_equal 3,User.where(User.arel_table[:age] > 20).count
94
+ assert_equal 4,User.where(User.arel_table[:age] >=20).count
95
+ assert_equal 1,User.where(User.arel_table[:age] > 5).where(User.arel_table[:age] < 20).count
98
96
  end
99
97
 
100
98
  def test_date_duration
101
- #Year
99
+ # Year
102
100
  assert_equal 2016,User.where(User.arel_table[:name].eq("Lucas")).select((User.arel_table[:created_at].year).as("res")).first.res.to_i
103
101
  assert_equal 0,User.where(User.arel_table[:created_at].year.eq("2012")).count
104
- #Month
102
+ # Month
105
103
  assert_equal 5,User.where(User.arel_table[:name].eq("Camille")).select((User.arel_table[:created_at].month).as("res")).first.res.to_i
106
104
  assert_equal 8,User.where(User.arel_table[:created_at].month.eq("05")).count
107
- #Week
105
+ # Week
108
106
  assert_equal 21,User.where(User.arel_table[:name].eq("Arthur")).select((User.arel_table[:created_at].week).as("res")).first.res.to_i
109
107
  assert_equal 8,User.where(User.arel_table[:created_at].month.eq("05")).count
110
- #Day
108
+ # Day
111
109
  assert_equal 23,User.where(User.arel_table[:name].eq("Laure")).select((User.arel_table[:created_at].day).as("res")).first.res.to_i
112
110
  assert_equal 0,User.where(User.arel_table[:created_at].day.eq("05")).count
113
111
  end
114
112
 
115
-
116
-
117
113
  def test_length
118
114
  assert_equal 7,User.where(User.arel_table[:name].eq("Camille")).select((User.arel_table[:name].length).as("res")).first.res
119
115
  assert_equal 5,User.where(User.arel_table[:name].eq("Laure")).select((User.arel_table[:name].length).as("res")).first.res
@@ -136,7 +132,6 @@ class ListTest < Minitest::Test
136
132
  end
137
133
  end
138
134
 
139
-
140
135
  def test_floor
141
136
  if !$sqlite || !$load_extension_disabled
142
137
  assert_equal 0,User.where(User.arel_table[:name].eq("Negatif")).select((User.arel_table[:score].floor).as("res")).first.res
@@ -144,57 +139,51 @@ class ListTest < Minitest::Test
144
139
  end
145
140
  end
146
141
 
147
-
148
142
  def test_findinset
149
143
  db = ActiveRecord::Base.connection.raw_connection
150
- assert_equal 3,db.get_first_value( "select find_in_set(name,'i') from users where name = 'Camille'" )
151
- assert_equal "",db.get_first_value( "select find_in_set(name,'p') from users where name = 'Camille'" ).to_s
152
- #number
153
- #assert_equal 1,User.select(User.arel_table[:name] & ("l")).count
154
- #assert_equal 3,(User.select(User.arel_table[:age] & [5,15,20]))
155
- #string
144
+ assert_equal 3,db.get_first_value("select find_in_set(name,'i') from users where name = 'Camille'")
145
+ assert_equal "",db.get_first_value("select find_in_set(name,'p') from users where name = 'Camille'").to_s
146
+ # number
147
+ # assert_equal 1,User.select(User.arel_table[:name] & ("l")).count
148
+ # assert_equal 3,(User.select(User.arel_table[:age] & [5,15,20]))
149
+ # string
156
150
  end
157
151
 
158
-
159
152
  def test_math_plus
160
153
  d = Date.new(1997,06,15)
161
- #Concat String
154
+ # Concat String
162
155
  assert_equal "SophiePhan",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + "Phan").as("res")).first.res
163
- assert_equal "Sophie2",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + 2 ).as("res")).first.res
156
+ assert_equal "Sophie2",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + 2).as("res")).first.res
164
157
  assert_equal "Sophie1997-06-15",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + d).as("res")).first.res
165
158
  assert_equal "Sophie15",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + User.arel_table[:age]).as("res")).first.res
166
159
  assert_equal "SophieSophie",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + User.arel_table[:name]).as("res")).first.res
167
160
  assert_equal "Sophie2016-05-23",User.where(User.arel_table[:name].eq("Sophie")).select((User.arel_table[:name] + User.arel_table[:created_at]).as("res")).first.res
168
- #concat Integer
161
+ # concat Integer
169
162
  assert_equal 1, User.where((User.arel_table[:age] + 10).eq(33)).count
170
163
  assert_equal 1, User.where((User.arel_table[:age] + "1").eq(6)).count
171
164
  assert_equal 1, User.where((User.arel_table[:age] + User.arel_table[:age]).eq(10)).count
172
- #concat Date
173
- # puts((User.arel_table[:created_at] + 1).as("res").to_sql.inspect)
165
+ # concat Date
166
+ # puts((User.arel_table[:created_at] + 1).as("res").to_sql.inspect)
174
167
  assert_equal "2016-05-24", @myung.select((User.arel_table[:created_at] + 1).as("res")).first.res.to_date.to_s
175
168
  assert_equal "2016-05-25", @myung.select((User.arel_table[:created_at] + 2.day).as("res")).first.res.to_date.to_s
176
169
  end
177
170
 
178
-
179
171
  def test_math_moins
180
172
  d = Date.new(2016,05,20)
181
- #Datediff
173
+ # Datediff
182
174
  assert_equal 8,User.where((User.arel_table[:created_at] - User.arel_table[:created_at]).eq(0)).count
183
175
  assert_equal 3,User.where(User.arel_table[:name].eq("Laure")).select((User.arel_table[:created_at] - d).as("res")).first.res.abs.to_i
184
- #Substraction
176
+ # Substraction
185
177
  assert_equal 0, User.where((User.arel_table[:age] - 10).eq(50)).count
186
178
  assert_equal 0, User.where((User.arel_table[:age] - "10").eq(50)).count
187
179
  end
188
180
 
189
-
190
-
191
181
  def test_rand
192
182
  assert_equal 5,User.where(User.arel_table[:score].eq(20.16)).select(User.arel_table[:id]).order(Arel.rand).take(50).count
193
- #test_alias :random :rand
183
+ # test_alias :random :rand
194
184
  assert_equal 8,User.select(User.arel_table[:name]).order(Arel.rand).take(50).count
195
185
  end
196
186
 
197
-
198
187
  def test_regexp_not_regex
199
188
  if !$sqlite || !$load_extension_disabled
200
189
  assert_equal 1, User.where(User.arel_table[:name] =~ '^M').count
@@ -207,13 +196,11 @@ class ListTest < Minitest::Test
207
196
  assert_equal "replace",User.where(User.arel_table[:name].eq("Lucas")).select(((User.arel_table[:name]).replace(User.arel_table[:name],"replace")).as("res")).first.res
208
197
  end
209
198
 
210
-
211
199
  def test_round
212
200
  assert_equal 1, User.where(((User.arel_table[:age]).round(0)).eq(5.0)).count
213
201
  assert_equal 0, User.where(((User.arel_table[:age]).round(-1)).eq(6.0)).count
214
202
  end
215
203
 
216
-
217
204
  def test_Soundex
218
205
  if !$sqlite || !$load_extension_disabled
219
206
  assert_equal "C540",User.where(User.arel_table[:name].eq("Camille")).select((User.arel_table[:name].soundex).as("res")).first.res.to_s
@@ -222,14 +209,13 @@ class ListTest < Minitest::Test
222
209
  end
223
210
 
224
211
  def test_Sum
225
- #.take(50) because of limit by ORDER BY
212
+ # .take(50) because of limit by ORDER BY
226
213
  assert_equal 110,User.select((User.arel_table[:age].sum + 1).as("res")).take(50).first.res
227
214
  assert_equal 218,User.select((User.arel_table[:age].sum + User.arel_table[:age].sum).as("res")).take(50).first.res
228
215
  assert_equal 327,User.select(((User.arel_table[:age] * 3).sum).as("res")).take(50).first.res
229
216
  assert_equal 2245,User.select(((User.arel_table[:age] * User.arel_table[:age]).sum).as("res")).take(50).first.res
230
217
  end
231
218
 
232
-
233
219
  def test_trim
234
220
  assert_equal "Myun",User.where(User.arel_table[:name].eq("Myung")).select(User.arel_table[:name].rtrim("g").as("res")).first.res
235
221
  assert_equal "yung",User.where(User.arel_table[:name].eq("Myung")).select(User.arel_table[:name].ltrim("M").as("res")).first.res
@@ -243,5 +229,4 @@ class ListTest < Minitest::Test
243
229
  assert_equal 1,User.where(User.arel_table[:name].eq("Myung")).select((User.arel_table[:created_at].wday).as("res")).first.res.to_i
244
230
  assert_equal 0,User.select(d.wday).as("res").first.to_i
245
231
  end
246
-
247
232
  end
@@ -7,7 +7,7 @@ module FakeRecord
7
7
  attr_accessor :visitor
8
8
 
9
9
  def initialize(visitor = nil)
10
- @tables = %w{ users photos developers products}
10
+ @tables = %w{users photos developers products}
11
11
  @columns = {
12
12
  'users' => [
13
13
  Column.new('id', :integer),
@@ -2,9 +2,7 @@ require 'arelx_test_helper'
2
2
 
3
3
  module ArelExtensions
4
4
  module Nodes
5
-
6
5
  describe ArelExtensions::Comparators do
7
-
8
6
  before do
9
7
  @conn = FakeRecord::Base.new
10
8
  Arel::Table.engine = @conn
@@ -39,8 +37,6 @@ module ArelExtensions
39
37
  _(compile(@table[:created_at] >= Date.new(2016, 3, 31)))
40
38
  .must_be_like %{"users"."created_at" >= '2016-03-31'}
41
39
  end
42
-
43
40
  end
44
-
45
41
  end
46
42
  end
@@ -29,7 +29,6 @@ module ArelExtensions
29
29
  .must_be_like %Q[INSERT INTO "users" ("name", "comments", "created_at")
30
30
  ((SELECT 'nom1', 'sdfdsfdsfsdf', '2016-01-01' FROM DUAL) UNION ALL (SELECT 'nom2', 'sdfdsfdsfsdf', '2016-01-01' FROM DUAL))]
31
31
  end
32
-
33
32
  end
34
33
  end
35
34
  end
@@ -2,7 +2,6 @@ require 'arelx_test_helper'
2
2
 
3
3
  module ArelExtensions
4
4
  module BulkInsertSQLlite
5
-
6
5
  describe 'the sqlite visitor can bulk insert' do
7
6
  before do
8
7
  @conn = FakeRecord::Base.new
@@ -31,7 +30,6 @@ module ArelExtensions
31
30
  .must_be_like %Q[INSERT INTO "users" ("id", "name", "comments", "created_at")
32
31
  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']
33
32
  end
34
-
35
33
  end
36
34
  end
37
35
  end
@@ -70,7 +70,7 @@ module ArelExtensions
70
70
 
71
71
  it "should diff date col and datetime col with AS" do
72
72
  sql = compile((@table[:updated_at] - @table[:created_at]).as('new_name'))
73
- # sql.must_be_like %{(TO_DATE("users"."updated_at") - "users"."created_at") * 86400 AS new_name}
73
+ # sql.must_be_like %{(TO_DATE("users"."updated_at") - "users"."created_at") * 86400 AS new_name}
74
74
  _(sql).must_be_like %{("users"."updated_at" - "users"."created_at") * (CASE WHEN (TRUNC("users"."updated_at", 'DDD') = "users"."updated_at") THEN 1 ELSE 86400 END) AS new_name}
75
75
  end
76
76
 
@@ -104,7 +104,6 @@ module ArelExtensions
104
104
  _(compile(c =~ /\Atest\Z/)).must_be_like %{REGEXP_LIKE("users"."name", '^test$')}
105
105
  _(compile(c !~ /\Ate\Dst\Z/)).must_be_like %{NOT REGEXP_LIKE("users"."name", '^te[^0-9]st$')}
106
106
  end
107
-
108
107
  end
109
108
  end
110
109
  end
@@ -23,7 +23,6 @@ module ArelExtensions
23
23
  end
24
24
 
25
25
  describe "primitive methods" do
26
-
27
26
  it "should be able to recognize equal nodes" do
28
27
  c = @table[:id]
29
28
  _(c == 1).must_be :eql?, (c == 1)
@@ -32,7 +31,6 @@ module ArelExtensions
32
31
 
33
32
  _([c == 1, c == 1].uniq).must_equal [c == 1]
34
33
  end
35
-
36
34
  end
37
35
 
38
36
  # Math Functions
@@ -53,7 +51,7 @@ module ArelExtensions
53
51
  end
54
52
 
55
53
  it "should return right calculations on numbers" do
56
- #puts (@price.abs + 42).inspect
54
+ # puts (@price.abs + 42).inspect
57
55
  _(compile(@price.abs + 42)).must_be_like %{(ABS("products"."price") + 42)}
58
56
  _(compile(@price.ceil + 42)).must_be_like %{(CEIL("products"."price") + 42)}
59
57
  _(compile(@price.floor + 42)).must_be_like %{(FLOOR("products"."price") + 42)}
@@ -93,7 +91,7 @@ module ArelExtensions
93
91
  c = @table[:name]
94
92
  _(compile(c + 'test')).must_be_like %{CONCAT(\"users\".\"name\", 'test')}
95
93
  _(compile(c.length)).must_be_like %{LENGTH("users"."name")}
96
- #puts (c.length.round + 42).inspect
94
+ # puts (c.length.round + 42).inspect
97
95
  _(compile(c.length.round + 42)).must_be_like %{(ROUND(LENGTH("users"."name")) + 42)}
98
96
  _(compile(c.locate('test'))).must_be_like %{LOCATE('test', "users"."name")}
99
97
  _(compile(c & 42)).must_be_like %{FIND_IN_SET(42, "users"."name")}
@@ -119,7 +117,7 @@ module ArelExtensions
119
117
  _(compile(Arel::Nodes.build_quoted('test') + ' chain')).must_be_like %{'test chain'}
120
118
  _(compile(c + '' + c)).must_be_like %{CONCAT(\"users\".\"name\", \"users\".\"name\")}
121
119
 
122
- _(compile(c.md5)).must_be_like %{MD5(\"users\".\"name\")}
120
+ _(compile(c.md5)).must_be_like %{MD5(\"users\".\"name\")}
123
121
  end
124
122
 
125
123
  # Comparators
@@ -135,9 +133,9 @@ module ArelExtensions
135
133
  _(compile(@table[:id] <= 42)).must_match %{"users"."id" <= 42}
136
134
  _(compile((@table[:id] <= 42).as('new_name'))).must_match %{("users"."id" <= 42) AS new_name}
137
135
  _(compile(@table[:id].count.eq 42)).must_match %{COUNT("users"."id") = 42}
138
- #_(compile(@table[:id].count == 42)).must_match %{COUNT("users"."id") = 42} # TODO
139
- #_(compile(@table[:id].count != 42)).must_match %{COUNT("users"."id") != 42}
140
- #_(compile(@table[:id].count >= 42)).must_match %{COUNT("users"."id") >= 42}
136
+ # _(compile(@table[:id].count == 42)).must_match %{COUNT("users"."id") = 42} # TODO
137
+ # _(compile(@table[:id].count != 42)).must_match %{COUNT("users"."id") != 42}
138
+ # _(compile(@table[:id].count >= 42)).must_match %{COUNT("users"."id") >= 42}
141
139
  end
142
140
 
143
141
  it "should accept comparators on dates" do
@@ -201,7 +199,7 @@ module ArelExtensions
201
199
 
202
200
  it "should accept operators on dates with numbers" do
203
201
  c = @table[:created_at]
204
- #u = @table[:updated_at]
202
+ # u = @table[:updated_at]
205
203
  _(compile(c - 42)).must_be_like %{DATE_SUB("users"."created_at", 42)}
206
204
  _(compile(c - @table[:id])).must_be_like %{DATE_SUB("users"."created_at", "users"."id")}
207
205
  end
@@ -300,7 +298,7 @@ module ArelExtensions
300
298
  c = @table[:name]
301
299
  _(compile(c.soundex == 'test')).must_be_like %{SOUNDEX("users"."name") = 'test'}
302
300
  _(compile(c.soundex != 'test')).must_be_like %{SOUNDEX("users"."name") != 'test'}
303
- _(compile(c.length >= 0 )).must_be_like %{LENGTH("users"."name") >= 0}
301
+ _(compile(c.length >= 0)).must_be_like %{LENGTH("users"."name") >= 0}
304
302
  end
305
303
 
306
304
  it "should accept in on select statement" do
@@ -339,7 +337,6 @@ module ArelExtensions
339
337
  end
340
338
 
341
339
  describe "the function in" do
342
-
343
340
  it "should be possible to have nil element in the function IN" do
344
341
  _(compile(@table[:id].in(nil)))
345
342
  .must_be_like %{ISNULL("users"."id")}
@@ -362,14 +359,14 @@ module ArelExtensions
362
359
  it "should be possible to correctly use a Range on an IN" do
363
360
  _(compile(@table[:id].in(1..4)))
364
361
  .must_be_like %{"users"."id" BETWEEN (1) AND (4)}
365
- _(compile(@table[:created_at].in(Date.new(2016, 3, 31) .. Date.new(2017, 3, 31))))
362
+ _(compile(@table[:created_at].in(Date.new(2016, 3, 31)..Date.new(2017, 3, 31))))
366
363
  .must_be_like %{"users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31')}
367
364
  end
368
365
 
369
366
  it "should be possible to use a list of values and ranges on an IN" do
370
367
  _(compile(@table[:id].in [1..10, 20, 30, 40..50]))
371
368
  .must_be_like %{("users"."id" IN (20, 30)) OR ("users"."id" BETWEEN (1) AND (10)) OR ("users"."id" BETWEEN (40) AND (50))}
372
- _(compile(@table[:created_at].in(Date.new(2016, 1, 1), Date.new(2016, 2, 1)..Date.new(2016, 2, 28), Date.new(2016, 3, 31) .. Date.new(2017, 3, 31), Date.new(2018, 1, 1))))
369
+ _(compile(@table[:created_at].in(Date.new(2016, 1, 1), Date.new(2016, 2, 1)..Date.new(2016, 2, 28), Date.new(2016, 3, 31)..Date.new(2017, 3, 31), Date.new(2018, 1, 1))))
373
370
  .must_be_like %{ ("users"."created_at" IN ('2016-01-01', '2018-01-01'))
374
371
  OR ("users"."created_at" BETWEEN ('2016-02-01') AND ('2016-02-28'))
375
372
  OR ("users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31'))}
@@ -385,12 +382,9 @@ module ArelExtensions
385
382
  _(compile(g[@table[:id], @table[:age]].in(g[1, 42], g[2, 51])))
386
383
  .must_be_like %{("users"."id", "users"."age") IN ((1, 42), (2, 51))}
387
384
  end
388
-
389
-
390
385
  end
391
386
 
392
387
  describe "the function not_in" do
393
-
394
388
  it "should be possible to have nil element in the function IN" do
395
389
  _(compile(@table[:id].not_in nil))
396
390
  .must_be_like %{NOT ISNULL("users"."id")}
@@ -415,7 +409,7 @@ module ArelExtensions
415
409
  _(compile(@table[:id].not_in 1..4))
416
410
  .must_be_like %{NOT ("users"."id" BETWEEN (1) AND (4))}
417
411
  # FIXME: Should use NOT BETWEEN
418
- _(compile(@table[:created_at].not_in Date.new(2016, 3, 31) .. Date.new(2017, 3, 31)))
412
+ _(compile(@table[:created_at].not_in Date.new(2016, 3, 31)..Date.new(2017, 3, 31)))
419
413
  .must_be_like %{NOT ("users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31'))}
420
414
  end
421
415
 
@@ -424,12 +418,11 @@ module ArelExtensions
424
418
  .must_be_like %{ ("users"."id" NOT IN (20, 30))
425
419
  AND (NOT ("users"."id" BETWEEN (1) AND (10)))
426
420
  AND (NOT ("users"."id" BETWEEN (40) AND (50)))}
427
- _(compile(@table[:created_at].not_in Date.new(2016, 1, 1), Date.new(2016, 2, 1)..Date.new(2016, 2, 28), Date.new(2016, 3, 31) .. Date.new(2017, 3, 31), Date.new(2018, 1, 1)))
421
+ _(compile(@table[:created_at].not_in Date.new(2016, 1, 1), Date.new(2016, 2, 1)..Date.new(2016, 2, 28), Date.new(2016, 3, 31)..Date.new(2017, 3, 31), Date.new(2018, 1, 1)))
428
422
  .must_be_like %{ ("users"."created_at" NOT IN ('2016-01-01', '2018-01-01'))
429
423
  AND (NOT ("users"."created_at" BETWEEN ('2016-02-01') AND ('2016-02-28')))
430
424
  AND (NOT ("users"."created_at" BETWEEN ('2016-03-31') AND ('2017-03-31')))}
431
425
  end
432
-
433
426
  end
434
427
 
435
428
  it "should be possible to add and substract as much as we want" do
@@ -471,7 +464,6 @@ module ArelExtensions
471
464
  end
472
465
 
473
466
  describe "logical functions" do
474
-
475
467
  it "should know about truth" do
476
468
  _(compile(Arel.false))
477
469
  .must_be_like %{1 = 0}
@@ -544,17 +536,16 @@ module ArelExtensions
544
536
 
545
537
  it "should avoid useless nesting" do
546
538
  c = @table[:id]
547
- _(compile(((c == 1).and(c == 2)) .and ((c == 3).and(c == 4))))
539
+ _(compile(((c == 1).and(c == 2)).and ((c == 3).and(c == 4))))
548
540
  .must_be_like %{("users"."id" = 1) AND ("users"."id" = 2) AND ("users"."id" = 3) AND ("users"."id" = 4)}
549
- _(compile(((c == 1).or(c == 2)) .or ((c == 3).or(c == 4))))
541
+ _(compile(((c == 1).or(c == 2)).or ((c == 3).or(c == 4))))
550
542
  .must_be_like %{("users"."id" = 1) OR ("users"."id" = 2) OR ("users"."id" = 3) OR ("users"."id" = 4)}
551
543
 
552
- _(compile(((c == 1).or(c == 2)) .and ((c == 3).or(c == 4))))
544
+ _(compile(((c == 1).or(c == 2)).and ((c == 3).or(c == 4))))
553
545
  .must_be_like %{(("users"."id" = 1) OR ("users"."id" = 2)) AND (("users"."id" = 3) OR ("users"."id" = 4))}
554
- _(compile(((c == 1).and(c == 2)) .or ((c == 3).and(c == 4))))
546
+ _(compile(((c == 1).and(c == 2)).or ((c == 3).and(c == 4))))
555
547
  .must_be_like %{(("users"."id" = 1) AND ("users"."id" = 2)) OR (("users"."id" = 3) AND ("users"."id" = 4))}
556
548
  end
557
-
558
549
  end
559
550
 
560
551
  puts "AREL VERSION : " + Arel::VERSION.to_s
@@ -3,7 +3,6 @@ require 'date'
3
3
 
4
4
  module ArelExtensions
5
5
  module WthAr
6
-
7
6
  class ListTest < Minitest::Test
8
7
  require 'minitest/pride'
9
8
  def connect_db
@@ -95,7 +94,7 @@ module ArelExtensions
95
94
  scope.select(node.as('res')).to_a.first.res
96
95
  end
97
96
 
98
- #manage the difference between adapters that handle or not json type
97
+ # manage the difference between adapters that handle or not json type
99
98
  def parse_json(h)
100
99
  if @env_db != 'postgresql'
101
100
  JSON.parse("{\"res\":#{h}}")['res']
@@ -117,7 +116,7 @@ module ArelExtensions
117
116
  end
118
117
 
119
118
  def test_ceil
120
- # skip "Sqlite version can't load extension for ceil" if $sqlite && $load_extension_disabled
119
+ # skip "Sqlite version can't load extension for ceil" if $sqlite && $load_extension_disabled
121
120
  assert_equal 2, t(@test, @score.ceil) # 1.62
122
121
  assert_equal(-20, t(@camille, @score.ceil)) # -20.16
123
122
  assert_equal(-20, t(@camille, (@score - 0.5).ceil)) # -20.16
@@ -126,7 +125,7 @@ module ArelExtensions
126
125
  end
127
126
 
128
127
  def test_floor
129
- # skip "Sqlite version can't load extension for floor" if $sqlite && $load_extension_disabled
128
+ # skip "Sqlite version can't load extension for floor" if $sqlite && $load_extension_disabled
130
129
  assert_equal 0, t(@neg, @score.floor)
131
130
  assert_equal 1, t(@test, @score.floor) # 1.62
132
131
  assert_equal(-9, t(@test, (@score - 10).floor)) # 1.62
@@ -163,6 +162,12 @@ module ArelExtensions
163
162
  end
164
163
  end
165
164
 
165
+ def test_aggregation_with_ar_calculation
166
+ # Since Arel10 (Rails6.1), some unwanted behaviors on aggregated calculation were present.
167
+ # This should works no matter which version of rails is used
168
+ assert User.group(:score).average(:id).values.all?{|e| !e.nil?}
169
+ end
170
+
166
171
  # String Functions
167
172
  def test_concat
168
173
  assert_equal 'Camille Camille', t(@camille, @name + ' ' + @name)
@@ -220,7 +225,7 @@ module ArelExtensions
220
225
  assert_equal 'Lu', t(@lucas, @name[0,2])
221
226
  assert_equal 'Lu', t(@lucas, @name[0..1])
222
227
 
223
- #substring should accept string function
228
+ # substring should accept string function
224
229
  assert_equal 'Ce', t(@camille, @name.substring(1, 1).concat('e'))
225
230
  assert_equal 'Ce', t(@camille, @name.substring(1, 1)+'e')
226
231
  end
@@ -233,7 +238,7 @@ module ArelExtensions
233
238
  end
234
239
 
235
240
  def test_string_comparators
236
- #skip "Oracle can't use math operators to compare strings" if @env_db == 'oracle' # use GREATEST ?
241
+ # skip "Oracle can't use math operators to compare strings" if @env_db == 'oracle' # use GREATEST ?
237
242
  skip "SQL Server can't use math operators to compare strings" if @env_db == 'mssql' # use GREATEST ?
238
243
  if @env_db == 'postgresql' # may return real boolean
239
244
  assert t(@neg, @name >= 'Mest') == true || t(@neg, @name >= 'Mest') == 't' # depends of ar version
@@ -254,20 +259,19 @@ module ArelExtensions
254
259
  def test_compare_on_date_time_types
255
260
  skip "Sqlite can't compare time" if $sqlite
256
261
  skip "Oracle can't compare time" if @env_db == 'oracle'
257
- #@created_at == 2016-05-23
262
+ # @created_at == 2016-05-23
258
263
  assert_includes [true,'t',1], t(@laure, ArelExtensions::Nodes::Case.new.when(@created_at >= '2014-01-01').then(1).else(0))
259
264
  assert_includes [false,'f',0], t(@laure, ArelExtensions::Nodes::Case.new.when(@created_at >= '2018-01-01').then(1).else(0))
260
- #@updated_at == 2014-03-03 12:42:00
265
+ # @updated_at == 2014-03-03 12:42:00
261
266
  assert_includes [true,'t',1], t(@laure, ArelExtensions::Nodes::Case.new.when(@updated_at >= '2014-03-03 10:10:10').then(1).else(0))
262
267
  assert_includes [false,'f',0], t(@laure, ArelExtensions::Nodes::Case.new.when(@updated_at >= '2014-03-03 13:10:10').then(1).else(0))
263
- #@duration == 12:42:21
264
- #puts @laure.select(ArelExtensions::Nodes::Case.new.when(@duration >= '10:10:10').then(1).else(0)).to_sql
265
- #puts @laure.select(ArelExtensions::Nodes::Case.new.when(@duration >= '14:10:10').then(1).else(0)).to_sql
268
+ # @duration == 12:42:21
269
+ # puts @laure.select(ArelExtensions::Nodes::Case.new.when(@duration >= '10:10:10').then(1).else(0)).to_sql
270
+ # puts @laure.select(ArelExtensions::Nodes::Case.new.when(@duration >= '14:10:10').then(1).else(0)).to_sql
266
271
  assert_includes [true,'t',1], t(@laure, ArelExtensions::Nodes::Case.new.when(@duration >= '10:10:10').then(1).else(0))
267
272
  assert_includes [false,'f',0], t(@laure, ArelExtensions::Nodes::Case.new.when(@duration >= '14:10:10').then(1).else(0))
268
273
  end
269
274
 
270
-
271
275
  def test_regexp_not_regexp
272
276
  skip "Sqlite version can't load extension for regexp" if $sqlite && $load_extension_disabled
273
277
  skip "SQL Server does not know about REGEXP without extensions" if @env_db == 'mssql'
@@ -278,7 +282,7 @@ module ArelExtensions
278
282
  end
279
283
 
280
284
  def test_imatches
281
- #puts User.where(@name.imatches('m%')).to_sql
285
+ # puts User.where(@name.imatches('m%')).to_sql
282
286
  assert_equal 1, User.where(@name.imatches('m%')).count
283
287
  assert_equal 4, User.where(@name.imatches_any(['L%', '%e'])).count
284
288
  assert_equal 7, User.where(@name.idoes_not_match('L%')).count
@@ -298,7 +302,7 @@ module ArelExtensions
298
302
 
299
303
  def test_replace_once
300
304
  skip "TODO"
301
- #skip "Sqlite version can't load extension for locate" if $sqlite && $load_extension_disabled
305
+ # skip "Sqlite version can't load extension for locate" if $sqlite && $load_extension_disabled
302
306
  assert_equal "LuCas", t(@lucas, @name.substring(1, @name.locate('c') - 1) + 'C' + @name.substring(@name.locate('c') + 1, @name.length))
303
307
  end
304
308
 
@@ -307,7 +311,7 @@ module ArelExtensions
307
311
  skip "PostgreSql version can't load extension for soundex" if @env_db == 'postgresql'
308
312
  assert_equal "C540", t(@camille, @name.soundex)
309
313
  assert_equal 9, User.where(@name.soundex.eq(@name.soundex)).count
310
- assert_equal 9 , User.where(@name.soundex == @name.soundex).count
314
+ assert_equal 9, User.where(@name.soundex == @name.soundex).count
311
315
  end
312
316
 
313
317
  def test_change_case
@@ -356,6 +360,7 @@ module ArelExtensions
356
360
  assert_equal '2016-05-23', t(@lucas, @created_at.format('%Y-%m-%d'))
357
361
  skip "SQL Server does not accept any format" if @env_db == 'mssql'
358
362
  assert_equal '2014/03/03 12:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S'))
363
+ assert_equal '12:42%', t(@lucas, @updated_at.format('%R%%'))
359
364
  end
360
365
 
361
366
  def test_coalesce
@@ -396,27 +401,27 @@ module ArelExtensions
396
401
  end
397
402
 
398
403
  def test_date_duration
399
- #Year
404
+ # Year
400
405
  assert_equal 2016, t(@lucas, @created_at.year).to_i
401
406
  assert_equal 0, User.where(@created_at.year.eq("2012")).count
402
- #Month
407
+ # Month
403
408
  assert_equal 5, t(@camille, @created_at.month).to_i
404
409
  assert_equal 9, User.where(@created_at.month.eq("05")).count
405
- #Week
410
+ # Week
406
411
  assert_equal(@env_db == 'mssql' ? 22 : 21, t(@arthur, @created_at.week).to_i)
407
412
  assert_equal 9, User.where(@created_at.month.eq("05")).count
408
- #Day
413
+ # Day
409
414
  assert_equal 23, t(@laure, @created_at.day).to_i
410
415
  assert_equal 0, User.where(@created_at.day.eq("05")).count
411
416
 
412
- #skip "manage DATE" if @env_db == 'oracle'
413
- #Hour
417
+ # skip "manage DATE" if @env_db == 'oracle'
418
+ # Hour
414
419
  assert_equal 0, t(@laure, @created_at.hour).to_i
415
420
  assert_equal 12, t(@lucas, @updated_at.hour).to_i
416
- #Minute
421
+ # Minute
417
422
  assert_equal 0, t(@laure, @created_at.minute).to_i
418
423
  assert_equal 42, t(@lucas, @updated_at.minute).to_i
419
- #Second
424
+ # Second
420
425
  assert_equal 0, t(@laure, @created_at.second).to_i
421
426
  assert_equal 0, t(@lucas, @updated_at.second).to_i
422
427
  end
@@ -449,13 +454,13 @@ module ArelExtensions
449
454
 
450
455
  datetime1 = Time.utc(2014, 3, 3, 12, 42, 0)
451
456
  # Pull Request #5 tests
452
- #puts (@created_at + durPos).cast(:date).to_sql
457
+ # puts (@created_at + durPos).cast(:date).to_sql
453
458
  assert_includes [date2,"2026-05-23"], t(@test,(@created_at + durPos).cast(:date))
454
459
  assert_includes [date3,"2006-05-23"], t(@test,(@created_at + durNeg).cast(:date))
455
460
 
456
- #puts (@created_at + @created_at.day).cast(:date).to_sql
461
+ # puts (@created_at + @created_at.day).cast(:date).to_sql
457
462
  assert_includes [date4,"2016-06-15"], t(@test,(@created_at + @created_at.day).cast(:date))
458
- #puts (@created_at - @created_at.day).cast(:date).to_sql
463
+ # puts (@created_at - @created_at.day).cast(:date).to_sql
459
464
  assert_includes [date5,"2016-04-30"], t(@test,(@created_at - @created_at.day).cast(:date))
460
465
 
461
466
  assert_includes [datetime1 + 42.seconds,"2014-03-03 12:42:42 UTC"], t(@lucas,(@updated_at + @updated_at.minute))
@@ -463,18 +468,18 @@ module ArelExtensions
463
468
 
464
469
  # (@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))).to_sql
465
470
  assert_includes [datetime1 + (12*60+42).seconds,"2014-03-03 12:54:42 UTC"],
466
- t(@lucas,(@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))))
471
+ t(@lucas,(@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))))
467
472
 
468
473
  assert_includes [datetime1 + (12*60+42).minutes,"2014-03-04 01:24:00 UTC"],
469
- t(@lucas,(@updated_at + Arel.duration('mn',(@updated_at.hour*60 + @updated_at.minute))))
474
+ t(@lucas,(@updated_at + Arel.duration('mn',(@updated_at.hour*60 + @updated_at.minute))))
470
475
 
471
476
  assert_includes ["2024-03-03"], t(@lucas,(@updated_at + durPos).format('%Y-%m-%d'))
472
- #puts (@updated_at - durPos).to_sql
477
+ # puts (@updated_at - durPos).to_sql
473
478
  assert_includes ["2004-03-03"], t(@lucas,(@updated_at - durPos).format('%Y-%m-%d'))
474
479
 
475
480
 
476
481
  # we test with the ruby object or the string because some adapters don't return an object Date
477
- # end
482
+ # end
478
483
  end
479
484
 
480
485
  # TODO; cast types
@@ -495,27 +500,27 @@ module ArelExtensions
495
500
  assert_equal Time, t(@lucas,@updated_at.cast(:string).cast(:datetime)).class
496
501
  assert_equal Time, t(@lucas,@updated_at.cast(:time)).class
497
502
 
498
- assert_equal "2014-03-03 12:42:00", t(@lucas,@updated_at.cast(:string)) unless @env_db == 'mssql' #locale dependent
503
+ assert_equal "2014-03-03 12:42:00", t(@lucas,@updated_at.cast(:string)) unless @env_db == 'mssql' # locale dependent
499
504
  assert_equal Date.parse("2014-03-03"), t(@lucas,Arel::Nodes.build_quoted('2014-03-03').cast(:date))
500
505
  assert_equal Date.parse("5014-03-03"), t(@lucas,(@age.cast(:string) + '014-03-03').cast(:date))
501
506
  assert_equal Time.parse("2014-03-03 12:42:00 UTC"), t(@lucas,@updated_at.cast(:string).cast(:datetime))
502
507
  assert_equal Date.parse("2014-03-03"), t(@lucas,@updated_at.cast(:date))
503
- assert_equal "12:42:00", t(@lucas,@updated_at.cast(:time).cast(:string)).split('.').first unless @env_db == 'oracle' #DateTime
508
+ assert_equal "12:42:00", t(@lucas,@updated_at.cast(:time).cast(:string)).split('.').first unless @env_db == 'oracle' # DateTime
504
509
  end
505
510
  end
506
511
 
507
512
  def test_is_null
508
- #puts User.where(@age.is_null).select(@name).to_sql
509
- #puts @age.is_null
510
- #puts @age.is_null.inspect
511
- #puts @age.is_null.to_sql
512
- #puts @age=='34'
513
+ # puts User.where(@age.is_null).select(@name).to_sql
514
+ # puts @age.is_null
515
+ # puts @age.is_null.inspect
516
+ # puts @age.is_null.to_sql
517
+ # puts @age=='34'
513
518
  assert_equal "Test", User.select(@name).where(@age.is_null.to_sql).first.name
514
519
  end
515
520
 
516
521
  def test_math_plus
517
522
  d = Date.new(1997, 6, 15)
518
- #Concat String
523
+ # Concat String
519
524
  assert_equal "SophiePhan", t(@sophie, @name + "Phan")
520
525
  assert_equal "Sophie2", t(@sophie, @name + 2)
521
526
  assert_equal "Sophie1997-06-15", t(@sophie, @name + d)
@@ -524,25 +529,24 @@ module ArelExtensions
524
529
  assert_equal "SophieSophieSophie", t(@sophie, @name + @name + @name)
525
530
  assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name.concat(@name)))
526
531
  assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name).concat(@name))
527
- #FIXME: should work as expected in Oracle
532
+ # FIXME: should work as expected in Oracle
528
533
  assert_equal "Sophie2016-05-23", t(@sophie, @name + @created_at) unless @env_db == 'oracle'
529
- #concat Integer
534
+ # concat Integer
530
535
  assert_equal 1, User.where((@age + 10).eq(33)).count
531
536
  assert_equal 1, User.where((@age + "1").eq(6)).count
532
537
  assert_equal 1, User.where((@age + @age).eq(10)).count
533
- #concat Date
534
- #puts((User.arel_table[:created_at] + 1).as("res").to_sql.inspect)
538
+ # concat Date
539
+ # puts((User.arel_table[:created_at] + 1).as("res").to_sql.inspect)
535
540
  assert_equal "2016-05-24", t(@myung, @created_at + 1).to_date.to_s
536
541
  assert_equal "2016-05-25", t(@myung, @created_at + 2.day).to_date.to_s
537
542
  end
538
543
 
539
-
540
544
  def test_math_minus
541
545
  d = Date.new(2016, 5, 20)
542
- #Datediff
546
+ # Datediff
543
547
  assert_equal 9, User.where((@created_at - @created_at).eq(0)).count
544
548
  assert_equal 3, @laure.select((@created_at - d).as("res")).first.res.abs.to_i
545
- #Substraction
549
+ # Substraction
546
550
  assert_equal 0, User.where((@age - 10).eq(50)).count
547
551
  assert_equal 0, User.where((@age - "10").eq(50)).count
548
552
  # assert_equal 0, User.where((@age - 9.5).eq(50.5)).count # should work: TODO
@@ -550,7 +554,7 @@ module ArelExtensions
550
554
  end
551
555
 
552
556
  def test_wday
553
- #d = Date.new(2016, 6, 26)
557
+ # d = Date.new(2016, 6, 26)
554
558
  assert_equal(@env_db == 'oracle' || @env_db == 'mssql' ? 2 : 1, t(@myung, @created_at.wday).to_i) # monday
555
559
  end
556
560
 
@@ -586,41 +590,41 @@ module ArelExtensions
586
590
  assert_equal 0, t(@arthur, @score.when(65.62,1).else(0)-1)
587
591
  assert_equal "11", t(@arthur, @score.when(65.62).then("1").else("0")+"1")
588
592
  assert_equal 66.62, t(@arthur, @score.when(65.62).then(@score).else(@score)+1)
589
- assert_equal "65.621", t(@arthur, @score.when(65.62).then(@score.cast(:string)).else(@score.cast(:string))+1).tr('0','') #tr is here because of precision on cast for some DBMS
593
+ assert_equal "65.621", t(@arthur, @score.when(65.62).then(@score.cast(:string)).else(@score.cast(:string))+1).tr('0','') # tr is here because of precision on cast for some DBMS
590
594
  end
591
595
 
592
596
  def test_format_numbers
593
- #score of Arthur = 65.62
597
+ # score of Arthur = 65.62
594
598
  skip " Works with SQLite if the version used knows printf" if $sqlite
595
599
 
596
- assert_equal "Wrong Format" , t(@arthur, @score.format_number("$ %...234.6F €","fr_FR"))
597
- assert_equal "AZERTY65,62" , t(@arthur, @score.format_number("AZERTY%.2f","fr_FR"))
598
- assert_equal "65,62AZERTY" , t(@arthur, @score.format_number("%.2fAZERTY","fr_FR"))
599
- assert_equal "$ 65.62 €" , t(@arthur, @score.format_number("$ %.2f €","en_US"))
600
- assert_equal "$ 66 €" , t(@arthur, @score.format_number("$ %.0f €","en_US"))
601
- assert_equal "$ 0065,62 €" , t(@arthur, @score.format_number("$ %07.2f €","fr_FR"))
602
- assert_equal "$ 65,62 €" , t(@arthur, @score.format_number("$ %-07.2f €","fr_FR"))
603
- assert_equal "$ 65,62 €" , t(@arthur, @score.format_number("$ %-7.2f €","fr_FR"))
604
- assert_equal "$ 65,62 €" , t(@arthur, @score.format_number("$ % 7.2f €","fr_FR"))
605
- assert_equal "$ 65,6 €" , t(@arthur, @score.format_number("$ % 7.1f €","fr_FR"))
606
- assert_equal "$ +65,62 €" , t(@arthur, @score.format_number("$ % +7.2f €","fr_FR"))
607
- assert_equal "$ +065,62 €" , t(@arthur, @score.format_number("$ %0+7.2f €","fr_FR"))
600
+ assert_equal "Wrong Format", t(@arthur, @score.format_number("$ %...234.6F €","fr_FR"))
601
+ assert_equal "AZERTY65,62", t(@arthur, @score.format_number("AZERTY%.2f","fr_FR"))
602
+ assert_equal "65,62AZERTY", t(@arthur, @score.format_number("%.2fAZERTY","fr_FR"))
603
+ assert_equal "$ 65.62 €", t(@arthur, @score.format_number("$ %.2f €","en_US"))
604
+ assert_equal "$ 66 €", t(@arthur, @score.format_number("$ %.0f €","en_US"))
605
+ assert_equal "$ 0065,62 €", t(@arthur, @score.format_number("$ %07.2f €","fr_FR"))
606
+ assert_equal "$ 65,62 €", t(@arthur, @score.format_number("$ %-07.2f €","fr_FR"))
607
+ assert_equal "$ 65,62 €", t(@arthur, @score.format_number("$ %-7.2f €","fr_FR"))
608
+ assert_equal "$ 65,62 €", t(@arthur, @score.format_number("$ % 7.2f €","fr_FR"))
609
+ assert_equal "$ 65,6 €", t(@arthur, @score.format_number("$ % 7.1f €","fr_FR"))
610
+ assert_equal "$ +65,62 €", t(@arthur, @score.format_number("$ % +7.2f €","fr_FR"))
611
+ assert_equal "$ +065,62 €", t(@arthur, @score.format_number("$ %0+7.2f €","fr_FR"))
608
612
  assert_includes ["$ 6,56e1 €","$ 6,56e+01 €"], t(@arthur, @score.format_number("$ %.2e €","fr_FR"))
609
613
  assert_includes ["$ 6,56E1 €","$ 6,56E+01 €"], t(@arthur, @score.format_number("$ %.2E €","fr_FR"))
610
614
  assert_includes ["$ 6,562E1 €","$ 6,562E+01 €"], t(@arthur, @score.format_number("$ %.3E €","fr_FR"))
611
- 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)
612
- assert_equal "123456765,6" , t(@arthur, (@score+123456700).format_number("%.1f","fr_FR")).gsub("\u00A0","") #because SqlServer does it like no one else
613
- assert_equal "123,456,765.6" , t(@arthur, (@score+123456700).format_number("%.1f","en_US"))
614
- assert_equal " 123,456,765.6" , t(@arthur, (@score+123456700).format_number("%16.1f","en_US"))
615
- assert_equal "$ 0,00 €" , t(@arthur, @score.when(65.62).then(Arel.sql("null")).else(1).format_number("$ %.2f €","fr_FR"))
616
- assert_equal "$ 0,00 €" , t(@arthur, (@score-65.62).format_number("$ %.2f €","fr_FR"))
615
+ 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)
616
+ assert_equal "123456765,6", t(@arthur, (@score+123456700).format_number("%.1f","fr_FR")).gsub("\u00A0","") # because SqlServer does it like no one else
617
+ assert_equal "123,456,765.6", t(@arthur, (@score+123456700).format_number("%.1f","en_US"))
618
+ assert_equal " 123,456,765.6", t(@arthur, (@score+123456700).format_number("%16.1f","en_US"))
619
+ assert_equal "$ 0,00 €", t(@arthur, @score.when(65.62).then(Arel.sql("null")).else(1).format_number("$ %.2f €","fr_FR"))
620
+ assert_equal "$ 0,00 €", t(@arthur, (@score-65.62).format_number("$ %.2f €","fr_FR"))
617
621
  end
618
622
 
619
623
  def test_accent_insensitive
620
624
  skip "SQLite is natively Case Insensitive and Accent Sensitive" if $sqlite
621
625
  skip "Not finished" if @env_db == 'mysql'
622
626
  # actual comments value: "arrêté"
623
- #AI & CI
627
+ # AI & CI
624
628
  if !['postgresql'].include?(@env_db) # Extension unaccent required on PG
625
629
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrêté")).then("1").else("0"))
626
630
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrete")).then("1").else("0"))
@@ -628,7 +632,7 @@ module ArelExtensions
628
632
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arretez")).then("1").else("0"))
629
633
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrete")).then("1").else("0"))
630
634
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrêté")).then("1").else("0"))
631
- #AI & CS
635
+ # AI & CS
632
636
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrêté")).then("1").else("0"))
633
637
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrete")).then("1").else("0"))
634
638
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("àrrétè")).then("1").else("0"))
@@ -638,7 +642,7 @@ module ArelExtensions
638
642
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("Arrêté")).then("1").else("0"))
639
643
  end
640
644
  end
641
- #AS & CI
645
+ # AS & CI
642
646
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrêté")).then("1").else("0"))
643
647
  if !['mysql'].include?(@env_db) # CI => AI in utf8 (AI not possible in latin1)
644
648
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrete")).then("1").else("0"))
@@ -649,7 +653,7 @@ module ArelExtensions
649
653
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrete")).then("1").else("0"))
650
654
  end
651
655
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrêté")).then("1").else("0"))
652
- #AS & CS
656
+ # AS & CS
653
657
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrêté")).then("1").else("0"))
654
658
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrete")).then("1").else("0"))
655
659
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("àrrétè")).then("1").else("0"))
@@ -663,29 +667,29 @@ module ArelExtensions
663
667
  assert_equal 9, User.where(@ut[:name].in(@ut.project(@ut[:name]).order(@ut[:name]))).count
664
668
  if !['mysql'].include?(@env_db) # MySql can't have limit in IN subquery
665
669
  assert_equal 2, User.where(:name => User.select(:name).order(:name).limit(2)).count
666
- #assert_equal 6, User.where(:name => User.select(:name).order(:name).offset(2)).count
670
+ # assert_equal 6, User.where(:name => User.select(:name).order(:name).offset(2)).count
667
671
  end
668
672
  end
669
673
 
670
674
  def test_in_with_nil
671
- assert_equal true , @myung.where(@age.in(1)).blank?
672
- assert_equal false , @myung.where(@age.in(23)).blank?
673
- assert_equal true , @myung.where(@age.in([1])).blank?
674
- assert_equal true , @myung.where(@age.in([1,2])).blank?
675
- assert_equal false , @myung.where(@age.in([1,23])).blank?
676
- assert_equal true , @myung.where(@age.in(nil)).blank?
677
- assert_equal true , @myung.where(@age.in([nil])).blank?
678
- assert_equal true , @myung.where(@age.in([nil,1])).blank?
679
- assert_equal false , @myung.where(@age.in([nil,23])).blank?
680
- assert_equal true , @myung.where(@age.in([nil,1,2])).blank?
681
- assert_equal false , @myung.where(@age.in([nil,1,23])).blank?
682
- assert_equal true , @test.where(@age.in(1)).blank?
683
- assert_equal true , @test.where(@age.in([1])).blank?
684
- assert_equal true , @test.where(@age.in([1,2])).blank?
685
- assert_equal false , @test.where(@age.in(nil)).blank?
686
- assert_equal false , @test.where(@age.in([nil])).blank?
687
- assert_equal false , @test.where(@age.in([nil,1])).blank?
688
- assert_equal false , @test.where(@age.in([nil,1,2])).blank?
675
+ assert_equal true, @myung.where(@age.in(1)).blank?
676
+ assert_equal false, @myung.where(@age.in(23)).blank?
677
+ assert_equal true, @myung.where(@age.in([1])).blank?
678
+ assert_equal true, @myung.where(@age.in([1,2])).blank?
679
+ assert_equal false, @myung.where(@age.in([1,23])).blank?
680
+ assert_equal true, @myung.where(@age.in(nil)).blank?
681
+ assert_equal true, @myung.where(@age.in([nil])).blank?
682
+ assert_equal true, @myung.where(@age.in([nil,1])).blank?
683
+ assert_equal false, @myung.where(@age.in([nil,23])).blank?
684
+ assert_equal true, @myung.where(@age.in([nil,1,2])).blank?
685
+ assert_equal false, @myung.where(@age.in([nil,1,23])).blank?
686
+ assert_equal true, @test.where(@age.in(1)).blank?
687
+ assert_equal true, @test.where(@age.in([1])).blank?
688
+ assert_equal true, @test.where(@age.in([1,2])).blank?
689
+ assert_equal false, @test.where(@age.in(nil)).blank?
690
+ assert_equal false, @test.where(@age.in([nil])).blank?
691
+ assert_equal false, @test.where(@age.in([nil,1])).blank?
692
+ assert_equal false, @test.where(@age.in([nil,1,2])).blank?
689
693
  end
690
694
 
691
695
  def test_scope_with_in_plus_new
@@ -699,40 +703,40 @@ module ArelExtensions
699
703
  end
700
704
 
701
705
  def test_is_not_null
702
- assert_equal false , @myung.where(@age.is_not_null).blank?
703
- assert_equal true , @test.where(@age.is_not_null).blank?
706
+ assert_equal false, @myung.where(@age.is_not_null).blank?
707
+ assert_equal true, @test.where(@age.is_not_null).blank?
704
708
  end
705
709
 
706
710
  def test_not_in_with_nil
707
- assert_equal false , @myung.where(@age.not_in(1)).blank?
708
- assert_equal true , @myung.where(@age.not_in(23)).blank?
709
- assert_equal false , @myung.where(@age.not_in([1])).blank?
710
- assert_equal false , @myung.where(@age.not_in([1,2])).blank?
711
- assert_equal true , @myung.where(@age.not_in([1,23])).blank?
712
- assert_equal false , @myung.where(@age.not_in(nil)).blank?
713
- assert_equal false , @myung.where(@age.not_in([nil])).blank?
714
- assert_equal false , @myung.where(@age.not_in([nil,1])).blank?
715
- assert_equal true , @myung.where(@age.not_in([nil,23])).blank?
716
- assert_equal false , @myung.where(@age.not_in([nil,1,2])).blank?
717
- assert_equal true , @myung.where(@age.not_in([nil,1,23])).blank?
718
-
719
- assert_equal false , @myung.where(@age.not_in(1..2)).blank?
720
-
721
- #if the column is null, the entry will never be selected with not in (like every DBMS does)
722
- #assert_equal false , @test.where(@age.not_in(1)).blank?
723
- #assert_equal false , @test.where(@age.not_in([1])).blank?
724
- #assert_equal false , @test.where(@age.not_in([1,2])).blank?
725
- #assert_equal true , @test.where(@age.not_in(nil)).blank?
726
- #assert_equal true , @test.where(@age.not_in([nil])).blank?
727
- #assert_equal true , @test.where(@age.not_in([nil,1])).blank?
728
- #assert_equal true , @test.where(@age.not_in([nil,1,2])).blank?
711
+ assert_equal false, @myung.where(@age.not_in(1)).blank?
712
+ assert_equal true, @myung.where(@age.not_in(23)).blank?
713
+ assert_equal false, @myung.where(@age.not_in([1])).blank?
714
+ assert_equal false, @myung.where(@age.not_in([1,2])).blank?
715
+ assert_equal true, @myung.where(@age.not_in([1,23])).blank?
716
+ assert_equal false, @myung.where(@age.not_in(nil)).blank?
717
+ assert_equal false, @myung.where(@age.not_in([nil])).blank?
718
+ assert_equal false, @myung.where(@age.not_in([nil,1])).blank?
719
+ assert_equal true, @myung.where(@age.not_in([nil,23])).blank?
720
+ assert_equal false, @myung.where(@age.not_in([nil,1,2])).blank?
721
+ assert_equal true, @myung.where(@age.not_in([nil,1,23])).blank?
722
+
723
+ assert_equal false, @myung.where(@age.not_in(1..2)).blank?
724
+
725
+ # if the column is null, the entry will never be selected with not in (like every DBMS does)
726
+ # assert_equal false , @test.where(@age.not_in(1)).blank?
727
+ # assert_equal false , @test.where(@age.not_in([1])).blank?
728
+ # assert_equal false , @test.where(@age.not_in([1,2])).blank?
729
+ # assert_equal true , @test.where(@age.not_in(nil)).blank?
730
+ # assert_equal true , @test.where(@age.not_in([nil])).blank?
731
+ # assert_equal true , @test.where(@age.not_in([nil,1])).blank?
732
+ # assert_equal true , @test.where(@age.not_in([nil,1,2])).blank?
729
733
  end
730
734
 
731
735
  def test_in_on_grouping
732
736
  skip "We should modify the visitor of IN to make it work" if $sqlite || @env_db == 'mssql'
733
- assert_equal 2 , User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23),Arel.tuple('Arthur',21))).count
734
- assert_equal 1 , User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23))).count
735
- assert_equal 0 , User.where(Arel.tuple(@name,@age).in([])).count
737
+ assert_equal 2, User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23),Arel.tuple('Arthur',21))).count
738
+ assert_equal 1, User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23))).count
739
+ assert_equal 0, User.where(Arel.tuple(@name,@age).in([])).count
736
740
  end
737
741
 
738
742
  def test_alias_shortened
@@ -741,29 +745,29 @@ module ArelExtensions
741
745
  at = User.arel_table.alias('azerty' * 15)
742
746
  assert_equal "\"user_tests\" \"#{new_alias}\"".downcase, User.arel_table.alias('azerty' * 15).to_sql.downcase
743
747
  assert_equal '"user_tests" "u"'.downcase, User.arel_table.alias('u').to_sql.downcase
744
- assert_equal %Q[SELECT "#{new_alias}"."id" FROM "user_tests" "#{new_alias}"].downcase,
745
- User.select(at[:id]).from(at).to_sql.downcase
748
+ assert_equal %Q[SELECT "#{new_alias}"."id" FROM "user_tests" "#{new_alias}"].downcase,
749
+ User.select(at[:id]).from(at).to_sql.downcase
746
750
  end
747
751
  end
748
752
 
749
753
  def test_stat_functions
750
754
  skip "SQLite doesn't work for most on this functions" if $sqlite
751
- #puts t(User.where(nil), @score.average)
752
- #puts t(User.where(nil), @score.variance(unbiased: true))
753
- #puts t(User.where(nil), @score.variance(unbiased: false))
754
- #puts t(User.where(nil), @score.std(unbiased: true))
755
- #puts t(User.where(nil), @score.std(unbiased: false))
755
+ # puts t(User.where(nil), @score.average)
756
+ # puts t(User.where(nil), @score.variance(unbiased: true))
757
+ # puts t(User.where(nil), @score.variance(unbiased: false))
758
+ # puts t(User.where(nil), @score.std(unbiased: true))
759
+ # puts t(User.where(nil), @score.std(unbiased: false))
756
760
 
757
761
  assert ( 15.43222 - t(User.where(nil), @score.average)).abs < 0.01
758
762
  assert (539.79804 - t(User.where(nil), @score.variance)).abs < 0.01
759
763
  assert (479.82048 - t(User.where(nil), @score.variance(unbiased: false))).abs < 0.01
760
764
  assert ( 23.23355 - t(User.where(nil), @score.std)).abs < 0.01
761
765
  assert ( 21.90480 - t(User.where(nil), @score.std(unbiased: false))).abs < 0.01
762
- skip "Not Yet Implemented" #if !['postgresql'].include?(@env_db)
766
+ skip "Not Yet Implemented" # if !['postgresql'].include?(@env_db)
763
767
  assert_equal 2, User.select(@score.std(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
764
- assert_equal 2, User.select(@score.variance(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
765
- assert_equal 2, User.select(@score.sum(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
766
- 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
768
+ assert_equal 2, User.select(@score.variance(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
769
+ assert_equal 2, User.select(@score.sum(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
770
+ 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
767
771
  end
768
772
 
769
773
  def test_levenshtein_distance
@@ -775,7 +779,7 @@ module ArelExtensions
775
779
 
776
780
  def test_json
777
781
  skip "Can't be tested on travis"
778
- #creation
782
+ # creation
779
783
  assert_equal 'Arthur', t(@arthur,Arel.json(@name))
780
784
  assert_equal ["Arthur","Arthur"], parse_json(t(@arthur,Arel.json(@name,@name)))
781
785
  assert_equal ({"Arthur" => "Arthur", "Arthur2" => "ArthurArthur"}), parse_json(t(@arthur,Arel.json({@name => @name,@name+"2" => @name+@name})))
@@ -784,29 +788,29 @@ module ArelExtensions
784
788
 
785
789
  # aggregate
786
790
  assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure"}),
787
- parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name}).group(false)))
791
+ parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name}).group(false)))
788
792
  assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure", "Laure"=>25, "Lucas"=>5, "Myung"=>23, "Sophie"=>15}),
789
- parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name,@name => @age}).group(false)))
793
+ parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name,@name => @age}).group(false)))
790
794
  assert_equal ([{"5" => "Lucas"},{ "15" => "Sophie"},{ "23" => "Myung"},{ "25" => "Laure"}]),
791
- parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score),Arel.json({@age => @name}).group(true,[@age])))
795
+ parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score),Arel.json({@age => @name}).group(true,[@age])))
792
796
 
793
- #puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_sql
794
- #puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_a
797
+ # puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_sql
798
+ # puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_a
795
799
 
796
800
  skip "Not Yet Implemented" if $sqlite || ['oracle','mssql'].include?(@env_db)
797
- #get
801
+ # get
798
802
  h1 = Arel.json({@name => @name+@name,@name+"2" => 1})
799
803
  assert_equal "ArthurArthur", parse_json(t(@arthur,h1.get(@name)))
800
804
  h2 = Arel.json([{age: @age},{name: @name,score: @score}])
801
805
  assert_equal ({"age" => 21}), parse_json(t(@arthur,h2.get(0)))
802
806
  assert_equal 21, parse_json(t(@arthur,h2.get(0).get('age')))
803
807
  assert_nil t(@arthur,h2.get('age'))
804
- #set
808
+ # set
805
809
  assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1}), parse_json(t(@arthur,h1.set(@name, ['toto','tata'])))
806
810
  assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.set(@name+"3",2)))
807
811
  assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => nil}), parse_json(t(@arthur,h1.set(@name+"3",nil)))
808
812
  assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => {"a" => 2}}), parse_json(t(@arthur,h1.set(@name+"3",{a: 2})))
809
- #merge
813
+ # merge
810
814
  assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata']},{@name+"3" => 2})))
811
815
  assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata'], @name+"3" => 2})))
812
816
  assert_equal ({"Arthur" => "ArthurArthur","Arthur2" => 1}), parse_json(t(@arthur,h1.merge({})))
@@ -814,7 +818,7 @@ module ArelExtensions
814
818
 
815
819
  def test_as_on_everything
816
820
  name = @arthur.select(@name.as('NaMe')).first.attributes
817
- assert_equal 'Arthur', name["NaMe"] || name["name"] #because of Oracle
821
+ assert_equal 'Arthur', name["NaMe"] || name["name"] # because of Oracle
818
822
  assert_equal 'Arthur', @arthur.select(@name.as('Na Me')).first.attributes["Na Me"]
819
823
  assert_equal 'ArthurArthur', @arthur.select((@name+@name).as('Na-Me')).first.attributes["Na-Me"]
820
824
  end
@@ -822,8 +826,6 @@ module ArelExtensions
822
826
  def test_exists_in_subquery
823
827
  assert User.where(User.where(nil).arel.exists).first
824
828
  end
825
-
826
-
827
829
  end
828
830
  end
829
831
  end