arel_extensions 1.2.17 → 1.2.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +102 -0
  3. data/Gemfile +10 -10
  4. data/Rakefile +4 -4
  5. data/arel_extensions.gemspec +1 -1
  6. data/gemfiles/rails3.gemfile +9 -9
  7. data/gemfiles/rails4.gemfile +13 -13
  8. data/gemfiles/rails5_0.gemfile +13 -13
  9. data/gemfiles/rails5_1_4.gemfile +13 -13
  10. data/gemfiles/rails5_2.gemfile +13 -13
  11. data/gemfiles/rails6.gemfile +13 -13
  12. data/gemfiles/rails6_1.gemfile +30 -0
  13. data/gemspecs/arel_extensions-v1.gemspec +28 -0
  14. data/{gemspec_v2 → gemspecs}/arel_extensions-v2.gemspec +0 -0
  15. data/generate_gems.sh +4 -3
  16. data/lib/arel_extensions.rb +23 -5
  17. data/lib/arel_extensions/attributes.rb +0 -0
  18. data/lib/arel_extensions/boolean_functions.rb +3 -7
  19. data/lib/arel_extensions/common_sql_functions.rb +0 -2
  20. data/lib/arel_extensions/comparators.rb +11 -14
  21. data/lib/arel_extensions/date_duration.rb +4 -5
  22. data/lib/arel_extensions/insert_manager.rb +16 -17
  23. data/lib/arel_extensions/math.rb +8 -9
  24. data/lib/arel_extensions/math_functions.rb +22 -20
  25. data/lib/arel_extensions/nodes/abs.rb +0 -1
  26. data/lib/arel_extensions/nodes/aggregate_function.rb +0 -1
  27. data/lib/arel_extensions/nodes/blank.rb +0 -1
  28. data/lib/arel_extensions/nodes/case.rb +3 -4
  29. data/lib/arel_extensions/nodes/cast.rb +0 -1
  30. data/lib/arel_extensions/nodes/ceil.rb +1 -1
  31. data/lib/arel_extensions/nodes/change_case.rb +0 -0
  32. data/lib/arel_extensions/nodes/coalesce.rb +0 -1
  33. data/lib/arel_extensions/nodes/collate.rb +0 -1
  34. data/lib/arel_extensions/nodes/concat.rb +2 -4
  35. data/lib/arel_extensions/nodes/date_diff.rb +4 -5
  36. data/lib/arel_extensions/nodes/duration.rb +0 -1
  37. data/lib/arel_extensions/nodes/find_in_set.rb +0 -1
  38. data/lib/arel_extensions/nodes/floor.rb +1 -1
  39. data/lib/arel_extensions/nodes/format.rb +1 -0
  40. data/lib/arel_extensions/nodes/formatted_number.rb +0 -1
  41. data/lib/arel_extensions/nodes/function.rb +8 -5
  42. data/lib/arel_extensions/nodes/is_null.rb +0 -0
  43. data/lib/arel_extensions/nodes/json.rb +0 -6
  44. data/lib/arel_extensions/nodes/length.rb +5 -0
  45. data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
  46. data/lib/arel_extensions/nodes/locate.rb +0 -1
  47. data/lib/arel_extensions/nodes/log10.rb +1 -2
  48. data/lib/arel_extensions/nodes/matches.rb +0 -2
  49. data/lib/arel_extensions/nodes/md5.rb +0 -1
  50. data/lib/arel_extensions/nodes/power.rb +0 -1
  51. data/lib/arel_extensions/nodes/rand.rb +0 -1
  52. data/lib/arel_extensions/nodes/repeat.rb +0 -2
  53. data/lib/arel_extensions/nodes/replace.rb +0 -2
  54. data/lib/arel_extensions/nodes/round.rb +0 -1
  55. data/lib/arel_extensions/nodes/soundex.rb +0 -1
  56. data/lib/arel_extensions/nodes/std.rb +4 -5
  57. data/lib/arel_extensions/nodes/substring.rb +0 -1
  58. data/lib/arel_extensions/nodes/sum.rb +0 -0
  59. data/lib/arel_extensions/nodes/then.rb +0 -0
  60. data/lib/arel_extensions/nodes/trim.rb +0 -2
  61. data/lib/arel_extensions/nodes/union.rb +0 -2
  62. data/lib/arel_extensions/nodes/union_all.rb +0 -2
  63. data/lib/arel_extensions/nodes/wday.rb +0 -4
  64. data/lib/arel_extensions/null_functions.rb +3 -5
  65. data/lib/arel_extensions/predications.rb +2 -3
  66. data/lib/arel_extensions/railtie.rb +5 -5
  67. data/lib/arel_extensions/set_functions.rb +0 -2
  68. data/lib/arel_extensions/string_functions.rb +30 -23
  69. data/lib/arel_extensions/tasks.rb +1 -1
  70. data/lib/arel_extensions/version.rb +1 -1
  71. data/lib/arel_extensions/visitors.rb +68 -60
  72. data/lib/arel_extensions/visitors/convert_format.rb +37 -0
  73. data/lib/arel_extensions/visitors/ibm_db.rb +4 -11
  74. data/lib/arel_extensions/visitors/mssql.rb +50 -45
  75. data/lib/arel_extensions/visitors/mysql.rb +63 -65
  76. data/lib/arel_extensions/visitors/oracle.rb +50 -57
  77. data/lib/arel_extensions/visitors/oracle12.rb +1 -14
  78. data/lib/arel_extensions/visitors/postgresql.rb +39 -34
  79. data/lib/arel_extensions/visitors/sqlite.rb +23 -18
  80. data/lib/arel_extensions/visitors/to_sql.rb +58 -48
  81. data/test/arelx_test_helper.rb +0 -2
  82. data/test/database.yml +2 -0
  83. data/test/real_db_test.rb +26 -41
  84. data/test/support/fake_record.rb +1 -1
  85. data/test/test_comparators.rb +0 -4
  86. data/test/visitors/test_bulk_insert_oracle.rb +0 -1
  87. data/test/visitors/test_bulk_insert_sqlite.rb +0 -2
  88. data/test/visitors/test_oracle.rb +1 -2
  89. data/test/visitors/test_to_sql.rb +16 -25
  90. data/test/with_ar/all_agnostic_test.rb +140 -139
  91. data/test/with_ar/insert_agnostic_test.rb +0 -2
  92. data/test/with_ar/test_bulk_sqlite.rb +0 -4
  93. data/test/with_ar/test_math_sqlite.rb +4 -8
  94. data/test/with_ar/test_string_mysql.rb +1 -5
  95. data/test/with_ar/test_string_sqlite.rb +1 -5
  96. data/version_v1.rb +1 -1
  97. data/version_v2.rb +1 -1
  98. 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
