arel_extensions 1.2.14 → 1.2.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +102 -0
- data/.travis.yml +2 -0
- data/Gemfile +10 -10
- data/Rakefile +4 -4
- data/arel_extensions.gemspec +1 -1
- 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/gemfiles/rails6_1.gemfile +30 -0
- data/gemspecs/arel_extensions-v1.gemspec +28 -0
- data/{gemspec_v2 → gemspecs}/arel_extensions-v2.gemspec +0 -0
- data/generate_gems.sh +4 -3
- data/lib/arel_extensions.rb +6 -4
- data/lib/arel_extensions/attributes.rb +0 -0
- data/lib/arel_extensions/boolean_functions.rb +21 -5
- data/lib/arel_extensions/common_sql_functions.rb +2 -4
- 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 +18 -20
- 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 +4 -2
- 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 +2 -4
- data/lib/arel_extensions/nodes/date_diff.rb +7 -8
- 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 +27 -1
- data/lib/arel_extensions/nodes/formatted_number.rb +0 -1
- data/lib/arel_extensions/nodes/function.rb +18 -15
- data/lib/arel_extensions/nodes/is_null.rb +0 -0
- data/lib/arel_extensions/nodes/json.rb +39 -30
- 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 +4 -5
- 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 +5 -6
- 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 +68 -60
- 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 +49 -44
- data/lib/arel_extensions/visitors/mysql.rb +65 -67
- data/lib/arel_extensions/visitors/oracle.rb +58 -55
- data/lib/arel_extensions/visitors/oracle12.rb +2 -3
- data/lib/arel_extensions/visitors/postgresql.rb +41 -34
- data/lib/arel_extensions/visitors/sqlite.rb +23 -18
- data/lib/arel_extensions/visitors/to_sql.rb +78 -61
- data/test/arelx_test_helper.rb +0 -2
- data/test/database.yml +2 -0
- data/test/real_db_test.rb +27 -42
- 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 +135 -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 +8 -4
data/test/arelx_test_helper.rb
CHANGED
data/test/database.yml
CHANGED
data/test/real_db_test.rb
CHANGED
@@ -21,10 +21,10 @@ def setup_db
|
|
21
21
|
db.enable_load_extension(0)
|
22
22
|
rescue => e
|
23
23
|
$load_extension_disabled = true
|
24
|
-
$stderr << "
|
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
|
@@ -356,6 +354,7 @@ module ArelExtensions
|
|
356
354
|
assert_equal '2016-05-23', t(@lucas, @created_at.format('%Y-%m-%d'))
|
357
355
|
skip "SQL Server does not accept any format" if @env_db == 'mssql'
|
358
356
|
assert_equal '2014/03/03 12:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S'))
|
357
|
+
assert_equal '12:42%', t(@lucas, @updated_at.format('%R%%'))
|
359
358
|
end
|
360
359
|
|
361
360
|
def test_coalesce
|
@@ -396,27 +395,27 @@ module ArelExtensions
|
|
396
395
|
end
|
397
396
|
|
398
397
|
def test_date_duration
|
399
|
-
#Year
|
398
|
+
# Year
|
400
399
|
assert_equal 2016, t(@lucas, @created_at.year).to_i
|
401
400
|
assert_equal 0, User.where(@created_at.year.eq("2012")).count
|
402
|
-
#Month
|
401
|
+
# Month
|
403
402
|
assert_equal 5, t(@camille, @created_at.month).to_i
|
404
403
|
assert_equal 9, User.where(@created_at.month.eq("05")).count
|
405
|
-
#Week
|
404
|
+
# Week
|
406
405
|
assert_equal(@env_db == 'mssql' ? 22 : 21, t(@arthur, @created_at.week).to_i)
|
407
406
|
assert_equal 9, User.where(@created_at.month.eq("05")).count
|
408
|
-
#Day
|
407
|
+
# Day
|
409
408
|
assert_equal 23, t(@laure, @created_at.day).to_i
|
410
409
|
assert_equal 0, User.where(@created_at.day.eq("05")).count
|
411
410
|
|
412
|
-
#skip "manage DATE" if @env_db == 'oracle'
|
413
|
-
#Hour
|
411
|
+
# skip "manage DATE" if @env_db == 'oracle'
|
412
|
+
# Hour
|
414
413
|
assert_equal 0, t(@laure, @created_at.hour).to_i
|
415
414
|
assert_equal 12, t(@lucas, @updated_at.hour).to_i
|
416
|
-
#Minute
|
415
|
+
# Minute
|
417
416
|
assert_equal 0, t(@laure, @created_at.minute).to_i
|
418
417
|
assert_equal 42, t(@lucas, @updated_at.minute).to_i
|
419
|
-
#Second
|
418
|
+
# Second
|
420
419
|
assert_equal 0, t(@laure, @created_at.second).to_i
|
421
420
|
assert_equal 0, t(@lucas, @updated_at.second).to_i
|
422
421
|
end
|
@@ -449,13 +448,13 @@ module ArelExtensions
|
|
449
448
|
|
450
449
|
datetime1 = Time.utc(2014, 3, 3, 12, 42, 0)
|
451
450
|
# Pull Request #5 tests
|
452
|
-
#puts (@created_at + durPos).cast(:date).to_sql
|
451
|
+
# puts (@created_at + durPos).cast(:date).to_sql
|
453
452
|
assert_includes [date2,"2026-05-23"], t(@test,(@created_at + durPos).cast(:date))
|
454
453
|
assert_includes [date3,"2006-05-23"], t(@test,(@created_at + durNeg).cast(:date))
|
455
454
|
|
456
|
-
#puts (@created_at + @created_at.day).cast(:date).to_sql
|
455
|
+
# puts (@created_at + @created_at.day).cast(:date).to_sql
|
457
456
|
assert_includes [date4,"2016-06-15"], t(@test,(@created_at + @created_at.day).cast(:date))
|
458
|
-
#puts (@created_at - @created_at.day).cast(:date).to_sql
|
457
|
+
# puts (@created_at - @created_at.day).cast(:date).to_sql
|
459
458
|
assert_includes [date5,"2016-04-30"], t(@test,(@created_at - @created_at.day).cast(:date))
|
460
459
|
|
461
460
|
assert_includes [datetime1 + 42.seconds,"2014-03-03 12:42:42 UTC"], t(@lucas,(@updated_at + @updated_at.minute))
|
@@ -463,18 +462,18 @@ module ArelExtensions
|
|
463
462
|
|
464
463
|
# (@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))).to_sql
|
465
464
|
assert_includes [datetime1 + (12*60+42).seconds,"2014-03-03 12:54:42 UTC"],
|
466
|
-
|
465
|
+
t(@lucas,(@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))))
|
467
466
|
|
468
467
|
assert_includes [datetime1 + (12*60+42).minutes,"2014-03-04 01:24:00 UTC"],
|
469
|
-
|
468
|
+
t(@lucas,(@updated_at + Arel.duration('mn',(@updated_at.hour*60 + @updated_at.minute))))
|
470
469
|
|
471
470
|
assert_includes ["2024-03-03"], t(@lucas,(@updated_at + durPos).format('%Y-%m-%d'))
|
472
|
-
#puts (@updated_at - durPos).to_sql
|
471
|
+
# puts (@updated_at - durPos).to_sql
|
473
472
|
assert_includes ["2004-03-03"], t(@lucas,(@updated_at - durPos).format('%Y-%m-%d'))
|
474
473
|
|
475
474
|
|
476
475
|
# we test with the ruby object or the string because some adapters don't return an object Date
|
477
|
-
# end
|
476
|
+
# end
|
478
477
|
end
|
479
478
|
|
480
479
|
# TODO; cast types
|
@@ -495,27 +494,27 @@ module ArelExtensions
|
|
495
494
|
assert_equal Time, t(@lucas,@updated_at.cast(:string).cast(:datetime)).class
|
496
495
|
assert_equal Time, t(@lucas,@updated_at.cast(:time)).class
|
497
496
|
|
498
|
-
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
|
499
498
|
assert_equal Date.parse("2014-03-03"), t(@lucas,Arel::Nodes.build_quoted('2014-03-03').cast(:date))
|
500
499
|
assert_equal Date.parse("5014-03-03"), t(@lucas,(@age.cast(:string) + '014-03-03').cast(:date))
|
501
500
|
assert_equal Time.parse("2014-03-03 12:42:00 UTC"), t(@lucas,@updated_at.cast(:string).cast(:datetime))
|
502
501
|
assert_equal Date.parse("2014-03-03"), t(@lucas,@updated_at.cast(:date))
|
503
|
-
assert_equal "12:42:00", t(@lucas,@updated_at.cast(:time).cast(:string)).split('.').first unless @env_db == 'oracle' #DateTime
|
502
|
+
assert_equal "12:42:00", t(@lucas,@updated_at.cast(:time).cast(:string)).split('.').first unless @env_db == 'oracle' # DateTime
|
504
503
|
end
|
505
504
|
end
|
506
505
|
|
507
506
|
def test_is_null
|
508
|
-
#puts User.where(@age.is_null).select(@name).to_sql
|
509
|
-
#puts @age.is_null
|
510
|
-
#puts @age.is_null.inspect
|
511
|
-
#puts @age.is_null.to_sql
|
512
|
-
#puts @age=='34'
|
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'
|
513
512
|
assert_equal "Test", User.select(@name).where(@age.is_null.to_sql).first.name
|
514
513
|
end
|
515
514
|
|
516
515
|
def test_math_plus
|
517
516
|
d = Date.new(1997, 6, 15)
|
518
|
-
#Concat String
|
517
|
+
# Concat String
|
519
518
|
assert_equal "SophiePhan", t(@sophie, @name + "Phan")
|
520
519
|
assert_equal "Sophie2", t(@sophie, @name + 2)
|
521
520
|
assert_equal "Sophie1997-06-15", t(@sophie, @name + d)
|
@@ -524,25 +523,24 @@ module ArelExtensions
|
|
524
523
|
assert_equal "SophieSophieSophie", t(@sophie, @name + @name + @name)
|
525
524
|
assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name.concat(@name)))
|
526
525
|
assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name).concat(@name))
|
527
|
-
#FIXME: should work as expected in Oracle
|
526
|
+
# FIXME: should work as expected in Oracle
|
528
527
|
assert_equal "Sophie2016-05-23", t(@sophie, @name + @created_at) unless @env_db == 'oracle'
|
529
|
-
#concat Integer
|
528
|
+
# concat Integer
|
530
529
|
assert_equal 1, User.where((@age + 10).eq(33)).count
|
531
530
|
assert_equal 1, User.where((@age + "1").eq(6)).count
|
532
531
|
assert_equal 1, User.where((@age + @age).eq(10)).count
|
533
|
-
#concat Date
|
534
|
-
#puts((User.arel_table[:created_at] + 1).as("res").to_sql.inspect)
|
532
|
+
# concat Date
|
533
|
+
# puts((User.arel_table[:created_at] + 1).as("res").to_sql.inspect)
|
535
534
|
assert_equal "2016-05-24", t(@myung, @created_at + 1).to_date.to_s
|
536
535
|
assert_equal "2016-05-25", t(@myung, @created_at + 2.day).to_date.to_s
|
537
536
|
end
|
538
537
|
|
539
|
-
|
540
538
|
def test_math_minus
|
541
539
|
d = Date.new(2016, 5, 20)
|
542
|
-
#Datediff
|
540
|
+
# Datediff
|
543
541
|
assert_equal 9, User.where((@created_at - @created_at).eq(0)).count
|
544
542
|
assert_equal 3, @laure.select((@created_at - d).as("res")).first.res.abs.to_i
|
545
|
-
#Substraction
|
543
|
+
# Substraction
|
546
544
|
assert_equal 0, User.where((@age - 10).eq(50)).count
|
547
545
|
assert_equal 0, User.where((@age - "10").eq(50)).count
|
548
546
|
# assert_equal 0, User.where((@age - 9.5).eq(50.5)).count # should work: TODO
|
@@ -550,7 +548,7 @@ module ArelExtensions
|
|
550
548
|
end
|
551
549
|
|
552
550
|
def test_wday
|
553
|
-
#d = Date.new(2016, 6, 26)
|
551
|
+
# d = Date.new(2016, 6, 26)
|
554
552
|
assert_equal(@env_db == 'oracle' || @env_db == 'mssql' ? 2 : 1, t(@myung, @created_at.wday).to_i) # monday
|
555
553
|
end
|
556
554
|
|
@@ -586,41 +584,41 @@ module ArelExtensions
|
|
586
584
|
assert_equal 0, t(@arthur, @score.when(65.62,1).else(0)-1)
|
587
585
|
assert_equal "11", t(@arthur, @score.when(65.62).then("1").else("0")+"1")
|
588
586
|
assert_equal 66.62, t(@arthur, @score.when(65.62).then(@score).else(@score)+1)
|
589
|
-
assert_equal "65.621", t(@arthur, @score.when(65.62).then(@score.cast(:string)).else(@score.cast(:string))+1).tr('0','') #tr is here because of precision on cast for some DBMS
|
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
|
590
588
|
end
|
591
589
|
|
592
590
|
def test_format_numbers
|
593
|
-
#score of Arthur = 65.62
|
591
|
+
# score of Arthur = 65.62
|
594
592
|
skip " Works with SQLite if the version used knows printf" if $sqlite
|
595
593
|
|
596
|
-
assert_equal "Wrong Format"
|
597
|
-
assert_equal "AZERTY65,62"
|
598
|
-
assert_equal "65,62AZERTY"
|
599
|
-
assert_equal "$ 65.62 €"
|
600
|
-
assert_equal "$ 66 €"
|
601
|
-
assert_equal "$ 0065,62 €"
|
602
|
-
assert_equal "$ 65,62 €"
|
603
|
-
assert_equal "$ 65,62 €"
|
604
|
-
assert_equal "$ 65,62 €"
|
605
|
-
assert_equal "$ 65,6 €"
|
606
|
-
assert_equal "$ +65,62 €"
|
607
|
-
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"))
|
608
606
|
assert_includes ["$ 6,56e1 €","$ 6,56e+01 €"], t(@arthur, @score.format_number("$ %.2e €","fr_FR"))
|
609
607
|
assert_includes ["$ 6,56E1 €","$ 6,56E+01 €"], t(@arthur, @score.format_number("$ %.2E €","fr_FR"))
|
610
608
|
assert_includes ["$ 6,562E1 €","$ 6,562E+01 €"], t(@arthur, @score.format_number("$ %.3E €","fr_FR"))
|
611
|
-
assert_equal "123 456 765,6"
|
612
|
-
assert_equal "123456765,6"
|
613
|
-
assert_equal "123,456,765.6"
|
614
|
-
assert_equal " 123,456,765.6"
|
615
|
-
assert_equal "$ 0,00 €"
|
616
|
-
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"))
|
617
615
|
end
|
618
616
|
|
619
617
|
def test_accent_insensitive
|
620
618
|
skip "SQLite is natively Case Insensitive and Accent Sensitive" if $sqlite
|
621
619
|
skip "Not finished" if @env_db == 'mysql'
|
622
620
|
# actual comments value: "arrêté"
|
623
|
-
#AI & CI
|
621
|
+
# AI & CI
|
624
622
|
if !['postgresql'].include?(@env_db) # Extension unaccent required on PG
|
625
623
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrêté")).then("1").else("0"))
|
626
624
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrete")).then("1").else("0"))
|
@@ -628,7 +626,7 @@ module ArelExtensions
|
|
628
626
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arretez")).then("1").else("0"))
|
629
627
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrete")).then("1").else("0"))
|
630
628
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrêté")).then("1").else("0"))
|
631
|
-
#AI & CS
|
629
|
+
# AI & CS
|
632
630
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrêté")).then("1").else("0"))
|
633
631
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrete")).then("1").else("0"))
|
634
632
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("àrrétè")).then("1").else("0"))
|
@@ -638,7 +636,7 @@ module ArelExtensions
|
|
638
636
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("Arrêté")).then("1").else("0"))
|
639
637
|
end
|
640
638
|
end
|
641
|
-
#AS & CI
|
639
|
+
# AS & CI
|
642
640
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrêté")).then("1").else("0"))
|
643
641
|
if !['mysql'].include?(@env_db) # CI => AI in utf8 (AI not possible in latin1)
|
644
642
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrete")).then("1").else("0"))
|
@@ -649,7 +647,7 @@ module ArelExtensions
|
|
649
647
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrete")).then("1").else("0"))
|
650
648
|
end
|
651
649
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrêté")).then("1").else("0"))
|
652
|
-
#AS & CS
|
650
|
+
# AS & CS
|
653
651
|
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrêté")).then("1").else("0"))
|
654
652
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrete")).then("1").else("0"))
|
655
653
|
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("àrrétè")).then("1").else("0"))
|
@@ -663,29 +661,29 @@ module ArelExtensions
|
|
663
661
|
assert_equal 9, User.where(@ut[:name].in(@ut.project(@ut[:name]).order(@ut[:name]))).count
|
664
662
|
if !['mysql'].include?(@env_db) # MySql can't have limit in IN subquery
|
665
663
|
assert_equal 2, User.where(:name => User.select(:name).order(:name).limit(2)).count
|
666
|
-
#assert_equal 6, User.where(:name => User.select(:name).order(:name).offset(2)).count
|
664
|
+
# assert_equal 6, User.where(:name => User.select(:name).order(:name).offset(2)).count
|
667
665
|
end
|
668
666
|
end
|
669
667
|
|
670
668
|
def test_in_with_nil
|
671
|
-
assert_equal true
|
672
|
-
assert_equal false
|
673
|
-
assert_equal true
|
674
|
-
assert_equal true
|
675
|
-
assert_equal false
|
676
|
-
assert_equal true
|
677
|
-
assert_equal true
|
678
|
-
assert_equal true
|
679
|
-
assert_equal false
|
680
|
-
assert_equal true
|
681
|
-
assert_equal false
|
682
|
-
assert_equal true
|
683
|
-
assert_equal true
|
684
|
-
assert_equal true
|
685
|
-
assert_equal false
|
686
|
-
assert_equal false
|
687
|
-
assert_equal false
|
688
|
-
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?
|
689
687
|
end
|
690
688
|
|
691
689
|
def test_scope_with_in_plus_new
|
@@ -699,40 +697,40 @@ module ArelExtensions
|
|
699
697
|
end
|
700
698
|
|
701
699
|
def test_is_not_null
|
702
|
-
assert_equal false
|
703
|
-
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?
|
704
702
|
end
|
705
703
|
|
706
704
|
def test_not_in_with_nil
|
707
|
-
assert_equal false
|
708
|
-
assert_equal true
|
709
|
-
assert_equal false
|
710
|
-
assert_equal false
|
711
|
-
assert_equal true
|
712
|
-
assert_equal false
|
713
|
-
assert_equal false
|
714
|
-
assert_equal false
|
715
|
-
assert_equal true
|
716
|
-
assert_equal false
|
717
|
-
assert_equal true
|
718
|
-
|
719
|
-
assert_equal false
|
720
|
-
|
721
|
-
#if the column is null, the entry will never be selected with not in (like every DBMS does)
|
722
|
-
#assert_equal false , @test.where(@age.not_in(1)).blank?
|
723
|
-
#assert_equal false , @test.where(@age.not_in([1])).blank?
|
724
|
-
#assert_equal false , @test.where(@age.not_in([1,2])).blank?
|
725
|
-
#assert_equal true , @test.where(@age.not_in(nil)).blank?
|
726
|
-
#assert_equal true , @test.where(@age.not_in([nil])).blank?
|
727
|
-
#assert_equal true , @test.where(@age.not_in([nil,1])).blank?
|
728
|
-
#assert_equal true , @test.where(@age.not_in([nil,1,2])).blank?
|
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?
|
729
727
|
end
|
730
728
|
|
731
729
|
def test_in_on_grouping
|
732
730
|
skip "We should modify the visitor of IN to make it work" if $sqlite || @env_db == 'mssql'
|
733
|
-
assert_equal 2
|
734
|
-
assert_equal 1
|
735
|
-
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
|
736
734
|
end
|
737
735
|
|
738
736
|
def test_alias_shortened
|
@@ -741,29 +739,29 @@ module ArelExtensions
|
|
741
739
|
at = User.arel_table.alias('azerty' * 15)
|
742
740
|
assert_equal "\"user_tests\" \"#{new_alias}\"".downcase, User.arel_table.alias('azerty' * 15).to_sql.downcase
|
743
741
|
assert_equal '"user_tests" "u"'.downcase, User.arel_table.alias('u').to_sql.downcase
|
744
|
-
assert_equal
|
745
|
-
|
742
|
+
assert_equal %Q[SELECT "#{new_alias}"."id" FROM "user_tests" "#{new_alias}"].downcase,
|
743
|
+
User.select(at[:id]).from(at).to_sql.downcase
|
746
744
|
end
|
747
745
|
end
|
748
746
|
|
749
747
|
def test_stat_functions
|
750
748
|
skip "SQLite doesn't work for most on this functions" if $sqlite
|
751
|
-
#puts t(User.where(nil), @score.average)
|
752
|
-
#puts t(User.where(nil), @score.variance(unbiased: true))
|
753
|
-
#puts t(User.where(nil), @score.variance(unbiased: false))
|
754
|
-
#puts t(User.where(nil), @score.std(unbiased: true))
|
755
|
-
#puts t(User.where(nil), @score.std(unbiased: false))
|
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))
|
756
754
|
|
757
755
|
assert ( 15.43222 - t(User.where(nil), @score.average)).abs < 0.01
|
758
756
|
assert (539.79804 - t(User.where(nil), @score.variance)).abs < 0.01
|
759
757
|
assert (479.82048 - t(User.where(nil), @score.variance(unbiased: false))).abs < 0.01
|
760
758
|
assert ( 23.23355 - t(User.where(nil), @score.std)).abs < 0.01
|
761
759
|
assert ( 21.90480 - t(User.where(nil), @score.std(unbiased: false))).abs < 0.01
|
762
|
-
skip "Not Yet Implemented" #if !['postgresql'].include?(@env_db)
|
760
|
+
skip "Not Yet Implemented" # if !['postgresql'].include?(@env_db)
|
763
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
|
764
|
-
assert_equal 2, User.select(@score.variance(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
|
765
|
-
assert_equal 2, User.select(@score.sum(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
|
766
|
-
assert_equal 2, User.select(@comments.group_concat(group: Arel.when(@name > "M").then(0).else(1)).as('res')).map{|e|e['res']}.uniq.length
|
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
|
767
765
|
end
|
768
766
|
|
769
767
|
def test_levenshtein_distance
|
@@ -775,7 +773,7 @@ module ArelExtensions
|
|
775
773
|
|
776
774
|
def test_json
|
777
775
|
skip "Can't be tested on travis"
|
778
|
-
#creation
|
776
|
+
# creation
|
779
777
|
assert_equal 'Arthur', t(@arthur,Arel.json(@name))
|
780
778
|
assert_equal ["Arthur","Arthur"], parse_json(t(@arthur,Arel.json(@name,@name)))
|
781
779
|
assert_equal ({"Arthur" => "Arthur", "Arthur2" => "ArthurArthur"}), parse_json(t(@arthur,Arel.json({@name => @name,@name+"2" => @name+@name})))
|
@@ -784,29 +782,29 @@ module ArelExtensions
|
|
784
782
|
|
785
783
|
# aggregate
|
786
784
|
assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure"}),
|
787
|
-
|
785
|
+
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name}).group(false)))
|
788
786
|
assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure", "Laure"=>25, "Lucas"=>5, "Myung"=>23, "Sophie"=>15}),
|
789
|
-
|
787
|
+
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name,@name => @age}).group(false)))
|
790
788
|
assert_equal ([{"5" => "Lucas"},{ "15" => "Sophie"},{ "23" => "Myung"},{ "25" => "Laure"}]),
|
791
|
-
|
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])))
|
792
790
|
|
793
|
-
#puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_sql
|
794
|
-
#puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_a
|
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
|
795
793
|
|
796
794
|
skip "Not Yet Implemented" if $sqlite || ['oracle','mssql'].include?(@env_db)
|
797
|
-
#get
|
795
|
+
# get
|
798
796
|
h1 = Arel.json({@name => @name+@name,@name+"2" => 1})
|
799
797
|
assert_equal "ArthurArthur", parse_json(t(@arthur,h1.get(@name)))
|
800
798
|
h2 = Arel.json([{age: @age},{name: @name,score: @score}])
|
801
799
|
assert_equal ({"age" => 21}), parse_json(t(@arthur,h2.get(0)))
|
802
800
|
assert_equal 21, parse_json(t(@arthur,h2.get(0).get('age')))
|
803
801
|
assert_nil t(@arthur,h2.get('age'))
|
804
|
-
#set
|
802
|
+
# set
|
805
803
|
assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1}), parse_json(t(@arthur,h1.set(@name, ['toto','tata'])))
|
806
804
|
assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.set(@name+"3",2)))
|
807
805
|
assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => nil}), parse_json(t(@arthur,h1.set(@name+"3",nil)))
|
808
806
|
assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => {"a" => 2}}), parse_json(t(@arthur,h1.set(@name+"3",{a: 2})))
|
809
|
-
#merge
|
807
|
+
# merge
|
810
808
|
assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata']},{@name+"3" => 2})))
|
811
809
|
assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata'], @name+"3" => 2})))
|
812
810
|
assert_equal ({"Arthur" => "ArthurArthur","Arthur2" => 1}), parse_json(t(@arthur,h1.merge({})))
|
@@ -814,7 +812,7 @@ module ArelExtensions
|
|
814
812
|
|
815
813
|
def test_as_on_everything
|
816
814
|
name = @arthur.select(@name.as('NaMe')).first.attributes
|
817
|
-
assert_equal 'Arthur', name["NaMe"] || name["name"] #because of Oracle
|
815
|
+
assert_equal 'Arthur', name["NaMe"] || name["name"] # because of Oracle
|
818
816
|
assert_equal 'Arthur', @arthur.select(@name.as('Na Me')).first.attributes["Na Me"]
|
819
817
|
assert_equal 'ArthurArthur', @arthur.select((@name+@name).as('Na-Me')).first.attributes["Na-Me"]
|
820
818
|
end
|
@@ -822,8 +820,6 @@ module ArelExtensions
|
|
822
820
|
def test_exists_in_subquery
|
823
821
|
assert User.where(User.where(nil).arel.exists).first
|
824
822
|
end
|
825
|
-
|
826
|
-
|
827
823
|
end
|
828
824
|
end
|
829
825
|
end
|