arel_extensions 2.0.13 → 2.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +10 -10
- data/Rakefile +4 -4
- data/gemfiles/rails3.gemfile +9 -9
- data/gemfiles/rails4.gemfile +13 -13
- data/gemfiles/rails5_0.gemfile +13 -13
- data/gemfiles/rails5_1_4.gemfile +13 -13
- data/gemfiles/rails5_2.gemfile +13 -13
- data/gemfiles/rails6.gemfile +13 -13
- data/lib/arel_extensions.rb +2 -2
- data/lib/arel_extensions/attributes.rb +0 -0
- data/lib/arel_extensions/boolean_functions.rb +3 -7
- data/lib/arel_extensions/common_sql_functions.rb +0 -2
- data/lib/arel_extensions/comparators.rb +11 -14
- data/lib/arel_extensions/date_duration.rb +4 -5
- data/lib/arel_extensions/insert_manager.rb +16 -17
- data/lib/arel_extensions/math.rb +8 -9
- data/lib/arel_extensions/math_functions.rb +15 -17
- data/lib/arel_extensions/nodes/abs.rb +0 -1
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -1
- data/lib/arel_extensions/nodes/blank.rb +0 -1
- data/lib/arel_extensions/nodes/case.rb +3 -4
- data/lib/arel_extensions/nodes/cast.rb +0 -1
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/change_case.rb +0 -0
- data/lib/arel_extensions/nodes/coalesce.rb +0 -1
- data/lib/arel_extensions/nodes/collate.rb +0 -1
- data/lib/arel_extensions/nodes/concat.rb +1 -3
- data/lib/arel_extensions/nodes/date_diff.rb +4 -5
- data/lib/arel_extensions/nodes/duration.rb +0 -1
- data/lib/arel_extensions/nodes/find_in_set.rb +0 -1
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +1 -0
- data/lib/arel_extensions/nodes/formatted_number.rb +0 -1
- data/lib/arel_extensions/nodes/function.rb +2 -3
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +0 -6
- data/lib/arel_extensions/nodes/length.rb +0 -1
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +0 -0
- data/lib/arel_extensions/nodes/locate.rb +0 -1
- data/lib/arel_extensions/nodes/log10.rb +1 -2
- data/lib/arel_extensions/nodes/matches.rb +0 -2
- data/lib/arel_extensions/nodes/md5.rb +0 -1
- data/lib/arel_extensions/nodes/power.rb +0 -1
- data/lib/arel_extensions/nodes/rand.rb +0 -1
- data/lib/arel_extensions/nodes/repeat.rb +0 -2
- data/lib/arel_extensions/nodes/replace.rb +0 -2
- data/lib/arel_extensions/nodes/round.rb +0 -1
- data/lib/arel_extensions/nodes/soundex.rb +0 -1
- data/lib/arel_extensions/nodes/std.rb +0 -1
- data/lib/arel_extensions/nodes/substring.rb +0 -1
- data/lib/arel_extensions/nodes/sum.rb +0 -0
- data/lib/arel_extensions/nodes/then.rb +0 -0
- data/lib/arel_extensions/nodes/trim.rb +0 -2
- data/lib/arel_extensions/nodes/union.rb +0 -2
- data/lib/arel_extensions/nodes/union_all.rb +0 -2
- data/lib/arel_extensions/nodes/wday.rb +0 -4
- data/lib/arel_extensions/null_functions.rb +3 -5
- data/lib/arel_extensions/predications.rb +2 -3
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +0 -2
- data/lib/arel_extensions/string_functions.rb +21 -22
- data/lib/arel_extensions/tasks.rb +1 -1
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors.rb +9 -7
- data/lib/arel_extensions/visitors/convert_format.rb +37 -0
- data/lib/arel_extensions/visitors/ibm_db.rb +4 -11
- data/lib/arel_extensions/visitors/mssql.rb +48 -44
- data/lib/arel_extensions/visitors/mysql.rb +63 -65
- data/lib/arel_extensions/visitors/oracle.rb +48 -55
- data/lib/arel_extensions/visitors/oracle12.rb +2 -3
- data/lib/arel_extensions/visitors/postgresql.rb +39 -34
- data/lib/arel_extensions/visitors/sqlite.rb +23 -18
- data/lib/arel_extensions/visitors/to_sql.rb +42 -44
- data/test/arelx_test_helper.rb +0 -2
- data/test/real_db_test.rb +26 -41
- data/test/support/fake_record.rb +1 -1
- data/test/test_comparators.rb +0 -4
- data/test/visitors/test_bulk_insert_oracle.rb +0 -1
- data/test/visitors/test_bulk_insert_sqlite.rb +0 -2
- data/test/visitors/test_oracle.rb +1 -2
- data/test/visitors/test_to_sql.rb +16 -25
- data/test/with_ar/all_agnostic_test.rb +134 -139
- data/test/with_ar/insert_agnostic_test.rb +0 -2
- data/test/with_ar/test_bulk_sqlite.rb +0 -4
- data/test/with_ar/test_math_sqlite.rb +4 -8
- data/test/with_ar/test_string_mysql.rb +1 -5
- data/test/with_ar/test_string_sqlite.rb +1 -5
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +3 -2
data/test/arelx_test_helper.rb
CHANGED
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
|
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
|
94
|
-
assert_equal 2,User.where(User.arel_table[:age] <=10
|
95
|
-
assert_equal 3,User.where(User.arel_table[:age] > 20
|
96
|
-
assert_equal 4,User.where(User.arel_table[:age] >=20
|
97
|
-
assert_equal 1,User.where(User.arel_table[:age] > 5
|
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(
|
151
|
-
assert_equal "",db.get_first_value(
|
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
|
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
|
-
|
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
|
data/test/support/fake_record.rb
CHANGED
data/test/test_comparators.rb
CHANGED
@@ -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
|
@@ -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
|
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
|
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)
|
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)
|
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)
|
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)
|
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))
|
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))
|
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))
|
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))
|
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
|
@@ -220,7 +219,7 @@ module ArelExtensions
|
|
220
219
|
assert_equal 'Lu', t(@lucas, @name[0,2])
|
221
220
|
assert_equal 'Lu', t(@lucas, @name[0..1])
|
222
221
|
|
223
|
-
#substring should accept string function
|
222
|
+
# substring should accept string function
|
224
223
|
assert_equal 'Ce', t(@camille, @name.substring(1, 1).concat('e'))
|
225
224
|
assert_equal 'Ce', t(@camille, @name.substring(1, 1)+'e')
|
226
225
|
end
|
@@ -233,7 +232,7 @@ module ArelExtensions
|
|
233
232
|
end
|
234
233
|
|
235
234
|
def test_string_comparators
|
236
|
-
#skip "Oracle can't use math operators to compare strings" if @env_db == 'oracle' # use GREATEST ?
|
235
|
+
# skip "Oracle can't use math operators to compare strings" if @env_db == 'oracle' # use GREATEST ?
|
237
236
|
skip "SQL Server can't use math operators to compare strings" if @env_db == 'mssql' # use GREATEST ?
|
238
237
|
if @env_db == 'postgresql' # may return real boolean
|
239
238
|
assert t(@neg, @name >= 'Mest') == true || t(@neg, @name >= 'Mest') == 't' # depends of ar version
|
@@ -254,20 +253,19 @@ module ArelExtensions
|
|
254
253
|
def test_compare_on_date_time_types
|
255
254
|
skip "Sqlite can't compare time" if $sqlite
|
256
255
|
skip "Oracle can't compare time" if @env_db == 'oracle'
|
257
|
-
|
256
|
+
# @created_at == 2016-05-23
|
258
257
|
assert_includes [true,'t',1], t(@laure, ArelExtensions::Nodes::Case.new.when(@created_at >= '2014-01-01').then(1).else(0))
|
259
258
|
assert_includes [false,'f',0], t(@laure, ArelExtensions::Nodes::Case.new.when(@created_at >= '2018-01-01').then(1).else(0))
|
260
|
-
|
259
|
+
# @updated_at == 2014-03-03 12:42:00
|
261
260
|
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
261
|
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
|
-
|
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
|
262
|
+
# @duration == 12:42:21
|
263
|
+
# puts @laure.select(ArelExtensions::Nodes::Case.new.when(@duration >= '10:10:10').then(1).else(0)).to_sql
|
264
|
+
# puts @laure.select(ArelExtensions::Nodes::Case.new.when(@duration >= '14:10:10').then(1).else(0)).to_sql
|
266
265
|
assert_includes [true,'t',1], t(@laure, ArelExtensions::Nodes::Case.new.when(@duration >= '10:10:10').then(1).else(0))
|
267
266
|
assert_includes [false,'f',0], t(@laure, ArelExtensions::Nodes::Case.new.when(@duration >= '14:10:10').then(1).else(0))
|
268
267
|
end
|
269
268
|
|
270
|
-
|
271
269
|
def test_regexp_not_regexp
|
272
270
|
skip "Sqlite version can't load extension for regexp" if $sqlite && $load_extension_disabled
|
273
271
|
skip "SQL Server does not know about REGEXP without extensions" if @env_db == 'mssql'
|
@@ -278,7 +276,7 @@ module ArelExtensions
|
|
278
276
|
end
|
279
277
|
|
280
278
|
def test_imatches
|
281
|
-
#puts User.where(@name.imatches('m%')).to_sql
|
279
|
+
# puts User.where(@name.imatches('m%')).to_sql
|
282
280
|
assert_equal 1, User.where(@name.imatches('m%')).count
|
283
281
|
assert_equal 4, User.where(@name.imatches_any(['L%', '%e'])).count
|
284
282
|
assert_equal 7, User.where(@name.idoes_not_match('L%')).count
|
@@ -298,7 +296,7 @@ module ArelExtensions
|
|
298
296
|
|
299
297
|
def test_replace_once
|
300
298
|
skip "TODO"
|
301
|
-
#skip "Sqlite version can't load extension for locate" if $sqlite && $load_extension_disabled
|
299
|
+
# skip "Sqlite version can't load extension for locate" if $sqlite && $load_extension_disabled
|
302
300
|
assert_equal "LuCas", t(@lucas, @name.substring(1, @name.locate('c') - 1) + 'C' + @name.substring(@name.locate('c') + 1, @name.length))
|
303
301
|
end
|
304
302
|
|
@@ -307,7 +305,7 @@ module ArelExtensions
|
|
307
305
|
skip "PostgreSql version can't load extension for soundex" if @env_db == 'postgresql'
|
308
306
|
assert_equal "C540", t(@camille, @name.soundex)
|
309
307
|
assert_equal 9, User.where(@name.soundex.eq(@name.soundex)).count
|
310
|
-
assert_equal 9
|
308
|
+
assert_equal 9, User.where(@name.soundex == @name.soundex).count
|
311
309
|
end
|
312
310
|
|
313
311
|
def test_change_case
|
@@ -397,27 +395,27 @@ module ArelExtensions
|
|
397
395
|
end
|
398
396
|
|
399
397
|
def test_date_duration
|
400
|
-
#Year
|
398
|
+
# Year
|
401
399
|
assert_equal 2016, t(@lucas, @created_at.year).to_i
|
402
400
|
assert_equal 0, User.where(@created_at.year.eq("2012")).count
|
403
|
-
#Month
|
401
|
+
# Month
|
404
402
|
assert_equal 5, t(@camille, @created_at.month).to_i
|
405
403
|
assert_equal 9, User.where(@created_at.month.eq("05")).count
|
406
|
-
#Week
|
404
|
+
# Week
|
407
405
|
assert_equal(@env_db == 'mssql' ? 22 : 21, t(@arthur, @created_at.week).to_i)
|
408
406
|
assert_equal 9, User.where(@created_at.month.eq("05")).count
|
409
|
-
#Day
|
407
|
+
# Day
|
410
408
|
assert_equal 23, t(@laure, @created_at.day).to_i
|
411
409
|
assert_equal 0, User.where(@created_at.day.eq("05")).count
|
412
410
|
|
413
|
-
#skip "manage DATE" if @env_db == 'oracle'
|
414
|
-
#Hour
|
411
|
+
# skip "manage DATE" if @env_db == 'oracle'
|
412
|
+
# Hour
|
415
413
|
assert_equal 0, t(@laure, @created_at.hour).to_i
|
416
414
|
assert_equal 12, t(@lucas, @updated_at.hour).to_i
|
417
|
-
#Minute
|
415
|
+
# Minute
|
418
416
|
assert_equal 0, t(@laure, @created_at.minute).to_i
|
419
417
|
assert_equal 42, t(@lucas, @updated_at.minute).to_i
|
420
|
-
#Second
|
418
|
+
# Second
|
421
419
|
assert_equal 0, t(@laure, @created_at.second).to_i
|
422
420
|
assert_equal 0, t(@lucas, @updated_at.second).to_i
|
423
421
|
end
|
@@ -450,13 +448,13 @@ module ArelExtensions
|
|
450
448
|
|
451
449
|
datetime1 = Time.utc(2014, 3, 3, 12, 42, 0)
|
452
450
|
# Pull Request #5 tests
|
453
|
-
#puts (@created_at + durPos).cast(:date).to_sql
|
451
|
+
# puts (@created_at + durPos).cast(:date).to_sql
|
454
452
|
assert_includes [date2,"2026-05-23"], t(@test,(@created_at + durPos).cast(:date))
|
455
453
|
assert_includes [date3,"2006-05-23"], t(@test,(@created_at + durNeg).cast(:date))
|
456
454
|
|
457
|
-
#puts (@created_at + @created_at.day).cast(:date).to_sql
|
455
|
+
# puts (@created_at + @created_at.day).cast(:date).to_sql
|
458
456
|
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
|
457
|
+
# puts (@created_at - @created_at.day).cast(:date).to_sql
|
460
458
|
assert_includes [date5,"2016-04-30"], t(@test,(@created_at - @created_at.day).cast(:date))
|
461
459
|
|
462
460
|
assert_includes [datetime1 + 42.seconds,"2014-03-03 12:42:42 UTC"], t(@lucas,(@updated_at + @updated_at.minute))
|
@@ -464,18 +462,18 @@ module ArelExtensions
|
|
464
462
|
|
465
463
|
# (@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))).to_sql
|
466
464
|
assert_includes [datetime1 + (12*60+42).seconds,"2014-03-03 12:54:42 UTC"],
|
467
|
-
|
465
|
+
t(@lucas,(@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))))
|
468
466
|
|
469
467
|
assert_includes [datetime1 + (12*60+42).minutes,"2014-03-04 01:24:00 UTC"],
|
470
|
-
|
468
|
+
t(@lucas,(@updated_at + Arel.duration('mn',(@updated_at.hour*60 + @updated_at.minute))))
|
471
469
|
|
472
470
|
assert_includes ["2024-03-03"], t(@lucas,(@updated_at + durPos).format('%Y-%m-%d'))
|
473
|
-
#puts (@updated_at - durPos).to_sql
|
471
|
+
# puts (@updated_at - durPos).to_sql
|
474
472
|
assert_includes ["2004-03-03"], t(@lucas,(@updated_at - durPos).format('%Y-%m-%d'))
|
475
473
|
|
476
474
|
|
477
475
|
# we test with the ruby object or the string because some adapters don't return an object Date
|
478
|
-
# end
|
476
|
+
# end
|
479
477
|
end
|
480
478
|
|
481
479
|
# TODO; cast types
|
@@ -496,27 +494,27 @@ module ArelExtensions
|
|
496
494
|
assert_equal Time, t(@lucas,@updated_at.cast(:string).cast(:datetime)).class
|
497
495
|
assert_equal Time, t(@lucas,@updated_at.cast(:time)).class
|
498
496
|
|
499
|
-
assert_equal "2014-03-03 12:42:00", t(@lucas,@updated_at.cast(:string)) unless @env_db == 'mssql' #locale dependent
|
497
|
+
assert_equal "2014-03-03 12:42:00", t(@lucas,@updated_at.cast(:string)) unless @env_db == 'mssql' # locale dependent
|
500
498
|
assert_equal Date.parse("2014-03-03"), t(@lucas,Arel::Nodes.build_quoted('2014-03-03').cast(:date))
|
501
499
|
assert_equal Date.parse("5014-03-03"), t(@lucas,(@age.cast(:string) + '014-03-03').cast(:date))
|
502
500
|
assert_equal Time.parse("2014-03-03 12:42:00 UTC"), t(@lucas,@updated_at.cast(:string).cast(:datetime))
|
503
501
|
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
|
502
|
+
assert_equal "12:42:00", t(@lucas,@updated_at.cast(:time).cast(:string)).split('.').first unless @env_db == 'oracle' # DateTime
|
505
503
|
end
|
506
504
|
end
|
507
505
|
|
508
506
|
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'
|
507
|
+
# puts User.where(@age.is_null).select(@name).to_sql
|
508
|
+
# puts @age.is_null
|
509
|
+
# puts @age.is_null.inspect
|
510
|
+
# puts @age.is_null.to_sql
|
511
|
+
# puts @age=='34'
|
514
512
|
assert_equal "Test", User.select(@name).where(@age.is_null.to_sql).first.name
|
515
513
|
end
|
516
514
|
|
517
515
|
def test_math_plus
|
518
516
|
d = Date.new(1997, 6, 15)
|
519
|
-
#Concat String
|
517
|
+
# Concat String
|
520
518
|
assert_equal "SophiePhan", t(@sophie, @name + "Phan")
|
521
519
|
assert_equal "Sophie2", t(@sophie, @name + 2)
|
522
520
|
assert_equal "Sophie1997-06-15", t(@sophie, @name + d)
|
@@ -525,25 +523,24 @@ module ArelExtensions
|
|
525
523
|
assert_equal "SophieSophieSophie", t(@sophie, @name + @name + @name)
|
526
524
|
assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name.concat(@name)))
|
527
525
|
assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name).concat(@name))
|
528
|
-
#FIXME: should work as expected in Oracle
|
526
|
+
# FIXME: should work as expected in Oracle
|
529
527
|
assert_equal "Sophie2016-05-23", t(@sophie, @name + @created_at) unless @env_db == 'oracle'
|
530
|
-
#concat Integer
|
528
|
+
# concat Integer
|
531
529
|
assert_equal 1, User.where((@age + 10).eq(33)).count
|
532
530
|
assert_equal 1, User.where((@age + "1").eq(6)).count
|
533
531
|
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)
|
532
|
+
# concat Date
|
533
|
+
# puts((User.arel_table[:created_at] + 1).as("res").to_sql.inspect)
|
536
534
|
assert_equal "2016-05-24", t(@myung, @created_at + 1).to_date.to_s
|
537
535
|
assert_equal "2016-05-25", t(@myung, @created_at + 2.day).to_date.to_s
|
538
536
|
end
|
539
537
|
|
540
|
-
|
541
538
|
def test_math_minus
|
542
539
|
d = Date.new(2016, 5, 20)
|
543
|
-
#Datediff
|
540
|
+
# Datediff
|
544
541
|
assert_equal 9, User.where((@created_at - @created_at).eq(0)).count
|
545
542
|
assert_equal 3, @laure.select((@created_at - d).as("res")).first.res.abs.to_i
|
546
|
-
#Substraction
|
543
|
+
# Substraction
|
547
544
|
assert_equal 0, User.where((@age - 10).eq(50)).count
|
548
545
|
assert_equal 0, User.where((@age - "10").eq(50)).count
|
549
546
|
# assert_equal 0, User.where((@age - 9.5).eq(50.5)).count # should work: TODO
|
@@ -551,7 +548,7 @@ module ArelExtensions
|
|
551
548
|
end
|
552
549
|
|
553
550
|
def test_wday
|
554
|
-
#d = Date.new(2016, 6, 26)
|
551
|
+
# d = Date.new(2016, 6, 26)
|
555
552
|
assert_equal(@env_db == 'oracle' || @env_db == 'mssql' ? 2 : 1, t(@myung, @created_at.wday).to_i) # monday
|
556
553
|
end
|
557
554
|
|
@@ -587,41 +584,41 @@ module ArelExtensions
|
|
587
584
|
assert_equal 0, t(@arthur, @score.when(65.62,1).else(0)-1)
|
588
585
|
assert_equal "11", t(@arthur, @score.when(65.62).then("1").else("0")+"1")
|
589
586
|
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
|
587
|
+
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
588
|
end
|
592
589
|
|
593
590
|
def test_format_numbers
|
594
|
-
#score of Arthur = 65.62
|
591
|
+
# score of Arthur = 65.62
|
595
592
|
skip " Works with SQLite if the version used knows printf" if $sqlite
|
596
593
|
|
597
|
-
assert_equal "Wrong Format"
|
598
|
-
assert_equal "AZERTY65,62"
|
599
|
-
assert_equal "65,62AZERTY"
|
600
|
-
assert_equal "$ 65.62 €"
|
601
|
-
assert_equal "$ 66 €"
|
602
|
-
assert_equal "$ 0065,62 €"
|
603
|
-
assert_equal "$ 65,62 €"
|
604
|
-
assert_equal "$ 65,62 €"
|
605
|
-
assert_equal "$ 65,62 €"
|
606
|
-
assert_equal "$ 65,6 €"
|
607
|
-
assert_equal "$ +65,62 €"
|
608
|
-
assert_equal "$ +065,62 €"
|
594
|
+
assert_equal "Wrong Format", t(@arthur, @score.format_number("$ %...234.6F €","fr_FR"))
|
595
|
+
assert_equal "AZERTY65,62", t(@arthur, @score.format_number("AZERTY%.2f","fr_FR"))
|
596
|
+
assert_equal "65,62AZERTY", t(@arthur, @score.format_number("%.2fAZERTY","fr_FR"))
|
597
|
+
assert_equal "$ 65.62 €", t(@arthur, @score.format_number("$ %.2f €","en_US"))
|
598
|
+
assert_equal "$ 66 €", t(@arthur, @score.format_number("$ %.0f €","en_US"))
|
599
|
+
assert_equal "$ 0065,62 €", t(@arthur, @score.format_number("$ %07.2f €","fr_FR"))
|
600
|
+
assert_equal "$ 65,62 €", t(@arthur, @score.format_number("$ %-07.2f €","fr_FR"))
|
601
|
+
assert_equal "$ 65,62 €", t(@arthur, @score.format_number("$ %-7.2f €","fr_FR"))
|
602
|
+
assert_equal "$ 65,62 €", t(@arthur, @score.format_number("$ % 7.2f €","fr_FR"))
|
603
|
+
assert_equal "$ 65,6 €", t(@arthur, @score.format_number("$ % 7.1f €","fr_FR"))
|
604
|
+
assert_equal "$ +65,62 €", t(@arthur, @score.format_number("$ % +7.2f €","fr_FR"))
|
605
|
+
assert_equal "$ +065,62 €", t(@arthur, @score.format_number("$ %0+7.2f €","fr_FR"))
|
609
606
|
assert_includes ["$ 6,56e1 €","$ 6,56e+01 €"], t(@arthur, @score.format_number("$ %.2e €","fr_FR"))
|
610
607
|
assert_includes ["$ 6,56E1 €","$ 6,56E+01 €"], t(@arthur, @score.format_number("$ %.2E €","fr_FR"))
|
611
608
|
assert_includes ["$ 6,562E1 €","$ 6,562E+01 €"], t(@arthur, @score.format_number("$ %.3E €","fr_FR"))
|
612
|
-
assert_equal "123 456 765,6"
|
613
|
-
assert_equal "123456765,6"
|
614
|
-
assert_equal "123,456,765.6"
|
615
|
-
assert_equal " 123,456,765.6"
|
616
|
-
assert_equal "$ 0,00 €"
|
617
|
-
assert_equal "$ 0,00 €"
|
609
|
+
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)
|
610
|
+
assert_equal "123456765,6", t(@arthur, (@score+123456700).format_number("%.1f","fr_FR")).gsub("\u00A0","") # because SqlServer does it like no one else
|
611
|
+
assert_equal "123,456,765.6", t(@arthur, (@score+123456700).format_number("%.1f","en_US"))
|
612
|
+
assert_equal " 123,456,765.6", t(@arthur, (@score+123456700).format_number("%16.1f","en_US"))
|
613
|
+
assert_equal "$ 0,00 €", t(@arthur, @score.when(65.62).then(Arel.sql("null")).else(1).format_number("$ %.2f €","fr_FR"))
|
614
|
+
assert_equal "$ 0,00 €", t(@arthur, (@score-65.62).format_number("$ %.2f €","fr_FR"))
|
618
615
|
end
|
619
616
|
|
620
617
|
def test_accent_insensitive
|
621
618
|
skip "SQLite is natively Case Insensitive and Accent Sensitive" if $sqlite
|
622
619
|
skip "Not finished" if @env_db == 'mysql'
|
623
620
|
# actual comments value: "arrêté"
|
624
|
-
#AI & CI
|
621
|
+
# AI & CI
|
625
622
|
if !['postgresql'].include?(@env_db) # Extension unaccent required on PG
|
626
623
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrêté")).then("1").else("0"))
|
627
624
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrete")).then("1").else("0"))
|
@@ -629,7 +626,7 @@ module ArelExtensions
|
|
629
626
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arretez")).then("1").else("0"))
|
630
627
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrete")).then("1").else("0"))
|
631
628
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrêté")).then("1").else("0"))
|
632
|
-
#AI & CS
|
629
|
+
# AI & CS
|
633
630
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrêté")).then("1").else("0"))
|
634
631
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrete")).then("1").else("0"))
|
635
632
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("àrrétè")).then("1").else("0"))
|
@@ -639,7 +636,7 @@ module ArelExtensions
|
|
639
636
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("Arrêté")).then("1").else("0"))
|
640
637
|
end
|
641
638
|
end
|
642
|
-
#AS & CI
|
639
|
+
# AS & CI
|
643
640
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrêté")).then("1").else("0"))
|
644
641
|
if !['mysql'].include?(@env_db) # CI => AI in utf8 (AI not possible in latin1)
|
645
642
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrete")).then("1").else("0"))
|
@@ -650,7 +647,7 @@ module ArelExtensions
|
|
650
647
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrete")).then("1").else("0"))
|
651
648
|
end
|
652
649
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrêté")).then("1").else("0"))
|
653
|
-
#AS & CS
|
650
|
+
# AS & CS
|
654
651
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrêté")).then("1").else("0"))
|
655
652
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrete")).then("1").else("0"))
|
656
653
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("àrrétè")).then("1").else("0"))
|
@@ -664,29 +661,29 @@ module ArelExtensions
|
|
664
661
|
assert_equal 9, User.where(@ut[:name].in(@ut.project(@ut[:name]).order(@ut[:name]))).count
|
665
662
|
if !['mysql'].include?(@env_db) # MySql can't have limit in IN subquery
|
666
663
|
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
|
664
|
+
# assert_equal 6, User.where(:name => User.select(:name).order(:name).offset(2)).count
|
668
665
|
end
|
669
666
|
end
|
670
667
|
|
671
668
|
def test_in_with_nil
|
672
|
-
assert_equal true
|
673
|
-
assert_equal false
|
674
|
-
assert_equal true
|
675
|
-
assert_equal true
|
676
|
-
assert_equal false
|
677
|
-
assert_equal true
|
678
|
-
assert_equal true
|
679
|
-
assert_equal true
|
680
|
-
assert_equal false
|
681
|
-
assert_equal true
|
682
|
-
assert_equal false
|
683
|
-
assert_equal true
|
684
|
-
assert_equal true
|
685
|
-
assert_equal true
|
686
|
-
assert_equal false
|
687
|
-
assert_equal false
|
688
|
-
assert_equal false
|
689
|
-
assert_equal false
|
669
|
+
assert_equal true, @myung.where(@age.in(1)).blank?
|
670
|
+
assert_equal false, @myung.where(@age.in(23)).blank?
|
671
|
+
assert_equal true, @myung.where(@age.in([1])).blank?
|
672
|
+
assert_equal true, @myung.where(@age.in([1,2])).blank?
|
673
|
+
assert_equal false, @myung.where(@age.in([1,23])).blank?
|
674
|
+
assert_equal true, @myung.where(@age.in(nil)).blank?
|
675
|
+
assert_equal true, @myung.where(@age.in([nil])).blank?
|
676
|
+
assert_equal true, @myung.where(@age.in([nil,1])).blank?
|
677
|
+
assert_equal false, @myung.where(@age.in([nil,23])).blank?
|
678
|
+
assert_equal true, @myung.where(@age.in([nil,1,2])).blank?
|
679
|
+
assert_equal false, @myung.where(@age.in([nil,1,23])).blank?
|
680
|
+
assert_equal true, @test.where(@age.in(1)).blank?
|
681
|
+
assert_equal true, @test.where(@age.in([1])).blank?
|
682
|
+
assert_equal true, @test.where(@age.in([1,2])).blank?
|
683
|
+
assert_equal false, @test.where(@age.in(nil)).blank?
|
684
|
+
assert_equal false, @test.where(@age.in([nil])).blank?
|
685
|
+
assert_equal false, @test.where(@age.in([nil,1])).blank?
|
686
|
+
assert_equal false, @test.where(@age.in([nil,1,2])).blank?
|
690
687
|
end
|
691
688
|
|
692
689
|
def test_scope_with_in_plus_new
|
@@ -700,40 +697,40 @@ module ArelExtensions
|
|
700
697
|
end
|
701
698
|
|
702
699
|
def test_is_not_null
|
703
|
-
assert_equal false
|
704
|
-
assert_equal true
|
700
|
+
assert_equal false, @myung.where(@age.is_not_null).blank?
|
701
|
+
assert_equal true, @test.where(@age.is_not_null).blank?
|
705
702
|
end
|
706
703
|
|
707
704
|
def test_not_in_with_nil
|
708
|
-
assert_equal false
|
709
|
-
assert_equal true
|
710
|
-
assert_equal false
|
711
|
-
assert_equal false
|
712
|
-
assert_equal true
|
713
|
-
assert_equal false
|
714
|
-
assert_equal false
|
715
|
-
assert_equal false
|
716
|
-
assert_equal true
|
717
|
-
assert_equal false
|
718
|
-
assert_equal true
|
719
|
-
|
720
|
-
assert_equal false
|
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?
|
705
|
+
assert_equal false, @myung.where(@age.not_in(1)).blank?
|
706
|
+
assert_equal true, @myung.where(@age.not_in(23)).blank?
|
707
|
+
assert_equal false, @myung.where(@age.not_in([1])).blank?
|
708
|
+
assert_equal false, @myung.where(@age.not_in([1,2])).blank?
|
709
|
+
assert_equal true, @myung.where(@age.not_in([1,23])).blank?
|
710
|
+
assert_equal false, @myung.where(@age.not_in(nil)).blank?
|
711
|
+
assert_equal false, @myung.where(@age.not_in([nil])).blank?
|
712
|
+
assert_equal false, @myung.where(@age.not_in([nil,1])).blank?
|
713
|
+
assert_equal true, @myung.where(@age.not_in([nil,23])).blank?
|
714
|
+
assert_equal false, @myung.where(@age.not_in([nil,1,2])).blank?
|
715
|
+
assert_equal true, @myung.where(@age.not_in([nil,1,23])).blank?
|
716
|
+
|
717
|
+
assert_equal false, @myung.where(@age.not_in(1..2)).blank?
|
718
|
+
|
719
|
+
# if the column is null, the entry will never be selected with not in (like every DBMS does)
|
720
|
+
# assert_equal false , @test.where(@age.not_in(1)).blank?
|
721
|
+
# assert_equal false , @test.where(@age.not_in([1])).blank?
|
722
|
+
# assert_equal false , @test.where(@age.not_in([1,2])).blank?
|
723
|
+
# assert_equal true , @test.where(@age.not_in(nil)).blank?
|
724
|
+
# assert_equal true , @test.where(@age.not_in([nil])).blank?
|
725
|
+
# assert_equal true , @test.where(@age.not_in([nil,1])).blank?
|
726
|
+
# assert_equal true , @test.where(@age.not_in([nil,1,2])).blank?
|
730
727
|
end
|
731
728
|
|
732
729
|
def test_in_on_grouping
|
733
730
|
skip "We should modify the visitor of IN to make it work" if $sqlite || @env_db == 'mssql'
|
734
|
-
assert_equal 2
|
735
|
-
assert_equal 1
|
736
|
-
assert_equal 0
|
731
|
+
assert_equal 2, User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23),Arel.tuple('Arthur',21))).count
|
732
|
+
assert_equal 1, User.where(Arel.tuple(@name,@age).in(Arel.tuple('Myung',23))).count
|
733
|
+
assert_equal 0, User.where(Arel.tuple(@name,@age).in([])).count
|
737
734
|
end
|
738
735
|
|
739
736
|
def test_alias_shortened
|
@@ -742,29 +739,29 @@ module ArelExtensions
|
|
742
739
|
at = User.arel_table.alias('azerty' * 15)
|
743
740
|
assert_equal "\"user_tests\" \"#{new_alias}\"".downcase, User.arel_table.alias('azerty' * 15).to_sql.downcase
|
744
741
|
assert_equal '"user_tests" "u"'.downcase, User.arel_table.alias('u').to_sql.downcase
|
745
|
-
assert_equal
|
746
|
-
|
742
|
+
assert_equal %Q[SELECT "#{new_alias}"."id" FROM "user_tests" "#{new_alias}"].downcase,
|
743
|
+
User.select(at[:id]).from(at).to_sql.downcase
|
747
744
|
end
|
748
745
|
end
|
749
746
|
|
750
747
|
def test_stat_functions
|
751
748
|
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))
|
749
|
+
# puts t(User.where(nil), @score.average)
|
750
|
+
# puts t(User.where(nil), @score.variance(unbiased: true))
|
751
|
+
# puts t(User.where(nil), @score.variance(unbiased: false))
|
752
|
+
# puts t(User.where(nil), @score.std(unbiased: true))
|
753
|
+
# puts t(User.where(nil), @score.std(unbiased: false))
|
757
754
|
|
758
755
|
assert ( 15.43222 - t(User.where(nil), @score.average)).abs < 0.01
|
759
756
|
assert (539.79804 - t(User.where(nil), @score.variance)).abs < 0.01
|
760
757
|
assert (479.82048 - t(User.where(nil), @score.variance(unbiased: false))).abs < 0.01
|
761
758
|
assert ( 23.23355 - t(User.where(nil), @score.std)).abs < 0.01
|
762
759
|
assert ( 21.90480 - t(User.where(nil), @score.std(unbiased: false))).abs < 0.01
|
763
|
-
skip "Not Yet Implemented" #if !['postgresql'].include?(@env_db)
|
760
|
+
skip "Not Yet Implemented" # if !['postgresql'].include?(@env_db)
|
764
761
|
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
|
762
|
+
assert_equal 2, User.select(@score.variance(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
|
763
|
+
assert_equal 2, User.select(@score.sum(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
|
764
|
+
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
765
|
end
|
769
766
|
|
770
767
|
def test_levenshtein_distance
|
@@ -776,7 +773,7 @@ module ArelExtensions
|
|
776
773
|
|
777
774
|
def test_json
|
778
775
|
skip "Can't be tested on travis"
|
779
|
-
#creation
|
776
|
+
# creation
|
780
777
|
assert_equal 'Arthur', t(@arthur,Arel.json(@name))
|
781
778
|
assert_equal ["Arthur","Arthur"], parse_json(t(@arthur,Arel.json(@name,@name)))
|
782
779
|
assert_equal ({"Arthur" => "Arthur", "Arthur2" => "ArthurArthur"}), parse_json(t(@arthur,Arel.json({@name => @name,@name+"2" => @name+@name})))
|
@@ -785,29 +782,29 @@ module ArelExtensions
|
|
785
782
|
|
786
783
|
# aggregate
|
787
784
|
assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure"}),
|
788
|
-
|
785
|
+
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name}).group(false)))
|
789
786
|
assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure", "Laure"=>25, "Lucas"=>5, "Myung"=>23, "Sophie"=>15}),
|
790
|
-
|
787
|
+
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name,@name => @age}).group(false)))
|
791
788
|
assert_equal ([{"5" => "Lucas"},{ "15" => "Sophie"},{ "23" => "Myung"},{ "25" => "Laure"}]),
|
792
|
-
|
789
|
+
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
790
|
|
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
|
791
|
+
# puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_sql
|
792
|
+
# 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
793
|
|
797
794
|
skip "Not Yet Implemented" if $sqlite || ['oracle','mssql'].include?(@env_db)
|
798
|
-
#get
|
795
|
+
# get
|
799
796
|
h1 = Arel.json({@name => @name+@name,@name+"2" => 1})
|
800
797
|
assert_equal "ArthurArthur", parse_json(t(@arthur,h1.get(@name)))
|
801
798
|
h2 = Arel.json([{age: @age},{name: @name,score: @score}])
|
802
799
|
assert_equal ({"age" => 21}), parse_json(t(@arthur,h2.get(0)))
|
803
800
|
assert_equal 21, parse_json(t(@arthur,h2.get(0).get('age')))
|
804
801
|
assert_nil t(@arthur,h2.get('age'))
|
805
|
-
#set
|
802
|
+
# set
|
806
803
|
assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1}), parse_json(t(@arthur,h1.set(@name, ['toto','tata'])))
|
807
804
|
assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.set(@name+"3",2)))
|
808
805
|
assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => nil}), parse_json(t(@arthur,h1.set(@name+"3",nil)))
|
809
806
|
assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => {"a" => 2}}), parse_json(t(@arthur,h1.set(@name+"3",{a: 2})))
|
810
|
-
#merge
|
807
|
+
# merge
|
811
808
|
assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata']},{@name+"3" => 2})))
|
812
809
|
assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata'], @name+"3" => 2})))
|
813
810
|
assert_equal ({"Arthur" => "ArthurArthur","Arthur2" => 1}), parse_json(t(@arthur,h1.merge({})))
|
@@ -815,7 +812,7 @@ module ArelExtensions
|
|
815
812
|
|
816
813
|
def test_as_on_everything
|
817
814
|
name = @arthur.select(@name.as('NaMe')).first.attributes
|
818
|
-
assert_equal 'Arthur', name["NaMe"] || name["name"] #because of Oracle
|
815
|
+
assert_equal 'Arthur', name["NaMe"] || name["name"] # because of Oracle
|
819
816
|
assert_equal 'Arthur', @arthur.select(@name.as('Na Me')).first.attributes["Na Me"]
|
820
817
|
assert_equal 'ArthurArthur', @arthur.select((@name+@name).as('Na-Me')).first.attributes["Na-Me"]
|
821
818
|
end
|
@@ -823,8 +820,6 @@ module ArelExtensions
|
|
823
820
|
def test_exists_in_subquery
|
824
821
|
assert User.where(User.where(nil).arel.exists).first
|
825
822
|
end
|
826
|
-
|
827
|
-
|
828
823
|
end
|
829
824
|
end
|
830
825
|
end
|