@@ -24,7 +24,7 @@ def setup_db
24
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
@@ -397,27 +401,27 @@ module ArelExtensions
397
401
  end
398
402
 
399
403
  def test_date_duration
400
- #Year
404
+ # Year
401
405
  assert_equal 2016, t(@lucas, @created_at.year).to_i
402
406
  assert_equal 0, User.where(@created_at.year.eq("2012")).count
403
- #Month
407
+ # Month
404
408
  assert_equal 5, t(@camille, @created_at.month).to_i
405
409
  assert_equal 9, User.where(@created_at.month.eq("05")).count
406
- #Week
410
+ # Week
407
411
  assert_equal(@env_db == 'mssql' ? 22 : 21, t(@arthur, @created_at.week).to_i)
408
412
  assert_equal 9, User.where(@created_at.month.eq("05")).count
409
- #Day
413
+ # Day
410
414
  assert_equal 23, t(@laure, @created_at.day).to_i
411
415
  assert_equal 0, User.where(@created_at.day.eq("05")).count
412
416
 
413
- #skip "manage DATE" if @env_db == 'oracle'
414
- #Hour
417
+ # skip "manage DATE" if @env_db == 'oracle'
418
+ # Hour
415
419
  assert_equal 0, t(@laure, @created_at.hour).to_i
416
420
  assert_equal 12, t(@lucas, @updated_at.hour).to_i
417
- #Minute
421
+ # Minute
418
422
  assert_equal 0, t(@laure, @created_at.minute).to_i
419
423
  assert_equal 42, t(@lucas, @updated_at.minute).to_i
420
- #Second
424
+ # Second
421
425
  assert_equal 0, t(@laure, @created_at.second).to_i
422
426
  assert_equal 0, t(@lucas, @updated_at.second).to_i
423
427
  end
@@ -450,13 +454,13 @@ module ArelExtensions
450
454
 
451
455
  datetime1 = Time.utc(2014, 3, 3, 12, 42, 0)
452
456
  # Pull Request #5 tests
453
- #puts (@created_at + durPos).cast(:date).to_sql
457
+ # puts (@created_at + durPos).cast(:date).to_sql
454
458
  assert_includes [date2,"2026-05-23"], t(@test,(@created_at + durPos).cast(:date))
455
459
  assert_includes [date3,"2006-05-23"], t(@test,(@created_at + durNeg).cast(:date))
456
460
 
457
- #puts (@created_at + @created_at.day).cast(:date).to_sql
461
+ # puts (@created_at + @created_at.day).cast(:date).to_sql
458
462
  assert_includes [date4,"2016-06-15"], t(@test,(@created_at + @created_at.day).cast(:date))
459
- #puts (@created_at - @created_at.day).cast(:date).to_sql
463
+ # puts (@created_at - @created_at.day).cast(:date).to_sql
460
464
  assert_includes [date5,"2016-04-30"], t(@test,(@created_at - @created_at.day).cast(:date))
461
465
 
462
466
  assert_includes [datetime1 + 42.seconds,"2014-03-03 12:42:42 UTC"], t(@lucas,(@updated_at + @updated_at.minute))
@@ -464,18 +468,18 @@ module ArelExtensions
464
468
 
465
469
  # (@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))).to_sql
466
470
  assert_includes [datetime1 + (12*60+42).seconds,"2014-03-03 12:54:42 UTC"],
467
- 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))))
468
472
 
469
473
  assert_includes [datetime1 + (12*60+42).minutes,"2014-03-04 01:24:00 UTC"],
470
- 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))))
471
475
 
472
476
  assert_includes ["2024-03-03"], t(@lucas,(@updated_at + durPos).format('%Y-%m-%d'))
473
- #puts (@updated_at - durPos).to_sql
477
+ # puts (@updated_at - durPos).to_sql
474
478
  assert_includes ["2004-03-03"], t(@lucas,(@updated_at - durPos).format('%Y-%m-%d'))
475
479
 
476
480
 
477
481
  # we test with the ruby object or the string because some adapters don't return an object Date
478
- # end
482
+ # end
479
483
  end
480
484
 
481
485
  # TODO; cast types
@@ -496,27 +500,27 @@ module ArelExtensions
496
500
  assert_equal Time, t(@lucas,@updated_at.cast(:string).cast(:datetime)).class
497
501
  assert_equal Time, t(@lucas,@updated_at.cast(:time)).class
498
502
 
499
- 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
500
504
  assert_equal Date.parse("2014-03-03"), t(@lucas,Arel::Nodes.build_quoted('2014-03-03').cast(:date))
501
505
  assert_equal Date.parse("5014-03-03"), t(@lucas,(@age.cast(:string) + '014-03-03').cast(:date))
502
506
  assert_equal Time.parse("2014-03-03 12:42:00 UTC"), t(@lucas,@updated_at.cast(:string).cast(:datetime))
503
507
  assert_equal Date.parse("2014-03-03"), t(@lucas,@updated_at.cast(:date))
504
- 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
505
509
  end
506
510
  end
507
511
 
508
512
  def test_is_null
509
- #puts User.where(@age.is_null).select(@name).to_sql
510
- #puts @age.is_null
511
- #puts @age.is_null.inspect
512
- #puts @age.is_null.to_sql
513
- #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'
514
518
  assert_equal "Test", User.select(@name).where(@age.is_null.to_sql).first.name
515
519
  end
516
520
 
517
521
  def test_math_plus
518
522
  d = Date.new(1997, 6, 15)
519
- #Concat String
523
+ # Concat String
520
524
  assert_equal "SophiePhan", t(@sophie, @name + "Phan")
521
525
  assert_equal "Sophie2", t(@sophie, @name + 2)
522
526
  assert_equal "Sophie1997-06-15", t(@sophie, @name + d)
@@ -525,25 +529,24 @@ module ArelExtensions
525
529
  assert_equal "SophieSophieSophie", t(@sophie, @name + @name + @name)
526
530
  assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name.concat(@name)))
527
531
  assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name).concat(@name))
528
- #FIXME: should work as expected in Oracle
532
+ # FIXME: should work as expected in Oracle
529
533
  assert_equal "Sophie2016-05-23", t(@sophie, @name + @created_at) unless @env_db == 'oracle'
530
- #concat Integer
534
+ # concat Integer
531
535
  assert_equal 1, User.where((@age + 10).eq(33)).count
532
536
  assert_equal 1, User.where((@age + "1").eq(6)).count
533
537
  assert_equal 1, User.where((@age + @age).eq(10)).count
534
- #concat Date
535
- #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)
536
540
  assert_equal "2016-05-24", t(@myung, @created_at + 1).to_date.to_s
537
541
  assert_equal "2016-05-25", t(@myung, @created_at + 2.day).to_date.to_s
538
542
  end
539
543
 
540
-
541
544
  def test_math_minus
542
545
  d = Date.new(2016, 5, 20)
543
- #Datediff
546
+ # Datediff
544
547
  assert_equal 9, User.where((@created_at - @created_at).eq(0)).count
545
548
  assert_equal 3, @laure.select((@created_at - d).as("res")).first.res.abs.to_i
546
- #Substraction
549
+ # Substraction
547
550
  assert_equal 0, User.where((@age - 10).eq(50)).count
548
551
  assert_equal 0, User.where((@age - "10").eq(50)).count
549
552
  # assert_equal 0, User.where((@age - 9.5).eq(50.5)).count # should work: TODO
@@ -551,7 +554,7 @@ module ArelExtensions
551
554
  end
552
555
 
553
556
  def test_wday
554
- #d = Date.new(2016, 6, 26)
557
+ # d = Date.new(2016, 6, 26)
555
558
  assert_equal(@env_db == 'oracle' || @env_db == 'mssql' ? 2 : 1, t(@myung, @created_at.wday).to_i) # monday
556
559
  end
557
560
 
@@ -587,41 +590,41 @@ module ArelExtensions
587
590
  assert_equal 0, t(@arthur, @score.when(65.62,1).else(0)-1)
588
591
  assert_equal "11", t(@arthur, @score.when(65.62).then("1").else("0")+"1")
589
592
  assert_equal 66.62, t(@arthur, @score.when(65.62).then(@score).else(@score)+1)
590
- 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
591
594
  end
592
595
 
593
596
  def test_format_numbers
594
- #score of Arthur = 65.62
597
+ # score of Arthur = 65.62
595
598
  skip " Works with SQLite if the version used knows printf" if $sqlite
596
599
 
597
- assert_equal "Wrong Format" , t(@arthur, @score.format_number("$ %...234.6F €","fr_FR"))
598
- assert_equal "AZERTY65,62" , t(@arthur, @score.format_number("AZERTY%.2f","fr_FR"))
599
- assert_equal "65,62AZERTY" , t(@arthur, @score.format_number("%.2fAZERTY","fr_FR"))
600
- assert_equal "$ 65.62 €" , t(@arthur, @score.format_number("$ %.2f €","en_US"))
601
- assert_equal "$ 66 €" , t(@arthur, @score.format_number("$ %.0f €","en_US"))
602
- assert_equal "$ 0065,62 €" , t(@arthur, @score.format_number("$ %07.2f €","fr_FR"))
603
- assert_equal "$ 65,62 €" , t(@arthur, @score.format_number("$ %-07.2f €","fr_FR"))
604
- assert_equal "$ 65,62 €" , t(@arthur, @score.format_number("$ %-7.2f €","fr_FR"))
605
- assert_equal "$ 65,62 €" , t(@arthur, @score.format_number("$ % 7.2f €","fr_FR"))
606
- assert_equal "$ 65,6 €" , t(@arthur, @score.format_number("$ % 7.1f €","fr_FR"))
607
- assert_equal "$ +65,62 €" , t(@arthur, @score.format_number("$ % +7.2f €","fr_FR"))
608
- 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"))
609
612
  assert_includes ["$ 6,56e1 €","$ 6,56e+01 €"], t(@arthur, @score.format_number("$ %.2e €","fr_FR"))
610
613
  assert_includes ["$ 6,56E1 €","$ 6,56E+01 €"], t(@arthur, @score.format_number("$ %.2E €","fr_FR"))
611
614
  assert_includes ["$ 6,562E1 €","$ 6,562E+01 €"], t(@arthur, @score.format_number("$ %.3E €","fr_FR"))
612
- 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)
613
- assert_equal "123456765,6" , t(@arthur, (@score+123456700).format_number("%.1f","fr_FR")).gsub("\u00A0","") #because SqlServer does it like no one else
614
- assert_equal "123,456,765.6" , t(@arthur, (@score+123456700).format_number("%.1f","en_US"))
615
- assert_equal " 123,456,765.6" , t(@arthur, (@score+123456700).format_number("%16.1f","en_US"))
616
- assert_equal "$ 0,00 €" , t(@arthur, @score.when(65.62).then(Arel.sql("null")).else(1).format_number("$ %.2f €","fr_FR"))
617
- 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"))
618
621
  end
619
622
 
620
623
  def test_accent_insensitive
621
624
  skip "SQLite is natively Case Insensitive and Accent Sensitive" if $sqlite
622
625
  skip "Not finished" if @env_db == 'mysql'
623
626
  # actual comments value: "arrêté"
624
- #AI & CI
627
+ # AI & CI
625
628
  if !['postgresql'].include?(@env_db) # Extension unaccent required on PG
626
629
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrêté")).then("1").else("0"))
627
630
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrete")).then("1").else("0"))
@@ -629,7 +632,7 @@ module ArelExtensions
629
632
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arretez")).then("1").else("0"))
630
633
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrete")).then("1").else("0"))
631
634
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrêté")).then("1").else("0"))
632
- #AI & CS
635
+ # AI & CS
633
636
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrêté")).then("1").else("0"))
634
637
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrete")).then("1").else("0"))
635
638
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("àrrétè")).then("1").else("0"))
@@ -639,7 +642,7 @@ module ArelExtensions
639
642
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("Arrêté")).then("1").else("0"))
640
643
  end
641
644
  end
642
- #AS & CI
645
+ # AS & CI
643
646
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrêté")).then("1").else("0"))
644
647
  if !['mysql'].include?(@env_db) # CI => AI in utf8 (AI not possible in latin1)
645
648
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrete")).then("1").else("0"))
@@ -650,7 +653,7 @@ module ArelExtensions
650
653
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrete")).then("1").else("0"))
651
654
  end
652
655
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrêté")).then("1").else("0"))
653
- #AS & CS
656
+ # AS & CS
654
657
  assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrêté")).then("1").else("0"))
655
658
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrete")).then("1").else("0"))
656
659
  assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("àrrétè")).then("1").else("0"))
@@ -664,29 +667,29 @@ module ArelExtensions
664
667
  assert_equal 9, User.where(@ut[:name].in(@ut.project(@ut[:name]).order(@ut[:name]))).count
665
668
  if !['mysql'].include?(@env_db) # MySql can't have limit in IN subquery
666
669
  assert_equal 2, User.where(:name => User.select(:name).order(:name).limit(2)).count
667
- #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
668
671
  end
669
672
  end
670
673
 
671
674
  def test_in_with_nil
672
- assert_equal true , @myung.where(@age.in(1)).blank?
673
- assert_equal false , @myung.where(@age.in(23)).blank?
674
- assert_equal true , @myung.where(@age.in([1])).blank?
675
- assert_equal true , @myung.where(@age.in([1,2])).blank?
676
- assert_equal false , @myung.where(@age.in([1,23])).blank?
677
- assert_equal true , @myung.where(@age.in(nil)).blank?
678
- assert_equal true , @myung.where(@age.in([nil])).blank?
679
- assert_equal true , @myung.where(@age.in([nil,1])).blank?
680
- assert_equal false , @myung.where(@age.in([nil,23])).blank?
681
- assert_equal true , @myung.where(@age.in([nil,1,2])).blank?
682
- assert_equal false , @myung.where(@age.in([nil,1,23])).blank?
683
- assert_equal true , @test.where(@age.in(1)).blank?
684
- assert_equal true , @test.where(@age.in([1])).blank?
685
- assert_equal true , @test.where(@age.in([1,2])).blank?
686
- assert_equal false , @test.where(@age.in(nil)).blank?
687
- assert_equal false , @test.where(@age.in([nil])).blank?
688
- assert_equal false , @test.where(@age.in([nil,1])).blank?
689
- 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?
690
693
  end
691
694
 
692
695
  def test_scope_with_in_plus_new
@@ -700,40 +703,40 @@ module ArelExtensions
700
703
  end
701
704
 
702
705
  def test_is_not_null
703
- assert_equal false , @myung.where(@age.is_not_null).blank?
704
- 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?
705
708
  end
706
709
 
707
710
  def test_not_in_with_nil
708
- assert_equal false , @myung.where(@age.not_in(1)).blank?
709
- assert_equal true , @myung.where(@age.not_in(23)).blank?
710
- assert_equal false , @myung.where(@age.not_in([1])).blank?
711
- assert_equal false , @myung.where(@age.not_in([1,2])).blank?
712
- assert_equal true , @myung.where(@age.not_in([1,23])).blank?
713
- assert_equal false , @myung.where(@age.not_in(nil)).blank?
714
- assert_equal false , @myung.where(@age.not_in([nil])).blank?
715
- assert_equal false , @myung.where(@age.not_in([nil,1])).blank?
716
- assert_equal true , @myung.where(@age.not_in([nil,23])).blank?
717
- assert_equal false , @myung.where(@age.not_in([nil,1,2])).blank?
718
- assert_equal true , @myung.where(@age.not_in([nil,1,23])).blank?
719
-
720
- assert_equal false , @myung.where(@age.not_in(1..2)).blank?
721
-
722
- #if the column is null, the entry will never be selected with not in (like every DBMS does)
723
- #assert_equal false , @test.where(@age.not_in(1)).blank?
724
- #assert_equal false , @test.where(@age.not_in([1])).blank?
725
- #assert_equal false , @test.where(@age.not_in([1,2])).blank?
726
- #assert_equal true , @test.where(@age.not_in(nil)).blank?
727
- #assert_equal true , @test.where(@age.not_in([nil])).blank?
728
- #assert_equal true , @test.where(@age.not_in([nil,1])).blank?
729
- #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?
730
733
  end
731
734
 
732
735
  def test_in_on_grouping
733
736
  skip "We should modify the visitor of IN to make it work" if $sqlite || @env_db == 'mssql'
734
- assert_equal 2 , User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23),Arel.tuple('Arthur',21))).count
735
- assert_equal 1 , User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23))).count
736
- 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
737
740
  end
738
741
 
739
742
  def test_alias_shortened
@@ -742,29 +745,29 @@ module ArelExtensions
742
745
  at = User.arel_table.alias('azerty' * 15)
743
746
  assert_equal "\"user_tests\" \"#{new_alias}\"".downcase, User.arel_table.alias('azerty' * 15).to_sql.downcase
744
747
  assert_equal '"user_tests" "u"'.downcase, User.arel_table.alias('u').to_sql.downcase
745
- assert_equal %Q[SELECT "#{new_alias}"."id" FROM "user_tests" "#{new_alias}"].downcase,
746
- 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
747
750
  end
748
751
  end
749
752
 
750
753
  def test_stat_functions
751
754
  skip "SQLite doesn't work for most on this functions" if $sqlite
752
- #puts t(User.where(nil), @score.average)
753
- #puts t(User.where(nil), @score.variance(unbiased: true))
754
- #puts t(User.where(nil), @score.variance(unbiased: false))
755
- #puts t(User.where(nil), @score.std(unbiased: true))
756
- #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))
757
760
 
758
761
  assert ( 15.43222 - t(User.where(nil), @score.average)).abs < 0.01
759
762
  assert (539.79804 - t(User.where(nil), @score.variance)).abs < 0.01
760
763
  assert (479.82048 - t(User.where(nil), @score.variance(unbiased: false))).abs < 0.01
761
764
  assert ( 23.23355 - t(User.where(nil), @score.std)).abs < 0.01
762
765
  assert ( 21.90480 - t(User.where(nil), @score.std(unbiased: false))).abs < 0.01
763
- skip "Not Yet Implemented" #if !['postgresql'].include?(@env_db)
766
+ skip "Not Yet Implemented" # if !['postgresql'].include?(@env_db)
764
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
765
- assert_equal 2, User.select(@score.variance(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
766
- assert_equal 2, User.select(@score.sum(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
767
- 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
768
771
  end
769
772
 
770
773
  def test_levenshtein_distance
@@ -776,7 +779,7 @@ module ArelExtensions
776
779
 
777
780
  def test_json
778
781
  skip "Can't be tested on travis"
779
- #creation
782
+ # creation
780
783
  assert_equal 'Arthur', t(@arthur,Arel.json(@name))
781
784
  assert_equal ["Arthur","Arthur"], parse_json(t(@arthur,Arel.json(@name,@name)))
782
785
  assert_equal ({"Arthur" => "Arthur", "Arthur2" => "ArthurArthur"}), parse_json(t(@arthur,Arel.json({@name => @name,@name+"2" => @name+@name})))
@@ -785,29 +788,29 @@ module ArelExtensions
785
788
 
786
789
  # aggregate
787
790
  assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure"}),
788
- 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)))
789
792
  assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure", "Laure"=>25, "Lucas"=>5, "Myung"=>23, "Sophie"=>15}),
790
- 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)))
791
794
  assert_equal ([{"5" => "Lucas"},{ "15" => "Sophie"},{ "23" => "Myung"},{ "25" => "Laure"}]),
792
- 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])))
793
796
 
794
- #puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_sql
795
- #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
796
799
 
797
800
  skip "Not Yet Implemented" if $sqlite || ['oracle','mssql'].include?(@env_db)
798
- #get
801
+ # get
799
802
  h1 = Arel.json({@name => @name+@name,@name+"2" => 1})
800
803
  assert_equal "ArthurArthur", parse_json(t(@arthur,h1.get(@name)))
801
804
  h2 = Arel.json([{age: @age},{name: @name,score: @score}])
802
805
  assert_equal ({"age" => 21}), parse_json(t(@arthur,h2.get(0)))
803
806
  assert_equal 21, parse_json(t(@arthur,h2.get(0).get('age')))
804
807
  assert_nil t(@arthur,h2.get('age'))
805
- #set
808
+ # set
806
809
  assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1}), parse_json(t(@arthur,h1.set(@name, ['toto','tata'])))
807
810
  assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.set(@name+"3",2)))
808
811
  assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => nil}), parse_json(t(@arthur,h1.set(@name+"3",nil)))
809
812
  assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => {"a" => 2}}), parse_json(t(@arthur,h1.set(@name+"3",{a: 2})))
810
- #merge
813
+ # merge
811
814
  assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata']},{@name+"3" => 2})))
812
815
  assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata'], @name+"3" => 2})))
813
816
  assert_equal ({"Arthur" => "ArthurArthur","Arthur2" => 1}), parse_json(t(@arthur,h1.merge({})))
@@ -815,7 +818,7 @@ module ArelExtensions
815
818
 
816
819
  def test_as_on_everything
817
820
  name = @arthur.select(@name.as('NaMe')).first.attributes
818
- assert_equal 'Arthur', name["NaMe"] || name["name"] #because of Oracle
821
+ assert_equal 'Arthur', name["NaMe"] || name["name"] # because of Oracle
819
822
  assert_equal 'Arthur', @arthur.select(@name.as('Na Me')).first.attributes["Na Me"]
820
823
  assert_equal 'ArthurArthur', @arthur.select((@name+@name).as('Na-Me')).first.attributes["Na-Me"]
821
824
  end
@@ -823,8 +826,6 @@ module ArelExtensions
823
826
  def test_exists_in_subquery
824
827
  assert User.where(User.where(nil).arel.exists).first
825
828
  end
826
-
827
-
828
829
  end
829
830
  end
830
831
  end