arel_extensions 1.7.0 → 2.0.0.rc3
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/.codeclimate.yml +2 -1
- data/.gitignore +6 -8
- data/.rubocop.yml +4 -194
- data/.travis/oracle/download.js +152 -0
- data/.travis/oracle/download.sh +30 -0
- data/.travis/oracle/download_ojdbc.js +116 -0
- data/.travis/oracle/install.sh +34 -0
- data/.travis/setup_accounts.sh +9 -0
- data/.travis/sqlite3/extension-functions.sh +6 -0
- data/.travis.yml +223 -0
- data/Gemfile +28 -2
- data/README.md +89 -265
- data/Rakefile +30 -50
- data/TODO +1 -0
- data/appveyor.yml +22 -60
- data/arel_extensions.gemspec +17 -14
- data/functions.html +3 -3
- data/gemfiles/rails3.gemfile +20 -0
- data/gemfiles/rails4.gemfile +29 -0
- data/gemfiles/rails5_0.gemfile +29 -0
- data/gemfiles/rails5_1_4.gemfile +17 -19
- data/gemfiles/rails5_2.gemfile +17 -26
- data/init/mssql.sql +4 -4
- data/init/mysql.sql +38 -38
- data/init/oracle.sql +0 -0
- data/init/postgresql.sql +25 -24
- data/init/sqlite.sql +0 -0
- data/lib/arel_extensions/attributes.rb +3 -9
- data/lib/arel_extensions/boolean_functions.rb +16 -57
- data/lib/arel_extensions/common_sql_functions.rb +20 -21
- data/lib/arel_extensions/comparators.rb +28 -31
- data/lib/arel_extensions/date_duration.rb +13 -19
- data/lib/arel_extensions/insert_manager.rb +15 -22
- data/lib/arel_extensions/math.rb +70 -68
- data/lib/arel_extensions/math_functions.rb +52 -57
- data/lib/arel_extensions/nodes/abs.rb +1 -0
- data/lib/arel_extensions/nodes/blank.rb +5 -6
- data/lib/arel_extensions/nodes/case.rb +27 -31
- data/lib/arel_extensions/nodes/cast.rb +12 -12
- data/lib/arel_extensions/nodes/ceil.rb +1 -1
- data/lib/arel_extensions/nodes/coalesce.rb +5 -4
- data/lib/arel_extensions/nodes/collate.rb +10 -9
- data/lib/arel_extensions/nodes/concat.rb +22 -13
- data/lib/arel_extensions/nodes/date_diff.rb +70 -77
- data/lib/arel_extensions/nodes/duration.rb +5 -2
- data/lib/arel_extensions/nodes/find_in_set.rb +1 -0
- data/lib/arel_extensions/nodes/floor.rb +1 -1
- data/lib/arel_extensions/nodes/format.rb +8 -35
- data/lib/arel_extensions/nodes/formatted_number.rb +23 -22
- data/lib/arel_extensions/nodes/function.rb +39 -50
- data/lib/arel_extensions/nodes/is_null.rb +0 -2
- data/lib/arel_extensions/nodes/json.rb +47 -72
- data/lib/arel_extensions/nodes/length.rb +0 -5
- data/lib/arel_extensions/nodes/levenshtein_distance.rb +2 -2
- data/lib/arel_extensions/nodes/locate.rb +3 -2
- data/lib/arel_extensions/nodes/log10.rb +2 -1
- data/lib/arel_extensions/nodes/matches.rb +8 -6
- data/lib/arel_extensions/nodes/md5.rb +1 -0
- data/lib/arel_extensions/nodes/power.rb +5 -5
- data/lib/arel_extensions/nodes/rand.rb +3 -2
- data/lib/arel_extensions/nodes/repeat.rb +6 -4
- data/lib/arel_extensions/nodes/replace.rb +8 -16
- data/lib/arel_extensions/nodes/round.rb +7 -6
- data/lib/arel_extensions/nodes/soundex.rb +15 -15
- data/lib/arel_extensions/nodes/std.rb +21 -18
- data/lib/arel_extensions/nodes/substring.rb +16 -58
- data/lib/arel_extensions/nodes/then.rb +2 -2
- data/lib/arel_extensions/nodes/trim.rb +7 -5
- data/lib/arel_extensions/nodes/union.rb +9 -6
- data/lib/arel_extensions/nodes/union_all.rb +8 -5
- data/lib/arel_extensions/nodes/wday.rb +6 -2
- data/lib/arel_extensions/nodes.rb +1 -1
- data/lib/arel_extensions/null_functions.rb +6 -18
- data/lib/arel_extensions/predications.rb +49 -54
- data/lib/arel_extensions/railtie.rb +5 -5
- data/lib/arel_extensions/set_functions.rb +7 -5
- data/lib/arel_extensions/string_functions.rb +55 -110
- data/lib/arel_extensions/tasks.rb +6 -6
- data/lib/arel_extensions/version.rb +1 -3
- data/lib/arel_extensions/visitors/ibm_db.rb +36 -29
- data/lib/arel_extensions/visitors/mssql.rb +248 -493
- data/lib/arel_extensions/visitors/mysql.rb +244 -420
- data/lib/arel_extensions/visitors/oracle.rb +258 -311
- data/lib/arel_extensions/visitors/oracle12.rb +34 -20
- data/lib/arel_extensions/visitors/postgresql.rb +239 -350
- data/lib/arel_extensions/visitors/sqlite.rb +169 -191
- data/lib/arel_extensions/visitors/to_sql.rb +299 -371
- data/lib/arel_extensions/visitors.rb +62 -83
- data/lib/arel_extensions.rb +32 -243
- data/test/database.yml +10 -20
- data/test/helper.rb +18 -0
- data/test/real_db_test.rb +120 -123
- data/test/support/fake_record.rb +3 -11
- data/test/test_comparators.rb +17 -14
- data/test/visitors/test_bulk_insert_oracle.rb +12 -12
- data/test/visitors/test_bulk_insert_sqlite.rb +14 -13
- data/test/visitors/test_bulk_insert_to_sql.rb +13 -11
- data/test/visitors/test_oracle.rb +55 -55
- data/test/visitors/test_to_sql.rb +226 -419
- data/test/with_ar/all_agnostic_test.rb +375 -912
- data/test/with_ar/insert_agnostic_test.rb +22 -28
- data/test/with_ar/test_bulk_sqlite.rb +17 -18
- data/test/with_ar/test_math_sqlite.rb +27 -27
- data/test/with_ar/test_string_mysql.rb +34 -32
- data/test/with_ar/test_string_sqlite.rb +35 -31
- metadata +64 -50
- data/.github/workflows/publish.yml +0 -30
- data/.github/workflows/release.yml +0 -30
- data/.github/workflows/ruby.yml +0 -452
- data/CONTRIBUTING.md +0 -102
- data/Makefile +0 -48
- data/NEWS.md +0 -131
- data/bin/build +0 -15
- data/bin/publish +0 -8
- data/dev/arelx.dockerfile +0 -41
- data/dev/compose.yaml +0 -69
- data/dev/postgres.dockerfile +0 -5
- data/dev/rbenv +0 -189
- data/gemfiles/rails5.gemfile +0 -36
- data/gemfiles/rails6.gemfile +0 -40
- data/gemfiles/rails6_1.gemfile +0 -48
- data/gemfiles/rails7.gemfile +0 -48
- data/gemfiles/rails7_1.gemfile +0 -48
- data/gemfiles/rails7_2.gemfile +0 -47
- data/gemfiles/rails8.gemfile +0 -40
- data/gemfiles/rails8_1.gemfile +0 -41
- data/gemspecs/arel_extensions-v1.gemspec +0 -25
- data/gemspecs/arel_extensions-v2.gemspec +0 -25
- data/generate_gems.sh +0 -15
- data/lib/arel_extensions/aliases.rb +0 -14
- data/lib/arel_extensions/constants.rb +0 -13
- data/lib/arel_extensions/helpers.rb +0 -61
- data/lib/arel_extensions/nodes/aggregate_function.rb +0 -13
- data/lib/arel_extensions/nodes/byte_size.rb +0 -11
- data/lib/arel_extensions/nodes/char_length.rb +0 -11
- data/lib/arel_extensions/nodes/formatted_date.rb +0 -42
- data/lib/arel_extensions/nodes/rollup.rb +0 -36
- data/lib/arel_extensions/nodes/select.rb +0 -10
- data/lib/arel_extensions/nodes/sum.rb +0 -7
- data/lib/arel_extensions/visitors/convert_format.rb +0 -37
- data/lib/arel_extensions/warning.rb +0 -42
- data/test/arelx_test_helper.rb +0 -94
- data/test/config_loader.rb +0 -9
- data/version_v1.rb +0 -5
- data/version_v2.rb +0 -5
|
@@ -1,39 +1,21 @@
|
|
|
1
|
-
require '
|
|
1
|
+
require 'helper'
|
|
2
2
|
require 'date'
|
|
3
3
|
|
|
4
|
-
# class ActiveRecord::ConnectionAdapters::SQLServerAdapter
|
|
5
|
-
# # We use *args to avoid breaking signature changes between versions.
|
|
6
|
-
# # internal_exec_sql_query(sql, name = "SQL", binds = [], prepare: false)
|
|
7
|
-
# def internal_exec_sql_query(*args)
|
|
8
|
-
# sql = args.first
|
|
9
|
-
# puts "[DEBUG] MSSQL Query: #{sql}\n"
|
|
10
|
-
|
|
11
|
-
# # Call original implementation (defined in the DatabaseStatements module included in this class)
|
|
12
|
-
# super
|
|
13
|
-
# rescue => e
|
|
14
|
-
# # Catch the crash to print the specific query that caused it one last time
|
|
15
|
-
# puts "[CRASH]: #{args.first}\n"
|
|
16
|
-
# raise e
|
|
17
|
-
# end
|
|
18
|
-
# end
|
|
19
|
-
|
|
20
4
|
module ArelExtensions
|
|
21
|
-
module
|
|
5
|
+
module WthAr
|
|
6
|
+
|
|
22
7
|
class ListTest < Minitest::Test
|
|
8
|
+
require 'minitest/pride'
|
|
23
9
|
def connect_db
|
|
24
|
-
ActiveRecord::Base.configurations =
|
|
25
|
-
if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE ==
|
|
26
|
-
@env_db = (RUBY_PLATFORM == 'java' ?
|
|
27
|
-
skip "Platform not supported
|
|
10
|
+
ActiveRecord::Base.configurations = YAML.load_file('test/database.yml')
|
|
11
|
+
if ENV['DB'] == 'oracle' && ((defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx") || (RUBY_PLATFORM == 'java')) # not supported
|
|
12
|
+
@env_db = (RUBY_PLATFORM == 'java' ? "jdbc-sqlite" : 'sqlite')
|
|
13
|
+
skip "Platform not supported"
|
|
28
14
|
else
|
|
29
15
|
@env_db = ENV['DB']
|
|
30
16
|
end
|
|
31
17
|
ActiveRecord::Base.establish_connection(@env_db.try(:to_sym) || (RUBY_PLATFORM == 'java' ? :"jdbc-sqlite" : :sqlite))
|
|
32
|
-
|
|
33
|
-
ActiveRecord.default_timezone = :utc
|
|
34
|
-
else
|
|
35
|
-
ActiveRecord::Base.default_timezone = :utc
|
|
36
|
-
end
|
|
18
|
+
ActiveRecord::Base.default_timezone = :utc
|
|
37
19
|
@cnx = ActiveRecord::Base.connection
|
|
38
20
|
$sqlite = @cnx.adapter_name =~ /sqlite/i
|
|
39
21
|
$load_extension_disabled ||= false
|
|
@@ -48,15 +30,14 @@ module ArelExtensions
|
|
|
48
30
|
t.column :name, :string
|
|
49
31
|
t.column :comments, :text
|
|
50
32
|
t.column :created_at, :date
|
|
51
|
-
t.column :updated_at, :datetime
|
|
33
|
+
t.column :updated_at, :datetime
|
|
52
34
|
t.column :duration, :time
|
|
53
35
|
t.column :other, :string
|
|
54
|
-
t.column :score, :decimal, precision
|
|
55
|
-
t.column :enabled, :boolean
|
|
36
|
+
t.column :score, :decimal, :precision => 20, :scale => 10
|
|
56
37
|
end
|
|
57
38
|
@cnx.drop_table(:product_tests) rescue nil
|
|
58
39
|
@cnx.create_table :product_tests do |t|
|
|
59
|
-
t.column :price, :decimal, precision
|
|
40
|
+
t.column :price, :decimal, :precision => 20, :scale => 10
|
|
60
41
|
end
|
|
61
42
|
end
|
|
62
43
|
|
|
@@ -71,34 +52,24 @@ module ArelExtensions
|
|
|
71
52
|
d = Date.new(2016, 5, 23)
|
|
72
53
|
connect_db
|
|
73
54
|
setup_db
|
|
74
|
-
u = User.create age
|
|
75
|
-
@lucas = User.where(id
|
|
76
|
-
u = User.create age
|
|
77
|
-
@sophie = User.where(id
|
|
78
|
-
u = User.create age
|
|
79
|
-
@camille = User.where(id
|
|
80
|
-
u = User.create age
|
|
81
|
-
@arthur = User.where(id
|
|
82
|
-
u = User.create age
|
|
83
|
-
@myung = User.where(id
|
|
84
|
-
u = User.create age
|
|
85
|
-
@laure = User.where(id
|
|
86
|
-
u = User.create age
|
|
87
|
-
@test = User.where(id
|
|
88
|
-
u = User.create age
|
|
89
|
-
@neg = User.where(id
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
u = User.create age: nil, name: 'nilly', created_at: nil, score: nil
|
|
93
|
-
@nilly = User.where(id: u.id)
|
|
94
|
-
u = User.create age: nil, name: 'esmé', created_at: nil, score: nil
|
|
95
|
-
@esme = User.where(id: u.id)
|
|
96
|
-
u = User.create age: nil, name: 'esmé ', created_at: nil, score: nil
|
|
97
|
-
@esme2 = User.where(id: u.id)
|
|
98
|
-
u = User.create age: nil, name: nil, created_at: nil, score: nil
|
|
99
|
-
@all_nil = User.where(id: u.id)
|
|
100
|
-
|
|
101
|
-
@id = User.arel_table[:id]
|
|
55
|
+
u = User.create :age => 5, :name => "Lucas", :created_at => d, :score => 20.16, :updated_at => Time.utc(2014, 3, 3, 12, 42, 0)
|
|
56
|
+
@lucas = User.where(:id => u.id)
|
|
57
|
+
u = User.create :age => 15, :name => "Sophie", :created_at => d, :score => 20.16
|
|
58
|
+
@sophie = User.where(:id => u.id)
|
|
59
|
+
u = User.create :age => 20, :name => "Camille", :created_at => d, :score => -20.16, :comments => ''
|
|
60
|
+
@camille = User.where(:id => u.id)
|
|
61
|
+
u = User.create :age => 21, :name => "Arthur", :created_at => d, :score => 65.62, :comments => 'arrêté'
|
|
62
|
+
@arthur = User.where(:id => u.id)
|
|
63
|
+
u = User.create :age => 23, :name => "Myung", :created_at => d, :score => 20.16, :comments => ' '
|
|
64
|
+
@myung = User.where(:id => u.id)
|
|
65
|
+
u = User.create :age => 25, :name => "Laure", :created_at => d, :score => 20.16, :duration => Time.utc(2001, 1, 1, 12, 42, 21),:updated_at => Time.utc(2014, 3, 3, 12, 42, 0)
|
|
66
|
+
@laure = User.where(:id => u.id)
|
|
67
|
+
u = User.create :age => nil, :name => "Test", :created_at => d, :score => 1.62, :other => 'toto'
|
|
68
|
+
@test = User.where(:id => u.id)
|
|
69
|
+
u = User.create :age => -42, :name => "Negatif", :comments => '1,22,3,42,2', :created_at => d, :updated_at => d.to_time, :score => 0.17
|
|
70
|
+
@neg = User.where(:id => u.id)
|
|
71
|
+
|
|
72
|
+
|
|
102
73
|
@age = User.arel_table[:age]
|
|
103
74
|
@name = User.arel_table[:name]
|
|
104
75
|
@score = User.arel_table[:score]
|
|
@@ -108,7 +79,6 @@ module ArelExtensions
|
|
|
108
79
|
@duration = User.arel_table[:duration]
|
|
109
80
|
@price = Product.arel_table[:price]
|
|
110
81
|
@other = User.arel_table[:other]
|
|
111
|
-
@enabled = User.arel_table[:enabled]
|
|
112
82
|
@not_in_table = User.arel_table[:not_in_table]
|
|
113
83
|
|
|
114
84
|
@ut = User.arel_table
|
|
@@ -121,12 +91,10 @@ module ArelExtensions
|
|
|
121
91
|
end
|
|
122
92
|
|
|
123
93
|
def t(scope, node)
|
|
124
|
-
|
|
125
|
-
# puts "[scope] #{res.to_sql}"
|
|
126
|
-
res.to_a.first.res
|
|
94
|
+
scope.select(node.as('res')).to_a.first.res
|
|
127
95
|
end
|
|
128
96
|
|
|
129
|
-
#
|
|
97
|
+
#manage the difference between adapters that handle or not json type
|
|
130
98
|
def parse_json(h)
|
|
131
99
|
if @env_db != 'postgresql'
|
|
132
100
|
JSON.parse("{\"res\":#{h}}")['res']
|
|
@@ -135,14 +103,6 @@ module ArelExtensions
|
|
|
135
103
|
end
|
|
136
104
|
end
|
|
137
105
|
|
|
138
|
-
# Connection and column info
|
|
139
|
-
def test_column_of
|
|
140
|
-
assert_nil Arel.column_of('chupa', 'maflavla'), 'Non-existent table and column should return nil'
|
|
141
|
-
assert_nil Arel.column_of('chupa', 'updated_at'), 'Non-existent table but existent column should return nil'
|
|
142
|
-
assert_nil Arel.column_of('user_tests', 'maflavla'), 'Existent table but non-existent column should return nil'
|
|
143
|
-
assert_equal 'updated_at', Arel.column_of('user_tests', 'updated_at').name, 'An existing column name should be returned'
|
|
144
|
-
end
|
|
145
|
-
|
|
146
106
|
# Math Functions
|
|
147
107
|
def test_classical_arel
|
|
148
108
|
assert_in_epsilon 42.16, t(@laure, @score + 22), 0.01
|
|
@@ -156,28 +116,25 @@ module ArelExtensions
|
|
|
156
116
|
end
|
|
157
117
|
|
|
158
118
|
def test_ceil
|
|
159
|
-
|
|
119
|
+
# skip "Sqlite version can't load extension for ceil" if $sqlite && $load_extension_disabled
|
|
160
120
|
assert_equal 2, t(@test, @score.ceil) # 1.62
|
|
161
121
|
assert_equal(-20, t(@camille, @score.ceil)) # -20.16
|
|
162
122
|
assert_equal(-20, t(@camille, (@score - 0.5).ceil)) # -20.16
|
|
163
123
|
assert_equal 63, t(@arthur, @age.ceil + 42)
|
|
164
|
-
assert_equal 11, t(@justin, @score.ceil) # 11.0
|
|
165
124
|
end
|
|
166
125
|
|
|
167
126
|
def test_floor
|
|
168
|
-
|
|
127
|
+
# skip "Sqlite version can't load extension for floor" if $sqlite && $load_extension_disabled
|
|
169
128
|
assert_equal 0, t(@neg, @score.floor)
|
|
170
129
|
assert_equal 1, t(@test, @score.floor) # 1.62
|
|
171
130
|
assert_equal(-9, t(@test, (@score - 10).floor)) # 1.62
|
|
172
131
|
assert_equal 42, t(@arthur, @score.floor - 23)
|
|
173
|
-
assert_equal 11, t(@justin, @score.floor) # 11.0
|
|
174
|
-
assert_equal(-21, t(@camille, @score.floor)) # # -20.16
|
|
175
132
|
end
|
|
176
133
|
|
|
177
134
|
def test_rand
|
|
178
135
|
assert 42 != User.select(Arel.rand.as('res')).first.res
|
|
179
136
|
assert 0 <= User.select(Arel.rand.abs.as('res')).first.res
|
|
180
|
-
assert_equal
|
|
137
|
+
assert_equal 8, User.order(Arel.rand).limit(50).count
|
|
181
138
|
end
|
|
182
139
|
|
|
183
140
|
def test_round
|
|
@@ -189,126 +146,54 @@ module ArelExtensions
|
|
|
189
146
|
|
|
190
147
|
def test_sum
|
|
191
148
|
if @env_db == 'mssql'
|
|
192
|
-
skip
|
|
193
|
-
assert_equal
|
|
194
|
-
assert_equal
|
|
195
|
-
assert_equal
|
|
196
|
-
assert_equal
|
|
149
|
+
skip "SQL Server forces order?" # TODO
|
|
150
|
+
assert_equal 68, User.select((@age.sum + 1).as("res"), User.arel_table[:id].sum).take(50).reorder(@age).first.res
|
|
151
|
+
assert_equal 134, User.reorder(nil).select((@age.sum + @age.sum).as("res"), User.arel_table[:id].sum).take(50).first.res
|
|
152
|
+
assert_equal 201, User.reorder(nil).select(((@age * 3).sum).as("res"), User.arel_table[:id].sum).take(50).first.res
|
|
153
|
+
assert_equal 4009, User.reorder(nil).select(((@age * @age).sum).as("res"), User.arel_table[:id].sum).take(50).first.res
|
|
197
154
|
else
|
|
198
|
-
assert_equal
|
|
199
|
-
assert_equal
|
|
200
|
-
assert_equal
|
|
201
|
-
assert_equal
|
|
155
|
+
assert_equal 68, User.select((@age.sum + 1).as("res")).take(50).first.res
|
|
156
|
+
assert_equal 134, User.select((@age.sum + @age.sum).as("res")).take(50).first.res
|
|
157
|
+
assert_equal 201, User.select(((@age * 3).sum).as("res")).take(50).first.res
|
|
158
|
+
assert_equal 4009, User.select(((@age * @age).sum).as("res")).take(50).first.res
|
|
202
159
|
end
|
|
203
160
|
end
|
|
204
161
|
|
|
205
|
-
def test_aggregation_with_ar_calculation
|
|
206
|
-
# Since Arel10 (Rails6.1), some unwanted behaviors on aggregated calculation were present.
|
|
207
|
-
# This should works no matter which version of rails is used
|
|
208
|
-
assert User.group(:score).average(:id).values.all?{|e| !e.nil?}
|
|
209
|
-
|
|
210
|
-
# Since Rails 7, a patch to calculations.rb has tirggered a double
|
|
211
|
-
# quoting of the alias name. See https://github.com/rails/rails/commit/7e6e9091e55c3357b0162d44b6ab955ed0c718d5
|
|
212
|
-
# Before the patch that fixed this the following error would occur:
|
|
213
|
-
# ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
|
|
214
|
-
assert User.group(:score).count(:id).values.all?{|e| !e.nil?}
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
def test_rollup
|
|
218
|
-
skip 'sqlite not supported' if $sqlite
|
|
219
|
-
at = User.arel_table
|
|
220
|
-
# single
|
|
221
|
-
q = User.select(at[:name], at[:age].sum).group(Arel::Nodes::RollUp.new([at[:name]]))
|
|
222
|
-
assert q.to_a.length > 0
|
|
223
|
-
|
|
224
|
-
# multi
|
|
225
|
-
q = User.select(at[:name], at[:score], at[:age].sum).group(Arel::Nodes::RollUp.new([at[:score], at[:name]]))
|
|
226
|
-
assert q.to_a.length > 0
|
|
227
|
-
|
|
228
|
-
# hybrid
|
|
229
|
-
q = User.select(at[:name], at[:score], at[:age].sum).group(at[:score], Arel::Nodes::RollUp.new([at[:name]]))
|
|
230
|
-
assert q.to_a.length > 0
|
|
231
|
-
|
|
232
|
-
## Using Arel.rollup which is less verbose than the original way
|
|
233
|
-
|
|
234
|
-
# simple
|
|
235
|
-
q = User.select(at[:name], at[:age].sum).group(Arel.rollup(at[:name]))
|
|
236
|
-
assert q.to_a.length > 0
|
|
237
|
-
|
|
238
|
-
# multi
|
|
239
|
-
q = User.select(at[:name], at[:score], at[:age].sum).group(Arel.rollup([at[:score], at[:name]]))
|
|
240
|
-
assert q.to_a.length > 0
|
|
241
|
-
|
|
242
|
-
# hybrid
|
|
243
|
-
q = User.select(at[:name], at[:score], at[:age].sum).group(at[:score], Arel.rollup([at[:name]]))
|
|
244
|
-
assert q.to_a.length > 0
|
|
245
|
-
|
|
246
|
-
## Using at[:col].rollup which is handy for single column rollups
|
|
247
|
-
|
|
248
|
-
# simple
|
|
249
|
-
q = User.select(at[:name], at[:age].sum).group(at[:name].rollup)
|
|
250
|
-
assert q.to_a.length > 0
|
|
251
|
-
|
|
252
|
-
q = User.select(at[:name], at[:score], at[:age].sum).group(at[:name].rollup, at[:score].rollup)
|
|
253
|
-
assert q.to_a.length > 0
|
|
254
|
-
|
|
255
|
-
# hybrid
|
|
256
|
-
q = User.select(at[:name], at[:score], at[:age].sum).group(at[:name], at[:score].rollup)
|
|
257
|
-
assert q.to_a.length > 0
|
|
258
|
-
end
|
|
259
|
-
|
|
260
162
|
# String Functions
|
|
261
163
|
def test_concat
|
|
262
164
|
assert_equal 'Camille Camille', t(@camille, @name + ' ' + @name)
|
|
263
165
|
assert_equal 'Laure 2', t(@laure, @name + ' ' + 2)
|
|
264
|
-
assert_equal 'Test Laure', t(@laure, Arel.
|
|
265
|
-
end
|
|
166
|
+
assert_equal 'Test Laure', t(@laure, Arel::Nodes.build_quoted('Test ') + @name)
|
|
266
167
|
|
|
267
|
-
|
|
268
|
-
assert_equal
|
|
269
|
-
assert_equal
|
|
270
|
-
assert_equal
|
|
271
|
-
|
|
272
|
-
skip
|
|
273
|
-
assert_equal
|
|
274
|
-
assert_equal
|
|
275
|
-
assert_equal
|
|
276
|
-
assert_equal
|
|
277
|
-
assert_equal 'Lucas,Sophie,Arthur', t(User.where(name: %w[Lucas Sophie Arthur]), @name.group_concat(',', order: [@score.asc, @name.asc]))
|
|
168
|
+
skip "No group_concat in SqlServer before 2017" if @env_db == 'mssql'
|
|
169
|
+
assert_equal "Lucas Sophie", t(User.where(:name => ['Lucas', 'Sophie']), @name.group_concat(' '))
|
|
170
|
+
assert_equal "Lucas,Sophie", t(User.where(:name => ['Lucas', 'Sophie']), @name.group_concat(','))
|
|
171
|
+
assert_equal "Lucas,Sophie", t(User.where(:name => ['Lucas', 'Sophie']), @name.group_concat)
|
|
172
|
+
|
|
173
|
+
skip "No order in group_concat in SqlLite" if $sqlite
|
|
174
|
+
assert_equal "Arthur,Lucas,Sophie", t(User.where(:name => ['Lucas', 'Sophie','Arthur']), @name.group_concat(',',@name.asc))
|
|
175
|
+
assert_equal "Sophie,Lucas,Arthur", t(User.where(:name => ['Lucas', 'Sophie','Arthur']), @name.group_concat(',',@name.desc))
|
|
176
|
+
assert_equal "Lucas,Sophie,Arthur", t(User.where(:name => ['Lucas', 'Sophie','Arthur']), @name.group_concat(',',[@score.asc,@name.asc]))
|
|
177
|
+
assert_equal "Lucas,Sophie,Arthur", t(User.where(:name => ['Lucas', 'Sophie','Arthur']), @name.group_concat(',',@score.asc,@name.asc))
|
|
278
178
|
end
|
|
279
179
|
|
|
280
180
|
def test_length
|
|
281
181
|
assert_equal 7, t(@camille, @name.length)
|
|
282
182
|
assert_equal 7, t(@camille, @name.length.round.abs)
|
|
283
183
|
assert_equal 42, t(@laure, @name.length + 37)
|
|
284
|
-
|
|
285
|
-
if @env_db == 'mssql'
|
|
286
|
-
# By default it's UTF-16, and configuring the CI to be UTF-8 is a bit of a hassle.
|
|
287
|
-
assert_equal 4, t(@esme, @name.byte_size)
|
|
288
|
-
assert_equal 5, t(@esme2, @name.byte_size)
|
|
289
|
-
else
|
|
290
|
-
assert_equal 5, t(@esme, @name.byte_size)
|
|
291
|
-
assert_equal 6, t(@esme2, @name.byte_size)
|
|
292
|
-
end
|
|
293
|
-
assert_equal 0, t(@all_nil, @name.byte_size)
|
|
294
|
-
|
|
295
|
-
assert_equal 4, t(@esme, @name.char_length)
|
|
296
|
-
assert_equal 5, t(@esme2, @name.char_length)
|
|
297
|
-
assert_equal 0, t(@all_nil, @name.char_length)
|
|
298
184
|
end
|
|
299
185
|
|
|
300
186
|
def test_md5
|
|
301
187
|
skip "Sqlite can't do md5" if $sqlite
|
|
302
|
-
assert_equal
|
|
303
|
-
assert_equal
|
|
304
|
-
assert_equal '6eb6a030bcce166534b95bc2ab45d9cf', t(@lucas, Arel.quoted('a' * 50).md5)
|
|
188
|
+
assert_equal "e2cf99ca82a7e829d2a4ac85c48154d0", t(@camille, @name.md5)
|
|
189
|
+
assert_equal "c3d41bf5efb468a1bcce53bd53726c85", t(@lucas, @name.md5)
|
|
305
190
|
end
|
|
306
191
|
|
|
307
192
|
def test_locate
|
|
308
193
|
skip "Sqlite version can't load extension for locate" if $sqlite && $load_extension_disabled
|
|
309
|
-
assert_equal 1, t(@camille, @name.locate(
|
|
310
|
-
assert_equal 0, t(@lucas, @name.locate(
|
|
311
|
-
assert_equal 5, t(@lucas, @name.locate(
|
|
194
|
+
assert_equal 1, t(@camille, @name.locate("C"))
|
|
195
|
+
assert_equal 0, t(@lucas, @name.locate("z"))
|
|
196
|
+
assert_equal 5, t(@lucas, @name.locate("s"))
|
|
312
197
|
end
|
|
313
198
|
|
|
314
199
|
def test_substring
|
|
@@ -318,7 +203,7 @@ module ArelExtensions
|
|
|
318
203
|
else
|
|
319
204
|
assert_equal('', t(@lucas, @name.substring(42)))
|
|
320
205
|
end
|
|
321
|
-
assert_equal 'Lu', t(@lucas, @name.substring(1,
|
|
206
|
+
assert_equal 'Lu', t(@lucas, @name.substring(1,2))
|
|
322
207
|
|
|
323
208
|
assert_equal 'C', t(@camille, @name[0, 1])
|
|
324
209
|
assert_equal 'C', t(@camille, @name[0])
|
|
@@ -327,117 +212,32 @@ module ArelExtensions
|
|
|
327
212
|
else
|
|
328
213
|
assert_equal('', t(@lucas, @name[42]))
|
|
329
214
|
end
|
|
215
|
+
assert_equal 'Lu', t(@lucas, @name[0,2])
|
|
216
|
+
assert_equal 'Lu', t(@lucas, @name[0..1])
|
|
330
217
|
|
|
331
|
-
#
|
|
218
|
+
#substring should accept string function
|
|
332
219
|
assert_equal 'Ce', t(@camille, @name.substring(1, 1).concat('e'))
|
|
333
|
-
assert_equal 'Ce', t(@camille, @name.substring(1, 1)
|
|
334
|
-
end
|
|
335
|
-
|
|
336
|
-
def assert_substring(expected, scope, node)
|
|
337
|
-
expected = nil if expected == '' && @env_db == 'oracle'
|
|
338
|
-
actual = t(scope, node)
|
|
339
|
-
# Ruby 3.0+ requires assert_nil
|
|
340
|
-
expected.nil? ? assert_nil(actual) : assert_equal(expected, actual)
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
def test_substring_range
|
|
344
|
-
# exclusive end
|
|
345
|
-
assert_substring 'uc', @lucas, @name[1...3]
|
|
346
|
-
assert_substring 'uca', @lucas, @name[1...-1]
|
|
347
|
-
|
|
348
|
-
# boundary: begin exactly at length is valid (empty result),
|
|
349
|
-
# begin one past length is out of range (nil)
|
|
350
|
-
assert_substring '', @lucas, @name[5..6]
|
|
351
|
-
assert_substring nil, @lucas, @name[6..7]
|
|
352
|
-
assert_substring nil, @lucas, @name[100..200]
|
|
353
|
-
assert_substring nil, @lucas, @name[-100..-1]
|
|
354
|
-
|
|
355
|
-
# reversed / empty-result ranges, same-sign and mixed-sign
|
|
356
|
-
assert_substring '', @lucas, @name[3..1]
|
|
357
|
-
assert_substring '', @lucas, @name[-3..1]
|
|
358
|
-
|
|
359
|
-
# singleton slices
|
|
360
|
-
assert_substring 'L', @lucas, @name[0..0]
|
|
361
|
-
assert_substring 's', @lucas, @name[4..4]
|
|
362
|
-
|
|
363
|
-
# a second fixture, sanity-checking against a longer string
|
|
364
|
-
assert_substring 'mil', @camille, @name[2..4]
|
|
365
|
-
assert_substring 'lle', @camille, @name[-3..-1]
|
|
366
|
-
|
|
367
|
-
# NULL column
|
|
368
|
-
assert_nil t(@all_nil, @name[0..2])
|
|
369
|
-
|
|
370
|
-
# trailing whitespace
|
|
371
|
-
assert_substring ' ', @esme2, @name[4..4]
|
|
372
|
-
assert_substring 'esmé ', @esme2, @name[0..-1]
|
|
373
|
-
|
|
374
|
-
# passing a Range and an explicit length together is contradictory.
|
|
375
|
-
assert_raises(ArgumentError) { @name.substring(1..2, 5) }
|
|
376
|
-
|
|
377
|
-
end
|
|
378
|
-
|
|
379
|
-
def endless_range_supported?
|
|
380
|
-
Range.new(0, nil)
|
|
381
|
-
true
|
|
382
|
-
rescue ArgumentError
|
|
383
|
-
false
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
def beginless_range_supported?
|
|
387
|
-
Range.new(nil, 0)
|
|
388
|
-
true
|
|
389
|
-
rescue ArgumentError
|
|
390
|
-
false
|
|
391
|
-
end
|
|
392
|
-
|
|
393
|
-
def test_substring_range_endless
|
|
394
|
-
skip 'endless ranges not supported on this interpreter' if !endless_range_supported?
|
|
395
|
-
|
|
396
|
-
assert_substring 'as', @lucas, @name[Range.new(-2, nil)]
|
|
397
|
-
assert_substring 'Lucas', @lucas, @name[Range.new(-5, nil)] # begin == -length: still in range
|
|
398
|
-
assert_substring nil, @lucas, @name[Range.new(-6, nil)] # begin == -length - 1: out of range
|
|
399
|
-
assert_substring nil, @lucas, @name[Range.new(-100, nil)]
|
|
400
|
-
|
|
401
|
-
assert_nil t(@all_nil, @name[Range.new(-2, nil)])
|
|
402
|
-
assert_substring ' ', @esme2, @name[Range.new(-1, nil)]
|
|
403
|
-
|
|
404
|
-
assert_substring 'as', @lucas, @name.substring(Range.new(-2, nil))
|
|
405
|
-
end
|
|
406
|
-
|
|
407
|
-
def test_substring_range_beginless
|
|
408
|
-
skip 'beginless ranges not supported on this interpreter' if !beginless_range_supported?
|
|
409
|
-
|
|
410
|
-
assert_substring 'Luc', @lucas, @name[Range.new(nil, 2)]
|
|
411
|
-
assert_substring 'Lucas', @lucas, @name[Range.new(nil, -1)]
|
|
412
|
-
assert_substring 'Luca', @lucas, @name[Range.new(nil, -2)]
|
|
413
|
-
|
|
414
|
-
assert_nil t(@all_nil, @name[Range.new(nil, 3)])
|
|
415
|
-
assert_substring 'esmé', @esme2, @name[Range.new(nil, 3)]
|
|
416
|
-
|
|
417
|
-
assert_substring 'Luc', @lucas, @name.substring(Range.new(nil, 2))
|
|
220
|
+
assert_equal 'Ce', t(@camille, @name.substring(1, 1)+'e')
|
|
418
221
|
end
|
|
419
222
|
|
|
420
223
|
def test_find_in_set
|
|
421
224
|
skip "Sqlite version can't load extension for find_in_set" if $sqlite && $load_extension_disabled
|
|
422
|
-
skip
|
|
225
|
+
skip "SQL Server does not know about FIND_IN_SET" if @env_db == 'mssql'
|
|
423
226
|
assert_equal 5, t(@neg, @comments & 2)
|
|
424
227
|
assert_equal 0, t(@neg, @comments & 6) # not found
|
|
425
|
-
assert_equal 5, t(@neg, @comments & '2')
|
|
426
|
-
assert_equal 0, t(@neg, @comments & '6') # not found
|
|
427
|
-
assert_equal 5, t(@neg, @comments & @other)
|
|
428
228
|
end
|
|
429
229
|
|
|
430
230
|
def test_string_comparators
|
|
431
|
-
#
|
|
231
|
+
#skip "Oracle can't use math operators to compare strings" if @env_db == 'oracle' # use GREATEST ?
|
|
432
232
|
skip "SQL Server can't use math operators to compare strings" if @env_db == 'mssql' # use GREATEST ?
|
|
433
233
|
if @env_db == 'postgresql' # may return real boolean
|
|
434
234
|
assert t(@neg, @name >= 'Mest') == true || t(@neg, @name >= 'Mest') == 't' # depends of ar version
|
|
435
235
|
assert t(@neg, @name <= (@name + 'Z')) == true || t(@neg, @name <= (@name + 'Z')) == 't'
|
|
436
236
|
elsif @env_db == 'oracle'
|
|
437
|
-
assert_equal 1, t(@neg,
|
|
438
|
-
assert_equal 1, t(@neg,
|
|
439
|
-
assert_equal 1, t(@neg,
|
|
440
|
-
assert_equal 1, t(@neg,
|
|
237
|
+
assert_equal 1, t(@neg, ArelExtensions::Nodes::Case.new.when(@name >= 'Mest').then(1).else(0))
|
|
238
|
+
assert_equal 1, t(@neg, ArelExtensions::Nodes::Case.new.when(@name <= (@name + 'Z')).then(1).else(0))
|
|
239
|
+
assert_equal 1, t(@neg, ArelExtensions::Nodes::Case.new.when(@name > 'Mest').then(1).else(0))
|
|
240
|
+
assert_equal 1, t(@neg, ArelExtensions::Nodes::Case.new.when(@name < (@name + 'Z')).then(1).else(0))
|
|
441
241
|
else
|
|
442
242
|
assert_equal 1, t(@neg, @name >= 'Mest')
|
|
443
243
|
assert_equal 1, t(@neg, @name <= (@name + 'Z'))
|
|
@@ -449,86 +249,69 @@ module ArelExtensions
|
|
|
449
249
|
def test_compare_on_date_time_types
|
|
450
250
|
skip "Sqlite can't compare time" if $sqlite
|
|
451
251
|
skip "Oracle can't compare time" if @env_db == 'oracle'
|
|
452
|
-
|
|
453
|
-
assert_includes [true,
|
|
454
|
-
assert_includes [false,
|
|
455
|
-
|
|
456
|
-
assert_includes [true,
|
|
457
|
-
assert_includes [false,
|
|
458
|
-
|
|
459
|
-
#
|
|
460
|
-
#
|
|
461
|
-
assert_includes [true,
|
|
462
|
-
assert_includes [false,
|
|
252
|
+
#@created_at == 2016-05-23
|
|
253
|
+
assert_includes [true,'t',1], t(@laure, ArelExtensions::Nodes::Case.new.when(@created_at >= '2014-01-01').then(1).else(0))
|
|
254
|
+
assert_includes [false,'f',0], t(@laure, ArelExtensions::Nodes::Case.new.when(@created_at >= '2018-01-01').then(1).else(0))
|
|
255
|
+
#@updated_at == 2014-03-03 12:42:00
|
|
256
|
+
assert_includes [true,'t',1], t(@laure, ArelExtensions::Nodes::Case.new.when(@updated_at >= '2014-03-03 10:10:10').then(1).else(0))
|
|
257
|
+
assert_includes [false,'f',0], t(@laure, ArelExtensions::Nodes::Case.new.when(@updated_at >= '2014-03-03 13:10:10').then(1).else(0))
|
|
258
|
+
#@duration == 12:42:21
|
|
259
|
+
#puts @laure.select(ArelExtensions::Nodes::Case.new.when(@duration >= '10:10:10').then(1).else(0)).to_sql
|
|
260
|
+
#puts @laure.select(ArelExtensions::Nodes::Case.new.when(@duration >= '14:10:10').then(1).else(0)).to_sql
|
|
261
|
+
assert_includes [true,'t',1], t(@laure, ArelExtensions::Nodes::Case.new.when(@duration >= '10:10:10').then(1).else(0))
|
|
262
|
+
assert_includes [false,'f',0], t(@laure, ArelExtensions::Nodes::Case.new.when(@duration >= '14:10:10').then(1).else(0))
|
|
463
263
|
end
|
|
464
264
|
|
|
265
|
+
|
|
465
266
|
def test_regexp_not_regexp
|
|
466
267
|
skip "Sqlite version can't load extension for regexp" if $sqlite && $load_extension_disabled
|
|
467
|
-
skip
|
|
268
|
+
skip "SQL Server does not know about REGEXP without extensions" if @env_db == 'mssql'
|
|
468
269
|
assert_equal 1, User.where(@name =~ '^M').count
|
|
469
|
-
assert_equal
|
|
270
|
+
assert_equal 6, User.where(@name !~ '^L').count
|
|
470
271
|
assert_equal 1, User.where(@name =~ /^M/).count
|
|
471
|
-
assert_equal
|
|
472
|
-
end
|
|
473
|
-
|
|
474
|
-
def test_regex_matches
|
|
475
|
-
skip "Sqlite version can't load extension for regexp" if $sqlite && $load_extension_disabled
|
|
476
|
-
skip 'SQL Server does not know about REGEXP without extensions' if @env_db == 'mssql'
|
|
477
|
-
assert_equal 1, User.where(@name.regex_matches '^M').count
|
|
478
|
-
assert_equal 1, User.where(@name.regex_matches /^M/).count
|
|
272
|
+
assert_equal 6, User.where(@name !~ /^L/).count
|
|
479
273
|
end
|
|
480
274
|
|
|
481
275
|
def test_imatches
|
|
482
|
-
#
|
|
276
|
+
#puts User.where(@name.imatches('m%')).to_sql
|
|
483
277
|
assert_equal 1, User.where(@name.imatches('m%')).count
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
else
|
|
487
|
-
assert_equal 4, User.where(@name.imatches_any(['L%', '%e'])).count
|
|
488
|
-
end
|
|
489
|
-
assert_equal 10, User.where(@name.idoes_not_match('L%')).count
|
|
278
|
+
assert_equal 4, User.where(@name.imatches_any(['L%', '%e'])).count
|
|
279
|
+
assert_equal 6, User.where(@name.idoes_not_match('L%')).count
|
|
490
280
|
end
|
|
491
281
|
|
|
492
282
|
def test_replace
|
|
493
|
-
assert_equal
|
|
494
|
-
assert_equal
|
|
495
|
-
|
|
496
|
-
skip 'Sqlite does not seem to support regexp_replace' if $sqlite
|
|
497
|
-
skip 'SQL Server does not know about REGEXP without extensions' if @env_db == 'mssql'
|
|
498
|
-
skip 'Travis mysql version does not support REGEXP_REPLACE' if @env_db == 'mysql'
|
|
499
|
-
assert_equal 'LXcXs', t(@lucas, @name.replace(/[ua]/, 'X'))
|
|
500
|
-
assert_equal 'LXcXs', t(@lucas, @name.regexp_replace(/[ua]/, 'X'))
|
|
501
|
-
assert_equal 'LXcXs', t(@lucas, @name.regexp_replace('[ua]', 'X'))
|
|
283
|
+
assert_equal "LucaX", t(@lucas, @name.replace("s", "X"))
|
|
284
|
+
assert_equal "replace", t(@lucas, @name.replace(@name, "replace"))
|
|
502
285
|
end
|
|
503
286
|
|
|
504
287
|
def test_replace_once
|
|
505
|
-
skip
|
|
506
|
-
#
|
|
507
|
-
assert_equal
|
|
288
|
+
skip "TODO"
|
|
289
|
+
#skip "Sqlite version can't load extension for locate" if $sqlite && $load_extension_disabled
|
|
290
|
+
assert_equal "LuCas", t(@lucas, @name.substring(1, @name.locate('c') - 1) + 'C' + @name.substring(@name.locate('c') + 1, @name.length))
|
|
508
291
|
end
|
|
509
292
|
|
|
510
293
|
def test_soundex
|
|
511
294
|
skip "Sqlite version can't load extension for soundex" if $sqlite && $load_extension_disabled
|
|
512
295
|
skip "PostgreSql version can't load extension for soundex" if @env_db == 'postgresql'
|
|
513
|
-
assert_equal
|
|
514
|
-
assert_equal
|
|
515
|
-
assert_equal
|
|
296
|
+
assert_equal "C540", t(@camille, @name.soundex)
|
|
297
|
+
assert_equal 8, User.where(@name.soundex.eq(@name.soundex)).count
|
|
298
|
+
assert_equal 8, User.where(@name.soundex == @name.soundex).count
|
|
516
299
|
end
|
|
517
300
|
|
|
518
301
|
def test_change_case
|
|
519
|
-
assert_equal
|
|
520
|
-
assert_equal
|
|
521
|
-
assert_equal
|
|
302
|
+
assert_equal "myung", t(@myung, @name.downcase)
|
|
303
|
+
assert_equal "MYUNG", t(@myung, @name.upcase)
|
|
304
|
+
assert_equal "myung", t(@myung, @name.upcase.downcase)
|
|
522
305
|
end
|
|
523
306
|
|
|
524
307
|
def test_trim
|
|
525
|
-
assert_equal
|
|
526
|
-
assert_equal
|
|
527
|
-
assert_equal
|
|
528
|
-
assert_equal
|
|
529
|
-
assert_equal
|
|
530
|
-
skip
|
|
531
|
-
assert_equal
|
|
308
|
+
assert_equal "Myung", t(@myung, @name.trim)
|
|
309
|
+
assert_equal "Myung", t(@myung, @name.trim.ltrim.rtrim)
|
|
310
|
+
assert_equal "Myun", t(@myung, @name.rtrim("g"))
|
|
311
|
+
assert_equal "yung", t(@myung, @name.ltrim("M"))
|
|
312
|
+
assert_equal "yung", t(@myung, (@name + "M").trim("M"))
|
|
313
|
+
skip "Oracle does not accept multi char trim" if @env_db == 'oracle'
|
|
314
|
+
assert_equal "", t(@myung, @name.rtrim(@name))
|
|
532
315
|
end
|
|
533
316
|
|
|
534
317
|
def test_blank
|
|
@@ -557,244 +340,32 @@ module ArelExtensions
|
|
|
557
340
|
assert_equal 'true', t(@neg, @comments.not_blank.then('true', 'false'))
|
|
558
341
|
end
|
|
559
342
|
|
|
560
|
-
# This test repeats a lot of `test_blank` cases.
|
|
561
|
-
def test_present
|
|
562
|
-
if @env_db == 'postgresql'
|
|
563
|
-
assert_includes [true, 't'], t(@myung, @name.present) # depends of adapter
|
|
564
|
-
assert_includes [false, 'f'], t(@myung, @comments.present)
|
|
565
|
-
end
|
|
566
|
-
assert_equal 1, @myung.where(@name.present).count
|
|
567
|
-
assert_equal 0, @myung.where(@comments.present).count
|
|
568
|
-
assert_equal 0, @sophie.where(@comments.present).count
|
|
569
|
-
assert_equal 0, @camille.where(@comments.present).count
|
|
570
|
-
|
|
571
|
-
assert_equal 1, @neg.where(@comments.present).count
|
|
572
|
-
assert_equal 'true', t(@myung, @name.present.then('true', 'false'))
|
|
573
|
-
assert_equal 'false', t(@myung, @comments.present.then('true', 'false'))
|
|
574
|
-
assert_equal 'true', t(@neg, @comments.present.then('true', 'false'))
|
|
575
|
-
end
|
|
576
|
-
|
|
577
343
|
def test_format
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
assert_equal '12:42%', t(@lucas, @updated_at.send(method, '%R%%'))
|
|
582
|
-
|
|
583
|
-
# The following tests will ensure proper conversion of timestamps to
|
|
584
|
-
# requested timezones.
|
|
585
|
-
#
|
|
586
|
-
# The names of the timezones is highly dependant on the underlying
|
|
587
|
-
# operating system, and this is why we need to handle each database
|
|
588
|
-
# separately: the images we're using to test these databases are
|
|
589
|
-
# different. So don't rely on the provided examples. Your setup is your
|
|
590
|
-
# reference.
|
|
591
|
-
#
|
|
592
|
-
# One could always have portable code if s/he uses standard
|
|
593
|
-
# abbreviations, like:
|
|
594
|
-
#
|
|
595
|
-
# 1. CET => Central European Time
|
|
596
|
-
# 2. CEST => Central European Summer Time
|
|
597
|
-
#
|
|
598
|
-
# Which implies that the caller should handle daylight saving detection.
|
|
599
|
-
# In fact, CET will handle daylight saving in MySQL but not Postgres.
|
|
600
|
-
#
|
|
601
|
-
# It looks like the posix convention is supported by mysql and
|
|
602
|
-
# postgresql, e.g.:
|
|
603
|
-
#
|
|
604
|
-
# posix/Europe/Paris
|
|
605
|
-
# posix/America/Nipigon
|
|
606
|
-
#
|
|
607
|
-
# so it looks like a more reliably portable way of specifying it.
|
|
608
|
-
time_zones = {
|
|
609
|
-
'mssql' => {
|
|
610
|
-
'utc' => 'UTC',
|
|
611
|
-
'sao_paulo' => 'Argentina Standard Time',
|
|
612
|
-
'tahiti' => 'Hawaiian Standard Time',
|
|
613
|
-
'paris' => 'Central European Standard Time'
|
|
614
|
-
},
|
|
615
|
-
'posix' => {
|
|
616
|
-
'utc' => 'UTC',
|
|
617
|
-
'sao_paulo' => 'America/Sao_Paulo',
|
|
618
|
-
'tahiti' => 'Pacific/Tahiti',
|
|
619
|
-
'paris' => 'Europe/Paris'
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
skip "Unsupported timezone conversion for DB=#{ENV['DB']}" if !%w[mssql mysql oracle postgresql].include?(ENV['DB'])
|
|
624
|
-
# TODO: Standarize timezone conversion across all databases.
|
|
625
|
-
# This test case will be refactored and should work the same across all vendors.
|
|
626
|
-
if ENV['DB'] == 'mssql' && /Microsoft SQL Server (\d+)/.match(ActiveRecord::Base.connection.select_value('SELECT @@version'))[1].to_i < 2016
|
|
627
|
-
skip 'SQL Server < 2016 is not currently supported'
|
|
628
|
-
end
|
|
629
|
-
|
|
630
|
-
tz = ENV['DB'] == 'mssql' ? time_zones['mssql'] : time_zones['posix']
|
|
631
|
-
|
|
632
|
-
assert_equal '2014/03/03 12:42:00', t(@lucas, @updated_at.send(method, '%Y/%m/%d %H:%M:%S', tz['utc']))
|
|
633
|
-
assert_equal '2014/03/03 09:42:00', t(@lucas, @updated_at.send(method, '%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['sao_paulo']}))
|
|
634
|
-
assert_equal '2014/03/03 02:42:00', t(@lucas, @updated_at.send(method, '%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['tahiti']}))
|
|
635
|
-
|
|
636
|
-
# Skipping conversion from UTC to the desired timezones fails in SQL
|
|
637
|
-
# Server and Postgres. This is mainly due to the fact that timezone
|
|
638
|
-
# information is not preserved in the column itself.
|
|
639
|
-
#
|
|
640
|
-
# MySQL is happy to consider that times by default are in UTC.
|
|
641
|
-
assert_equal '2014/03/03 13:42:00', t(@lucas, @updated_at.send(method, '%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
|
|
642
|
-
refute_equal '2014/03/03 13:42:00', t(@lucas, @updated_at.send(method, '%Y/%m/%d %H:%M:%S', tz['paris'])) if !%w[mysql postgresql].include?(ENV['DB'])
|
|
643
|
-
|
|
644
|
-
# Winter/Summer time
|
|
645
|
-
assert_equal '2014/08/03 14:42:00', t(@lucas, (@updated_at + 5.months).send(method, '%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
|
|
646
|
-
if ENV['DB'] == 'mssql'
|
|
647
|
-
assert_equal '2022/02/01 11:42:00', t(@lucas, Arel.quoted('2022-02-01 10:42:00').cast(:datetime).send(method, '%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
|
|
648
|
-
assert_equal '2022/08/01 12:42:00', t(@lucas, Arel.quoted('2022-08-01 10:42:00').cast(:datetime).send(method, '%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
|
|
649
|
-
else
|
|
650
|
-
assert_equal '2022/02/01 11:42:00', t(@lucas, Arel.quoted('2022-02-01 10:42:00').cast(:datetime).send(method, '%Y/%m/%d %H:%M:%S', tz['paris']))
|
|
651
|
-
assert_equal '2022/08/01 12:42:00', t(@lucas, Arel.quoted('2022-08-01 10:42:00').cast(:datetime).send(method, '%Y/%m/%d %H:%M:%S', tz['paris']))
|
|
652
|
-
end
|
|
653
|
-
end
|
|
654
|
-
end
|
|
655
|
-
|
|
656
|
-
def test_format_iso_week
|
|
657
|
-
%i[format format_date].each do |method|
|
|
658
|
-
skip "Unsupported ISO week number for DB=#{ENV['DB']}" if ['sqlite'].include?(ENV['DB'])
|
|
659
|
-
assert_equal '10', t(@lucas, @updated_at.send(method, '%V'))
|
|
660
|
-
{
|
|
661
|
-
'2024-01-01 10:42:00' => '01', # Monday
|
|
662
|
-
'2030-01-01 10:42:00' => '01', # Tuesday
|
|
663
|
-
'2025-01-01 10:42:00' => '01', # Wednesday
|
|
664
|
-
'2026-01-01 10:42:00' => '01', # Thursday
|
|
665
|
-
'2027-01-01 10:42:00' => '53', # Friday
|
|
666
|
-
'2028-01-01 10:42:00' => '52', # Saturday
|
|
667
|
-
'2034-01-01 10:42:00' => '52', # Sunday
|
|
668
|
-
}.each do |date, exp|
|
|
669
|
-
assert_equal exp, t(@lucas, Arel.quoted(date).cast(:datetime).send(method, '%V'))
|
|
670
|
-
end
|
|
671
|
-
end
|
|
672
|
-
end
|
|
673
|
-
|
|
674
|
-
def test_format_iso_year_of_week
|
|
675
|
-
skip "Unsupported ISO year of week for DB=#{ENV['DB']}" if %w[mssql sqlite].include?(ENV['DB'])
|
|
676
|
-
%i[format format_date].each do |method|
|
|
677
|
-
assert_equal '2014', t(@lucas, @updated_at.send(method, '%G'))
|
|
678
|
-
|
|
679
|
-
{
|
|
680
|
-
'2024-01-01 10:42:00' => '2024', # Monday
|
|
681
|
-
'2030-01-01 10:42:00' => '2030', # Tuesday
|
|
682
|
-
'2025-01-01 10:42:00' => '2025', # Wednesday
|
|
683
|
-
'2026-01-01 10:42:00' => '2026', # Thursday
|
|
684
|
-
'2027-01-01 10:42:00' => '2026', # Friday
|
|
685
|
-
'2028-01-01 10:42:00' => '2027', # Saturday
|
|
686
|
-
'2034-01-01 10:42:00' => '2033', # Sunday
|
|
687
|
-
}.each do |date, exp|
|
|
688
|
-
assert_equal exp, t(@lucas, Arel.quoted(date).cast(:datetime).send(method, '%G'))
|
|
689
|
-
end
|
|
690
|
-
end
|
|
691
|
-
end
|
|
692
|
-
|
|
693
|
-
def test_format_date_with_names
|
|
694
|
-
skip "#{ENV['DB']} does not support a variety of word-based formatting for month and day names" if %w[mssql sqlite].include?(ENV['DB'])
|
|
695
|
-
%i[format format_date].each do |method|
|
|
696
|
-
assert_equal 'Mon, 03 Mar 14', t(@lucas, @updated_at.send(method, '%a, %d %b %y'))
|
|
697
|
-
assert_equal 'Monday, 03 March 14', t(@lucas, @updated_at.send(method, '%A, %d %B %y'))
|
|
698
|
-
end
|
|
699
|
-
|
|
700
|
-
skip "#{ENV['DB']} does not support ALLCAPS month and day names" if ['mysql'].include?(ENV['DB'])
|
|
701
|
-
%i[format format_date].each do |method|
|
|
702
|
-
|
|
703
|
-
assert_equal 'Mon, 03 MAR 14', t(@lucas, @updated_at.send(method, '%a, %d %^b %y'))
|
|
704
|
-
assert_equal 'Monday, 03 MARCH 14', t(@lucas, @updated_at.send(method, '%A, %d %^B %y'))
|
|
705
|
-
end
|
|
706
|
-
end
|
|
707
|
-
|
|
708
|
-
def switch_to_lang(lang)
|
|
709
|
-
languages = {
|
|
710
|
-
'mssql' => {en: 'English', fr: 'French'},
|
|
711
|
-
'mysql' => {en: 'en_US', fr: 'fr_FR'},
|
|
712
|
-
'postgresql' => {en: 'en_US.utf8', fr: 'fr_FR.utf8'}
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
sql = {
|
|
716
|
-
'mssql' => ->(l) { "SET LANGUAGE #{l};" },
|
|
717
|
-
'mysql' => ->(l) { "SET lc_time_names = '#{l}';" },
|
|
718
|
-
'postgresql' => ->(l) { "SET lc_time to '#{l}';" }
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
User.connection.execute(sql[ENV['DB']][languages[ENV['DB']][lang]])
|
|
722
|
-
end
|
|
723
|
-
|
|
724
|
-
def test_format_date_with_names_and_lang_switch
|
|
725
|
-
skip "#{ENV['DB']} does not support word-based formatting for month and day names" if ['sqlite'].include?(ENV['DB'])
|
|
726
|
-
|
|
727
|
-
# the begin-rescue block is here to make sure we set the db back to en_US
|
|
728
|
-
# if we fail, so that other tests don't get contaminated.
|
|
729
|
-
#
|
|
730
|
-
# Tests should assert one single thing in principle, but until we
|
|
731
|
-
# refactor this whole thing, we'll have to do tricks of this sort.
|
|
732
|
-
%i[format format_date].each do |method|
|
|
733
|
-
begin
|
|
734
|
-
switch_to_lang(:en)
|
|
735
|
-
case ENV['DB']
|
|
736
|
-
when 'mysql', 'postgresql'
|
|
737
|
-
assert_equal 'Mon, 03 Mar 14', t(@lucas, @updated_at.send(method, '%a, %d %b %y'))
|
|
738
|
-
assert_equal 'Monday, 03 March 14', t(@lucas, @updated_at.send(method, '%A, %d %B %y'))
|
|
739
|
-
when 'mssql'
|
|
740
|
-
assert_equal 'Monday, 03 March 2014', t(@lucas, @updated_at.send(method, '%A, %d %B %y'))
|
|
741
|
-
end
|
|
742
|
-
switch_to_lang(:fr)
|
|
743
|
-
case ENV['DB']
|
|
744
|
-
when 'mysql'
|
|
745
|
-
assert_equal 'lun, 03 mar 14', t(@lucas, @updated_at.send(method, '%a, %d %b %y'))
|
|
746
|
-
assert_equal 'lundi, 03 mars 14', t(@lucas, @updated_at.send(method, '%A, %d %B %y'))
|
|
747
|
-
when 'postgresql'
|
|
748
|
-
assert_equal 'Lun., 03 Mars 14', t(@lucas, @updated_at.send(method, '%a, %d %b %y'))
|
|
749
|
-
assert_equal 'Lundi, 03 Mars 14', t(@lucas, @updated_at.send(method, '%A, %d %B %y'))
|
|
750
|
-
when 'mssql'
|
|
751
|
-
assert_equal 'lundi, 03 mars 2014', t(@lucas, @updated_at.send(method, '%A, %d %B %y'))
|
|
752
|
-
end
|
|
753
|
-
ensure
|
|
754
|
-
switch_to_lang(:en)
|
|
755
|
-
end
|
|
756
|
-
end
|
|
344
|
+
assert_equal '2016-05-23', t(@lucas, @created_at.format('%Y-%m-%d'))
|
|
345
|
+
skip "SQL Server does not accept any format" if @env_db == 'mssql'
|
|
346
|
+
assert_equal '2014/03/03 12:42:00', t(@lucas, @updated_at.format('%Y/%m/%d %H:%M:%S'))
|
|
757
347
|
end
|
|
758
348
|
|
|
759
349
|
def test_coalesce
|
|
760
|
-
assert_equal 'Camille concat', t(@camille, @name.coalesce(nil,
|
|
350
|
+
assert_equal 'Camille concat', t(@camille, @name.coalesce(nil, "default") + ' concat')
|
|
761
351
|
|
|
762
|
-
assert_equal 'toto', t(@test, @other.coalesce(
|
|
352
|
+
assert_equal 'toto', t(@test, @other.coalesce(""))
|
|
763
353
|
|
|
764
|
-
assert_equal ' ', t(@myung, @comments.coalesce(
|
|
765
|
-
assert_equal 'Laure', t(@laure, @comments.coalesce(
|
|
354
|
+
assert_equal ' ', t(@myung, @comments.coalesce("Myung").coalesce('ignored'))
|
|
355
|
+
assert_equal 'Laure', t(@laure, @comments.coalesce("Laure"))
|
|
766
356
|
if @env_db == 'oracle'
|
|
767
|
-
assert_nil t(@laure, @comments.coalesce(
|
|
768
|
-
assert_nil t(@camille, @other.coalesce(
|
|
357
|
+
assert_nil t(@laure, @comments.coalesce(""))
|
|
358
|
+
assert_nil t(@camille, @other.coalesce(""))
|
|
769
359
|
else
|
|
770
|
-
assert_equal('', t(@laure, @comments.coalesce(
|
|
771
|
-
assert_equal '', t(@camille, @other.coalesce(
|
|
360
|
+
assert_equal('', t(@laure, @comments.coalesce("")))
|
|
361
|
+
assert_equal '', t(@camille, @other.coalesce(""))
|
|
772
362
|
end
|
|
773
363
|
assert_equal 100, t(@test, @age.coalesce(100))
|
|
774
|
-
assert_equal
|
|
364
|
+
assert_equal "Camille", t(@camille, @name.coalesce(nil, "default"))
|
|
775
365
|
assert_equal 20, t(@test, @age.coalesce(nil, 20))
|
|
776
366
|
|
|
777
|
-
assert_equal 20, t(@test, @age.coalesce(10)
|
|
778
|
-
assert_equal 'Laure10', t(@laure, @comments.coalesce(
|
|
779
|
-
end
|
|
780
|
-
|
|
781
|
-
def test_coalesce_blank
|
|
782
|
-
assert_equal 'Myung', t(@myung, @comments.coalesce_blank('Myung').coalesce_blank('ignored'))
|
|
783
|
-
assert_equal 'Myung', t(@myung, @comments.coalesce_blank('', ' ', ' ').coalesce_blank('Myung'))
|
|
784
|
-
assert_equal 'Myung', t(@myung, @comments.coalesce_blank('', ' ', ' ', 'Myung'))
|
|
785
|
-
assert_equal '2016-05-23', t(@myung, @created_at.coalesce_blank(Date.new(2022, 1, 1)).format('%Y-%m-%d'))
|
|
786
|
-
assert_equal '2016-05-23', t(@myung, @created_at.coalesce_blank(Date.new(2022, 1, 1)).format_date('%Y-%m-%d'))
|
|
787
|
-
assert_equal 'Laure', t(@laure, @comments.coalesce_blank('Laure'))
|
|
788
|
-
assert_equal 100, t(@test, @age.coalesce_blank(100))
|
|
789
|
-
assert_equal 20, t(@test, @age.coalesce_blank(20))
|
|
790
|
-
assert_equal 20, t(@test, @age.coalesce_blank(10) + 10)
|
|
791
|
-
assert_equal 'Laure10', t(@laure, @comments.coalesce_blank('Laure') + 10)
|
|
792
|
-
|
|
793
|
-
skip 'mssql does not support null in case results' if @env_db == 'mssql'
|
|
794
|
-
|
|
795
|
-
assert_equal 'Camille concat', t(@camille, @name.coalesce_blank(Arel.null, 'default') + ' concat')
|
|
796
|
-
assert_equal 'Myung', t(@myung, @comments.coalesce_blank(Arel.null, 'Myung'))
|
|
797
|
-
assert_equal 'Camille', t(@camille, @name.coalesce_blank(Arel.null, 'default'))
|
|
367
|
+
assert_equal 20, t(@test, @age.coalesce(10)+10)
|
|
368
|
+
assert_equal 'Laure10', t(@laure, @comments.coalesce("Laure") + 10)
|
|
798
369
|
end
|
|
799
370
|
|
|
800
371
|
# Comparators
|
|
@@ -803,46 +374,37 @@ module ArelExtensions
|
|
|
803
374
|
assert_equal 2, User.where(@age <= 10).count
|
|
804
375
|
assert_equal 3, User.where(@age > 20).count
|
|
805
376
|
assert_equal 4, User.where(@age >= 20).count
|
|
806
|
-
assert_equal
|
|
377
|
+
assert_equal 1, User.where(@age > 5).where(@age < 20).count
|
|
807
378
|
end
|
|
808
379
|
|
|
809
380
|
def test_date_comparator
|
|
810
381
|
d = Date.new(2016, 5, 23)
|
|
811
382
|
assert_equal 0, User.where(@created_at < d).count
|
|
812
|
-
assert_equal
|
|
383
|
+
assert_equal 8, User.where(@created_at >= d).count
|
|
813
384
|
end
|
|
814
385
|
|
|
815
386
|
def test_date_duration
|
|
816
|
-
#
|
|
817
|
-
# activerecord will give it the current date.
|
|
818
|
-
#
|
|
819
|
-
# So depending on the month when we run this test, we will get different
|
|
820
|
-
# results for `User.where(@created_at.month.eq('05'))`.
|
|
821
|
-
count_for_may = Date.today.month == 5 ? 10 : 9
|
|
822
|
-
count_for_day = Date.today.day == 5 ? 1 : 0
|
|
823
|
-
|
|
824
|
-
# Year
|
|
387
|
+
#Year
|
|
825
388
|
assert_equal 2016, t(@lucas, @created_at.year).to_i
|
|
826
|
-
assert_equal 0, User.where(@created_at.year.eq(
|
|
827
|
-
#
|
|
389
|
+
assert_equal 0, User.where(@created_at.year.eq("2012")).count
|
|
390
|
+
#Month
|
|
828
391
|
assert_equal 5, t(@camille, @created_at.month).to_i
|
|
829
|
-
assert_equal
|
|
830
|
-
#
|
|
392
|
+
assert_equal 8, User.where(@created_at.month.eq("05")).count
|
|
393
|
+
#Week
|
|
831
394
|
assert_equal(@env_db == 'mssql' ? 22 : 21, t(@arthur, @created_at.week).to_i)
|
|
832
|
-
assert_equal
|
|
833
|
-
#
|
|
395
|
+
assert_equal 8, User.where(@created_at.month.eq("05")).count
|
|
396
|
+
#Day
|
|
834
397
|
assert_equal 23, t(@laure, @created_at.day).to_i
|
|
835
|
-
|
|
836
|
-
assert_equal count_for_day, User.where(@created_at.day.eq('05')).count
|
|
398
|
+
assert_equal 0, User.where(@created_at.day.eq("05")).count
|
|
837
399
|
|
|
838
|
-
#
|
|
839
|
-
#
|
|
400
|
+
#skip "manage DATE" if @env_db == 'oracle'
|
|
401
|
+
#Hour
|
|
840
402
|
assert_equal 0, t(@laure, @created_at.hour).to_i
|
|
841
403
|
assert_equal 12, t(@lucas, @updated_at.hour).to_i
|
|
842
|
-
#
|
|
404
|
+
#Minute
|
|
843
405
|
assert_equal 0, t(@laure, @created_at.minute).to_i
|
|
844
406
|
assert_equal 42, t(@lucas, @updated_at.minute).to_i
|
|
845
|
-
#
|
|
407
|
+
#Second
|
|
846
408
|
assert_equal 0, t(@laure, @created_at.second).to_i
|
|
847
409
|
assert_equal 0, t(@lucas, @updated_at.second).to_i
|
|
848
410
|
end
|
|
@@ -850,8 +412,8 @@ module ArelExtensions
|
|
|
850
412
|
def test_datetime_diff
|
|
851
413
|
assert_equal 0, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 12, 42)).to_i
|
|
852
414
|
if @env_db == 'oracle' && Arel::VERSION.to_i > 6 # in rails 5, result is multiplied by 24*60*60 = 86400...
|
|
853
|
-
assert_equal 42 *
|
|
854
|
-
assert_equal(-3600 *
|
|
415
|
+
assert_equal 42 * 86400, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 12, 41, 18)).to_i
|
|
416
|
+
assert_equal(-3600 * 86400, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 13, 42)).to_i)
|
|
855
417
|
else
|
|
856
418
|
assert_equal 42, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 12, 41, 18)).to_i
|
|
857
419
|
assert_equal(-3600, t(@lucas, @updated_at - Time.utc(2014, 3, 3, 13, 42)).to_i)
|
|
@@ -862,8 +424,7 @@ module ArelExtensions
|
|
|
862
424
|
end
|
|
863
425
|
end
|
|
864
426
|
|
|
865
|
-
|
|
866
|
-
skip 'not yet implemented' if $sqlite
|
|
427
|
+
skip "not yet implemented" if $sqlite
|
|
867
428
|
|
|
868
429
|
date1 = Date.new(2016, 5, 23)
|
|
869
430
|
durPos = 10.years
|
|
@@ -875,135 +436,106 @@ module ArelExtensions
|
|
|
875
436
|
|
|
876
437
|
datetime1 = Time.utc(2014, 3, 3, 12, 42, 0)
|
|
877
438
|
# Pull Request #5 tests
|
|
878
|
-
#
|
|
879
|
-
assert_includes [date2,
|
|
880
|
-
assert_includes [date3,
|
|
439
|
+
#puts (@created_at + durPos).cast(:date).to_sql
|
|
440
|
+
assert_includes [date2,"2026-05-23"], t(@test,(@created_at + durPos).cast(:date))
|
|
441
|
+
assert_includes [date3,"2006-05-23"], t(@test,(@created_at + durNeg).cast(:date))
|
|
881
442
|
|
|
882
|
-
#
|
|
883
|
-
assert_includes [date4,
|
|
884
|
-
#
|
|
885
|
-
assert_includes [date5,
|
|
443
|
+
#puts (@created_at + @created_at.day).cast(:date).to_sql
|
|
444
|
+
assert_includes [date4,"2016-06-15"], t(@test,(@created_at + @created_at.day).cast(:date))
|
|
445
|
+
#puts (@created_at - @created_at.day).cast(:date).to_sql
|
|
446
|
+
assert_includes [date5,"2016-04-30"], t(@test,(@created_at - @created_at.day).cast(:date))
|
|
886
447
|
|
|
887
|
-
assert_includes [datetime1 + 42.seconds,
|
|
888
|
-
assert_includes [datetime1 - 42.seconds,
|
|
448
|
+
assert_includes [datetime1 + 42.seconds,"2014-03-03 12:42:42 UTC"], t(@lucas,(@updated_at + @updated_at.minute))
|
|
449
|
+
assert_includes [datetime1 - 42.seconds,"2014-03-03 12:41:18 UTC"], t(@lucas,(@updated_at - @updated_at.minute))
|
|
889
450
|
|
|
890
451
|
# (@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))).to_sql
|
|
891
|
-
assert_includes [datetime1 + (12
|
|
892
|
-
|
|
452
|
+
assert_includes [datetime1 + (12*60+42).seconds,"2014-03-03 12:54:42 UTC"],
|
|
453
|
+
t(@lucas,(@updated_at + Arel.duration('s',(@updated_at.hour*60 + @updated_at.minute))))
|
|
893
454
|
|
|
894
|
-
assert_includes [datetime1 + (12
|
|
895
|
-
|
|
455
|
+
assert_includes [datetime1 + (12*60+42).minutes,"2014-03-04 01:24:00 UTC"],
|
|
456
|
+
t(@lucas,(@updated_at + Arel.duration('mn',(@updated_at.hour*60 + @updated_at.minute))))
|
|
896
457
|
|
|
897
|
-
assert_includes [
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
assert_includes ['2004-03-03'], t(@lucas, (@updated_at - durPos).format('%Y-%m-%d'))
|
|
901
|
-
assert_includes ['2004-03-03'], t(@lucas, (@updated_at - durPos).format_date('%Y-%m-%d'))
|
|
458
|
+
assert_includes ["2024-03-03"], t(@lucas,(@updated_at + durPos).format('%Y-%m-%d'))
|
|
459
|
+
#puts (@updated_at - durPos).to_sql
|
|
460
|
+
assert_includes ["2004-03-03"], t(@lucas,(@updated_at - durPos).format('%Y-%m-%d'))
|
|
902
461
|
|
|
903
462
|
|
|
904
463
|
# we test with the ruby object or the string because some adapters don't return an object Date
|
|
905
|
-
|
|
464
|
+
# end
|
|
906
465
|
end
|
|
907
466
|
|
|
908
467
|
# TODO; cast types
|
|
909
468
|
def test_cast_types
|
|
910
|
-
assert_equal
|
|
911
|
-
assert_equal 'a' * 50, t(@lucas, Arel.quoted('a' * 50).cast(:string))
|
|
912
|
-
skip 'jdbc adapters does not work properly here (v52 works fine)' if RUBY_PLATFORM.match?(/java/i)
|
|
469
|
+
assert_equal "5", t(@lucas, @age.cast(:string))
|
|
913
470
|
if @env_db == 'mysql' || @env_db == 'postgresql' || @env_db == 'oracle' || @env_db == 'mssql'
|
|
914
|
-
assert_equal 1, t(@laure,
|
|
915
|
-
assert_equal 1, t(@laure,
|
|
916
|
-
assert_equal
|
|
917
|
-
assert_equal
|
|
918
|
-
assert_equal 21.16, t(@laure
|
|
919
|
-
assert_equal 21, t(@laure
|
|
920
|
-
|
|
921
|
-
assert_equal String, t(@lucas
|
|
922
|
-
|
|
923
|
-
assert_equal
|
|
924
|
-
assert_equal Time, t(@lucas
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
assert_equal
|
|
929
|
-
assert_equal
|
|
930
|
-
assert_equal Date.parse(
|
|
931
|
-
assert_equal
|
|
932
|
-
assert_equal Date.parse('2014-03-03'), t(@lucas, @updated_at.cast(:date))
|
|
933
|
-
assert_equal '12:42:00', t(@lucas, @updated_at.cast(:time).cast(:string)).split('.').first unless @env_db == 'oracle' # DateTime
|
|
934
|
-
end
|
|
935
|
-
end
|
|
936
|
-
|
|
937
|
-
def test_if_present
|
|
938
|
-
assert_nil t(@myung, @comments.if_present)
|
|
939
|
-
assert_equal 0, t(@myung, @comments.if_present.count)
|
|
940
|
-
assert_equal 20.16, t(@myung, @score.if_present)
|
|
941
|
-
assert_equal '2016-05-23', t(@myung, @created_at.if_present.format('%Y-%m-%d'))
|
|
942
|
-
assert_equal '2016-05-23', t(@myung, @created_at.if_present.format_date('%Y-%m-%d'))
|
|
943
|
-
assert_nil t(@laure, @comments.if_present)
|
|
944
|
-
|
|
945
|
-
assert_nil t(@nilly, @duration.if_present.format('%Y-%m-%d'))
|
|
946
|
-
assert_nil t(@nilly, @duration.if_present.format_date('%Y-%m-%d'))
|
|
947
|
-
|
|
948
|
-
# NOTE: here we're testing the capacity to format a nil value,
|
|
949
|
-
# however, @comments is a text field, and not a date/datetime field,
|
|
950
|
-
# so Postgres will rightfully complain when we format the text:
|
|
951
|
-
# we need to cast it first.
|
|
952
|
-
if @env_db == 'postgresql'
|
|
953
|
-
assert_nil t(@laure, @comments.cast(:date).if_present.format('%Y-%m-%d'))
|
|
954
|
-
assert_nil t(@laure, @comments.cast(:date).if_present.format_date('%Y-%m-%d'))
|
|
955
|
-
else
|
|
956
|
-
assert_nil t(@laure, @comments.if_present.format('%Y-%m-%d'))
|
|
957
|
-
assert_nil t(@laure, @comments.if_present.format_date('%Y-%m-%d'))
|
|
471
|
+
assert_equal 1, t(@laure,ArelExtensions::Nodes::Case.new.when(@duration.cast(:time).cast(:string).eq("12:42:21")).then(1).else(0)) unless @env_db == 'oracle' || @env_db == 'mssql'
|
|
472
|
+
assert_equal 1, t(@laure,ArelExtensions::Nodes::Case.new.when(@duration.cast(:time).eq("12:42:21")).then(1).else(0)) unless @env_db == 'oracle'
|
|
473
|
+
assert_equal "20.16", t(@laure,@score.cast(:string)).gsub(/[0]*\z/,'')
|
|
474
|
+
assert_equal "20.161", t(@laure,@score.cast(:string)+1).gsub(/[0]*1\z/,'1')
|
|
475
|
+
assert_equal 21.16, t(@laure,@score.cast(:string).cast(:decimal)+1)
|
|
476
|
+
assert_equal 21, t(@laure,@score.cast(:string).cast(:int)+1)
|
|
477
|
+
|
|
478
|
+
assert_equal String, t(@lucas,@updated_at.cast(:string)).class
|
|
479
|
+
assert_equal Date, t(@lucas,@updated_at.cast(:date)).class unless @env_db == 'oracle' # DateTime
|
|
480
|
+
assert_equal Time, t(@lucas,@updated_at.cast(:string).cast(:datetime)).class
|
|
481
|
+
assert_equal Time, t(@lucas,@updated_at.cast(:time)).class
|
|
482
|
+
|
|
483
|
+
assert_equal "2014-03-03 12:42:00", t(@lucas,@updated_at.cast(:string)) unless @env_db == 'mssql' #locale dependent
|
|
484
|
+
assert_equal Date.parse("2014-03-03"), t(@lucas,Arel::Nodes.build_quoted('2014-03-03').cast(:date))
|
|
485
|
+
assert_equal Date.parse("5014-03-03"), t(@lucas,(@age.cast(:string) + '014-03-03').cast(:date))
|
|
486
|
+
assert_equal Time.parse("2014-03-03 12:42:00 UTC"), t(@lucas,@updated_at.cast(:string).cast(:datetime))
|
|
487
|
+
assert_equal Date.parse("2014-03-03"), t(@lucas,@updated_at.cast(:date))
|
|
488
|
+
assert_equal "12:42:00", t(@lucas,@updated_at.cast(:time).cast(:string)).split('.').first unless @env_db == 'oracle' #DateTime
|
|
958
489
|
end
|
|
959
490
|
end
|
|
960
491
|
|
|
961
492
|
def test_is_null
|
|
962
|
-
#
|
|
963
|
-
#
|
|
964
|
-
#
|
|
965
|
-
#
|
|
966
|
-
#
|
|
967
|
-
assert_equal
|
|
493
|
+
#puts User.where(@age.is_null).select(@name).to_sql
|
|
494
|
+
#puts @age.is_null
|
|
495
|
+
#puts @age.is_null.inspect
|
|
496
|
+
#puts @age.is_null.to_sql
|
|
497
|
+
#puts @age=='34'
|
|
498
|
+
assert_equal "Test", User.select(@name).where(@age.is_null.to_sql).first.name
|
|
968
499
|
end
|
|
969
500
|
|
|
970
501
|
def test_math_plus
|
|
971
502
|
d = Date.new(1997, 6, 15)
|
|
972
|
-
#
|
|
973
|
-
assert_equal
|
|
974
|
-
assert_equal
|
|
975
|
-
assert_equal
|
|
976
|
-
assert_equal
|
|
977
|
-
assert_equal
|
|
978
|
-
assert_equal
|
|
979
|
-
assert_equal
|
|
980
|
-
assert_equal
|
|
981
|
-
#
|
|
982
|
-
assert_equal
|
|
983
|
-
#
|
|
503
|
+
#Concat String
|
|
504
|
+
assert_equal "SophiePhan", t(@sophie, @name + "Phan")
|
|
505
|
+
assert_equal "Sophie2", t(@sophie, @name + 2)
|
|
506
|
+
assert_equal "Sophie1997-06-15", t(@sophie, @name + d)
|
|
507
|
+
assert_equal "Sophie15", t(@sophie, @name + @age)
|
|
508
|
+
assert_equal "SophieSophie", t(@sophie, @name + @name)
|
|
509
|
+
assert_equal "SophieSophieSophie", t(@sophie, @name + @name + @name)
|
|
510
|
+
assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name.concat(@name)))
|
|
511
|
+
assert_equal "SophieSophieSophie", t(@sophie, @name.concat(@name).concat(@name))
|
|
512
|
+
#FIXME: should work as expected in Oracle
|
|
513
|
+
assert_equal "Sophie2016-05-23", t(@sophie, @name + @created_at) unless @env_db == 'oracle'
|
|
514
|
+
#concat Integer
|
|
984
515
|
assert_equal 1, User.where((@age + 10).eq(33)).count
|
|
985
|
-
assert_equal 1, User.where((@age +
|
|
516
|
+
assert_equal 1, User.where((@age + "1").eq(6)).count
|
|
986
517
|
assert_equal 1, User.where((@age + @age).eq(10)).count
|
|
987
|
-
#
|
|
988
|
-
#
|
|
989
|
-
assert_equal
|
|
990
|
-
assert_equal
|
|
518
|
+
#concat Date
|
|
519
|
+
#puts((User.arel_table[:created_at] + 1).as("res").to_sql.inspect)
|
|
520
|
+
assert_equal "2016-05-24", t(@myung, @created_at + 1).to_date.to_s
|
|
521
|
+
assert_equal "2016-05-25", t(@myung, @created_at + 2.day).to_date.to_s
|
|
991
522
|
end
|
|
992
523
|
|
|
524
|
+
|
|
993
525
|
def test_math_minus
|
|
994
526
|
d = Date.new(2016, 5, 20)
|
|
995
|
-
#
|
|
996
|
-
assert_equal
|
|
997
|
-
assert_equal 3, @laure.select((@created_at - d).as(
|
|
998
|
-
#
|
|
527
|
+
#Datediff
|
|
528
|
+
assert_equal 8, User.where((@created_at - @created_at).eq(0)).count
|
|
529
|
+
assert_equal 3, @laure.select((@created_at - d).as("res")).first.res.abs.to_i
|
|
530
|
+
#Substraction
|
|
999
531
|
assert_equal 0, User.where((@age - 10).eq(50)).count
|
|
1000
|
-
assert_equal 0, User.where((@age -
|
|
532
|
+
assert_equal 0, User.where((@age - "10").eq(50)).count
|
|
1001
533
|
# assert_equal 0, User.where((@age - 9.5).eq(50.5)).count # should work: TODO
|
|
1002
|
-
assert_equal 0, User.where((@age -
|
|
534
|
+
assert_equal 0, User.where((@age - "9.5").eq(50.5)).count
|
|
1003
535
|
end
|
|
1004
536
|
|
|
1005
537
|
def test_wday
|
|
1006
|
-
#
|
|
538
|
+
#d = Date.new(2016, 6, 26)
|
|
1007
539
|
assert_equal(@env_db == 'oracle' || @env_db == 'mssql' ? 2 : 1, t(@myung, @created_at.wday).to_i) # monday
|
|
1008
540
|
end
|
|
1009
541
|
|
|
@@ -1022,11 +554,11 @@ module ArelExtensions
|
|
|
1022
554
|
assert_equal 3, User.select('*').from((@ut.project(@age).where(@age.eq(20)) + @ut.project(@age).where(@age.eq(23)) + @ut.project(@age).where(@age.eq(21))).as('my_union')).length
|
|
1023
555
|
assert_equal 2, User.select('*').from((@ut.project(@age).where(@age.eq(20)) + @ut.project(@age).where(@age.eq(20)) + @ut.project(@age).where(@age.eq(21))).as('my_union')).length
|
|
1024
556
|
|
|
1025
|
-
assert_equal 3, User.find_by_sql(@ut.project(@age).where(@age.gt(22)).union_all(@ut.project(@age).where(@age.lt(0))).to_sql).length
|
|
1026
|
-
assert_equal 3, User.find_by_sql(@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(20))).union_all(@ut.project(@age).where(@age.eq(21))).to_sql).length
|
|
1027
|
-
assert_equal 3, User.select('*').from(@ut.project(@age).where(@age.gt(22)).union_all(@ut.project(@age).where(@age.lt(0))).as('my_union')).length
|
|
1028
|
-
assert_equal 3, User.select('*').from(@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(23))).union_all(@ut.project(@age).where(@age.eq(21))).as('my_union')).length
|
|
1029
|
-
assert_equal 3, User.select('*').from(@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(20))).union_all(@ut.project(@age).where(@age.eq(21))).as('my_union')).length
|
|
557
|
+
assert_equal 3, User.find_by_sql((@ut.project(@age).where(@age.gt(22)).union_all(@ut.project(@age).where(@age.lt(0)))).to_sql).length
|
|
558
|
+
assert_equal 3, User.find_by_sql((@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(20))).union_all(@ut.project(@age).where(@age.eq(21)))).to_sql).length
|
|
559
|
+
assert_equal 3, User.select('*').from((@ut.project(@age).where(@age.gt(22)).union_all(@ut.project(@age).where(@age.lt(0)))).as('my_union')).length
|
|
560
|
+
assert_equal 3, User.select('*').from((@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(23))).union_all(@ut.project(@age).where(@age.eq(21)))).as('my_union')).length
|
|
561
|
+
assert_equal 3, User.select('*').from((@ut.project(@age).where(@age.eq(20)).union_all(@ut.project(@age).where(@age.eq(20))).union_all(@ut.project(@age).where(@age.eq(21)))).as('my_union')).length
|
|
1030
562
|
|
|
1031
563
|
assert (@ut.project(@age) + @ut.project(@age)).as('toto').table_name # as on union should answer to table_name (TableAlias)
|
|
1032
564
|
end
|
|
@@ -1034,123 +566,116 @@ module ArelExtensions
|
|
|
1034
566
|
# Case clause
|
|
1035
567
|
def test_case
|
|
1036
568
|
assert_equal 4, User.find_by_sql(@ut.project(@score.when(20.16).then(1).else(0).as('score_bin')).to_sql).sum(&:score_bin)
|
|
1037
|
-
assert_equal
|
|
1038
|
-
assert_equal
|
|
1039
|
-
assert_equal
|
|
1040
|
-
assert_equal
|
|
1041
|
-
assert_equal
|
|
1042
|
-
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
|
|
569
|
+
assert_equal 2, t(@arthur, @score.when(65.62,1).else(0)+1)
|
|
570
|
+
assert_equal 0, t(@arthur, @score.when(65.62,1).else(0)-1)
|
|
571
|
+
assert_equal "11", t(@arthur, @score.when(65.62).then("1").else("0")+"1")
|
|
572
|
+
assert_equal 66.62, t(@arthur, @score.when(65.62).then(@score).else(@score)+1)
|
|
573
|
+
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
|
|
1043
574
|
end
|
|
1044
575
|
|
|
1045
576
|
def test_format_numbers
|
|
1046
|
-
#
|
|
1047
|
-
skip
|
|
1048
|
-
|
|
1049
|
-
assert_equal
|
|
1050
|
-
assert_equal
|
|
1051
|
-
assert_equal
|
|
1052
|
-
assert_equal
|
|
1053
|
-
assert_equal
|
|
1054
|
-
assert_equal
|
|
1055
|
-
assert_equal
|
|
1056
|
-
assert_equal
|
|
1057
|
-
assert_equal
|
|
1058
|
-
assert_equal
|
|
1059
|
-
assert_equal
|
|
1060
|
-
assert_equal
|
|
1061
|
-
assert_includes [
|
|
1062
|
-
assert_includes [
|
|
1063
|
-
assert_includes [
|
|
1064
|
-
assert_equal
|
|
1065
|
-
assert_equal
|
|
1066
|
-
assert_equal
|
|
1067
|
-
assert_equal
|
|
1068
|
-
assert_equal
|
|
1069
|
-
assert_equal
|
|
577
|
+
#score of Arthur = 65.62
|
|
578
|
+
skip " Works with SQLite if the version used knows printf" if $sqlite
|
|
579
|
+
|
|
580
|
+
assert_equal "Wrong Format" , t(@arthur, @score.format_number("$ %...234.6F €","fr_FR"))
|
|
581
|
+
assert_equal "AZERTY65,62" , t(@arthur, @score.format_number("AZERTY%.2f","fr_FR"))
|
|
582
|
+
assert_equal "65,62AZERTY" , t(@arthur, @score.format_number("%.2fAZERTY","fr_FR"))
|
|
583
|
+
assert_equal "$ 65.62 €" , t(@arthur, @score.format_number("$ %.2f €","en_US"))
|
|
584
|
+
assert_equal "$ 66 €" , t(@arthur, @score.format_number("$ %.0f €","en_US"))
|
|
585
|
+
assert_equal "$ 0065,62 €" , t(@arthur, @score.format_number("$ %07.2f €","fr_FR"))
|
|
586
|
+
assert_equal "$ 65,62 €" , t(@arthur, @score.format_number("$ %-07.2f €","fr_FR"))
|
|
587
|
+
assert_equal "$ 65,62 €" , t(@arthur, @score.format_number("$ %-7.2f €","fr_FR"))
|
|
588
|
+
assert_equal "$ 65,62 €" , t(@arthur, @score.format_number("$ % 7.2f €","fr_FR"))
|
|
589
|
+
assert_equal "$ 65,6 €" , t(@arthur, @score.format_number("$ % 7.1f €","fr_FR"))
|
|
590
|
+
assert_equal "$ +65,62 €" , t(@arthur, @score.format_number("$ % +7.2f €","fr_FR"))
|
|
591
|
+
assert_equal "$ +065,62 €" , t(@arthur, @score.format_number("$ %0+7.2f €","fr_FR"))
|
|
592
|
+
assert_includes ["$ 6,56e1 €","$ 6,56e+01 €"], t(@arthur, @score.format_number("$ %.2e €","fr_FR"))
|
|
593
|
+
assert_includes ["$ 6,56E1 €","$ 6,56E+01 €"], t(@arthur, @score.format_number("$ %.2E €","fr_FR"))
|
|
594
|
+
assert_includes ["$ 6,562E1 €","$ 6,562E+01 €"], t(@arthur, @score.format_number("$ %.3E €","fr_FR"))
|
|
595
|
+
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)
|
|
596
|
+
assert_equal "123456765,6" , t(@arthur, (@score+123456700).format_number("%.1f","fr_FR")).gsub("\u00A0","") #because SqlServer does it like no one else
|
|
597
|
+
assert_equal "123,456,765.6" , t(@arthur, (@score+123456700).format_number("%.1f","en_US"))
|
|
598
|
+
assert_equal " 123,456,765.6" , t(@arthur, (@score+123456700).format_number("%16.1f","en_US"))
|
|
599
|
+
assert_equal "$ 0,00 €" , t(@arthur, @score.when(65.62).then(Arel.sql("null")).else(1).format_number("$ %.2f €","fr_FR"))
|
|
600
|
+
assert_equal "$ 0,00 €" , t(@arthur, (@score-65.62).format_number("$ %.2f €","fr_FR"))
|
|
1070
601
|
end
|
|
1071
602
|
|
|
1072
603
|
def test_accent_insensitive
|
|
1073
|
-
skip
|
|
1074
|
-
skip
|
|
604
|
+
skip "SQLite is natively Case Insensitive and Accent Sensitive" if $sqlite
|
|
605
|
+
skip "Not finished" if @env_db == 'mysql'
|
|
1075
606
|
# actual comments value: "arrêté"
|
|
1076
|
-
#
|
|
607
|
+
#AI & CI
|
|
1077
608
|
if !['postgresql'].include?(@env_db) # Extension unaccent required on PG
|
|
1078
|
-
assert_equal
|
|
1079
|
-
assert_equal
|
|
1080
|
-
assert_equal
|
|
1081
|
-
assert_equal
|
|
1082
|
-
assert_equal
|
|
1083
|
-
assert_equal
|
|
1084
|
-
#
|
|
1085
|
-
assert_equal
|
|
1086
|
-
assert_equal
|
|
1087
|
-
assert_equal
|
|
1088
|
-
assert_equal
|
|
1089
|
-
if
|
|
1090
|
-
assert_equal
|
|
1091
|
-
assert_equal
|
|
609
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrêté")).then("1").else("0"))
|
|
610
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arrete")).then("1").else("0"))
|
|
611
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("àrrétè")).then("1").else("0"))
|
|
612
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("arretez")).then("1").else("0"))
|
|
613
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrete")).then("1").else("0"))
|
|
614
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_imatches("Arrêté")).then("1").else("0"))
|
|
615
|
+
#AI & CS
|
|
616
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrêté")).then("1").else("0"))
|
|
617
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arrete")).then("1").else("0"))
|
|
618
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("àrrétè")).then("1").else("0"))
|
|
619
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("arretez")).then("1").else("0"))
|
|
620
|
+
if !['oracle','postgresql','mysql'].include?(@env_db) # AI => CI
|
|
621
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("Arrete")).then("1").else("0"))
|
|
622
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.ai_matches("Arrêté")).then("1").else("0"))
|
|
1092
623
|
end
|
|
1093
624
|
end
|
|
1094
|
-
#
|
|
1095
|
-
assert_equal
|
|
625
|
+
#AS & CI
|
|
626
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrêté")).then("1").else("0"))
|
|
1096
627
|
if !['mysql'].include?(@env_db) # CI => AI in utf8 (AI not possible in latin1)
|
|
1097
|
-
assert_equal
|
|
1098
|
-
assert_equal
|
|
628
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arrete")).then("1").else("0"))
|
|
629
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("àrrétè")).then("1").else("0"))
|
|
1099
630
|
end
|
|
1100
|
-
assert_equal
|
|
631
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("arretez")).then("1").else("0"))
|
|
1101
632
|
if !['mysql'].include?(@env_db) # CI => AI in utf8 (AI not possible in latin1)
|
|
1102
|
-
assert_equal
|
|
633
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrete")).then("1").else("0"))
|
|
1103
634
|
end
|
|
1104
|
-
assert_equal
|
|
1105
|
-
#
|
|
1106
|
-
assert_equal
|
|
1107
|
-
assert_equal
|
|
1108
|
-
assert_equal
|
|
1109
|
-
assert_equal
|
|
1110
|
-
assert_equal
|
|
1111
|
-
assert_equal
|
|
635
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.imatches("Arrêté")).then("1").else("0"))
|
|
636
|
+
#AS & CS
|
|
637
|
+
assert_equal "1", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrêté")).then("1").else("0"))
|
|
638
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arrete")).then("1").else("0"))
|
|
639
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("àrrétè")).then("1").else("0"))
|
|
640
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("arretez")).then("1").else("0"))
|
|
641
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("Arrete")).then("1").else("0"))
|
|
642
|
+
assert_equal "0", t(@arthur,ArelExtensions::Nodes::Case.new.when(@comments.smatches("Arrêté")).then("1").else("0"))
|
|
1112
643
|
end
|
|
1113
644
|
|
|
1114
645
|
def test_subquery_with_order
|
|
1115
|
-
|
|
1116
|
-
assert_equal
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
# Sqlite and mssql are sensistive to the nil value in name, defined by @all_nil
|
|
1121
|
-
assert_equal 1, User.where(name: User.select(:name).order(:name).limit(2)).count
|
|
1122
|
-
elsif @env_db != 'mysql'
|
|
1123
|
-
# MySql can't have limit in IN subquery
|
|
1124
|
-
assert_equal 2, User.where(name: User.select(:name).order(:name).limit(2)).count
|
|
1125
|
-
# assert_equal 6, User.where(name: User.select(:name).order(:name).offset(2)).count
|
|
646
|
+
assert_equal 8, User.where(:name => User.select(:name).order(:name)).count
|
|
647
|
+
assert_equal 8, User.where(@ut[:name].in(@ut.project(@ut[:name]).order(@ut[:name]))).count
|
|
648
|
+
if !['mysql'].include?(@env_db) # MySql can't have limit in IN subquery
|
|
649
|
+
assert_equal 2, User.where(:name => User.select(:name).order(:name).limit(2)).count
|
|
650
|
+
#assert_equal 6, User.where(:name => User.select(:name).order(:name).offset(2)).count
|
|
1126
651
|
end
|
|
1127
652
|
end
|
|
1128
653
|
|
|
1129
654
|
def test_in_with_nil
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
655
|
+
assert_equal true , @myung.where(@age.in(1)).blank?
|
|
656
|
+
assert_equal false , @myung.where(@age.in(23)).blank?
|
|
657
|
+
assert_equal true , @myung.where(@age.in([1])).blank?
|
|
658
|
+
assert_equal true , @myung.where(@age.in([1,2])).blank?
|
|
659
|
+
assert_equal false , @myung.where(@age.in([1,23])).blank?
|
|
660
|
+
assert_equal true , @myung.where(@age.in(nil)).blank?
|
|
661
|
+
assert_equal true , @myung.where(@age.in([nil])).blank?
|
|
662
|
+
assert_equal true , @myung.where(@age.in([nil,1])).blank?
|
|
663
|
+
assert_equal false , @myung.where(@age.in([nil,23])).blank?
|
|
664
|
+
assert_equal true , @myung.where(@age.in([nil,1,2])).blank?
|
|
665
|
+
assert_equal false , @myung.where(@age.in([nil,1,23])).blank?
|
|
666
|
+
assert_equal true , @test.where(@age.in(1)).blank?
|
|
667
|
+
assert_equal true , @test.where(@age.in([1])).blank?
|
|
668
|
+
assert_equal true , @test.where(@age.in([1,2])).blank?
|
|
669
|
+
assert_equal false , @test.where(@age.in(nil)).blank?
|
|
670
|
+
assert_equal false , @test.where(@age.in([nil])).blank?
|
|
671
|
+
assert_equal false , @test.where(@age.in([nil,1])).blank?
|
|
672
|
+
assert_equal false , @test.where(@age.in([nil,1,2])).blank?
|
|
1148
673
|
end
|
|
1149
674
|
|
|
1150
675
|
def test_scope_with_in_plus_new
|
|
1151
676
|
begin
|
|
1152
|
-
@test.where(@age.in([1,
|
|
1153
|
-
@test.where(@age.not_in([1,
|
|
677
|
+
@test.where(@age.in([1,2])).new
|
|
678
|
+
@test.where(@age.not_in([1,2])).new
|
|
1154
679
|
assert true
|
|
1155
680
|
rescue
|
|
1156
681
|
assert false
|
|
@@ -1158,176 +683,114 @@ module ArelExtensions
|
|
|
1158
683
|
end
|
|
1159
684
|
|
|
1160
685
|
def test_is_not_null
|
|
1161
|
-
|
|
1162
|
-
|
|
686
|
+
assert_equal false , @myung.where(@age.is_not_null).blank?
|
|
687
|
+
assert_equal true , @test.where(@age.is_not_null).blank?
|
|
1163
688
|
end
|
|
1164
689
|
|
|
1165
690
|
def test_not_in_with_nil
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
#
|
|
1181
|
-
#
|
|
1182
|
-
#
|
|
1183
|
-
#
|
|
1184
|
-
#
|
|
1185
|
-
#
|
|
1186
|
-
#
|
|
1187
|
-
#
|
|
1188
|
-
end
|
|
1189
|
-
|
|
1190
|
-
def test_in_on_grouping
|
|
1191
|
-
skip 'We should modify the visitor of IN to make it work' if $sqlite || @env_db == 'mssql'
|
|
1192
|
-
assert_equal 2, User.where(Arel.tuple(@name, @age).in(Arel.tuple('Myung', 23), Arel.tuple('Arthur', 21))).count
|
|
1193
|
-
assert_equal 1, User.where(Arel.tuple(@name, @age).in(Arel.tuple('Myung', 23))).count
|
|
1194
|
-
assert_equal 0, User.where(Arel.tuple(@name, @age).in([])).count
|
|
691
|
+
assert_equal false , @myung.where(@age.not_in(1)).blank?
|
|
692
|
+
assert_equal true , @myung.where(@age.not_in(23)).blank?
|
|
693
|
+
assert_equal false , @myung.where(@age.not_in([1])).blank?
|
|
694
|
+
assert_equal false , @myung.where(@age.not_in([1,2])).blank?
|
|
695
|
+
assert_equal true , @myung.where(@age.not_in([1,23])).blank?
|
|
696
|
+
assert_equal false , @myung.where(@age.not_in(nil)).blank?
|
|
697
|
+
assert_equal false , @myung.where(@age.not_in([nil])).blank?
|
|
698
|
+
assert_equal false , @myung.where(@age.not_in([nil,1])).blank?
|
|
699
|
+
assert_equal true , @myung.where(@age.not_in([nil,23])).blank?
|
|
700
|
+
assert_equal false , @myung.where(@age.not_in([nil,1,2])).blank?
|
|
701
|
+
assert_equal true , @myung.where(@age.not_in([nil,1,23])).blank?
|
|
702
|
+
|
|
703
|
+
assert_equal false , @myung.where(@age.not_in(1..2)).blank?
|
|
704
|
+
|
|
705
|
+
#if the column is null, the entry will never be selected with not in (like every DBMS does)
|
|
706
|
+
#assert_equal false , @test.where(@age.not_in(1)).blank?
|
|
707
|
+
#assert_equal false , @test.where(@age.not_in([1])).blank?
|
|
708
|
+
#assert_equal false , @test.where(@age.not_in([1,2])).blank?
|
|
709
|
+
#assert_equal true , @test.where(@age.not_in(nil)).blank?
|
|
710
|
+
#assert_equal true , @test.where(@age.not_in([nil])).blank?
|
|
711
|
+
#assert_equal true , @test.where(@age.not_in([nil,1])).blank?
|
|
712
|
+
#assert_equal true , @test.where(@age.not_in([nil,1,2])).blank?
|
|
1195
713
|
end
|
|
1196
714
|
|
|
1197
715
|
def test_alias_shortened
|
|
1198
|
-
if
|
|
716
|
+
if ['postgresql','oracle'].include?(@env_db)
|
|
1199
717
|
new_alias = Arel.shorten('azerty' * 15)
|
|
1200
718
|
at = User.arel_table.alias('azerty' * 15)
|
|
1201
719
|
assert_equal "\"user_tests\" \"#{new_alias}\"".downcase, User.arel_table.alias('azerty' * 15).to_sql.downcase
|
|
1202
720
|
assert_equal '"user_tests" "u"'.downcase, User.arel_table.alias('u').to_sql.downcase
|
|
1203
|
-
assert_equal
|
|
1204
|
-
|
|
721
|
+
assert_equal %Q[SELECT "#{new_alias}"."id" FROM "user_tests" "#{new_alias}"].downcase,
|
|
722
|
+
User.select(at[:id]).from(at).to_sql.downcase
|
|
1205
723
|
end
|
|
1206
724
|
end
|
|
1207
725
|
|
|
1208
726
|
def test_stat_functions
|
|
1209
727
|
skip "SQLite doesn't work for most on this functions" if $sqlite
|
|
1210
|
-
#
|
|
1211
|
-
#
|
|
1212
|
-
#
|
|
1213
|
-
#
|
|
1214
|
-
#
|
|
1215
|
-
|
|
1216
|
-
assert ( 15.
|
|
1217
|
-
assert (
|
|
1218
|
-
assert (
|
|
1219
|
-
assert (
|
|
1220
|
-
assert (
|
|
1221
|
-
skip 'Not Yet Implemented' # if !['postgresql'].include?(@env_db)
|
|
1222
|
-
assert_equal 2, User.select(@score.std(group: Arel.when(@name > 'M').then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
|
|
1223
|
-
assert_equal 2, User.select(@score.variance(group: Arel.when(@name > 'M').then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
|
|
1224
|
-
assert_equal 2, User.select(@score.sum(group: Arel.when(@name > 'M').then(0).else(1)).as('res')).map{|e| e['res']}.uniq.length
|
|
1225
|
-
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
|
|
728
|
+
#puts t(User.where(nil), @score.average)
|
|
729
|
+
#puts t(User.where(nil), @score.variance(true))
|
|
730
|
+
#puts t(User.where(nil), @score.variance(false))
|
|
731
|
+
#puts t(User.where(nil), @score.std(true))
|
|
732
|
+
#puts t(User.where(nil), @score.std(false))
|
|
733
|
+
|
|
734
|
+
assert ( 15.98625 - t(User.where(nil), @score.average)).abs < 0.01
|
|
735
|
+
assert (613.75488 - t(User.where(nil), @score.variance)).abs < 0.01
|
|
736
|
+
assert ( 537.0355 - t(User.where(nil), @score.variance(false))).abs < 0.01
|
|
737
|
+
assert ( 24.77408 - t(User.where(nil), @score.std)).abs < 0.01
|
|
738
|
+
assert ( 23.17403 - t(User.where(nil), @score.std(false))).abs < 0.01
|
|
1226
739
|
end
|
|
1227
740
|
|
|
1228
741
|
def test_levenshtein_distance
|
|
1229
|
-
skip
|
|
1230
|
-
assert_equal 0, t(@arthur
|
|
1231
|
-
assert_equal 2, t(@arthur
|
|
1232
|
-
assert_equal 1, t(@arthur
|
|
742
|
+
skip "Not Yet Implemented" if $sqlite
|
|
743
|
+
assert_equal 0, t(@arthur,@name.levenshtein_distance("Arthur"))
|
|
744
|
+
assert_equal 2, t(@arthur,@name.levenshtein_distance("Artoor"))
|
|
745
|
+
assert_equal 1, t(@arthur,@name.levenshtein_distance("Artehur"))
|
|
1233
746
|
end
|
|
1234
747
|
|
|
1235
|
-
def
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
assert_equal
|
|
1239
|
-
assert_equal
|
|
1240
|
-
assert_equal ({
|
|
1241
|
-
assert_equal
|
|
1242
|
-
|
|
748
|
+
def test_json
|
|
749
|
+
skip "Can't be tested on travis"
|
|
750
|
+
#creation
|
|
751
|
+
assert_equal 'Arthur', t(@arthur,Arel.json(@name))
|
|
752
|
+
assert_equal ["Arthur","Arthur"], parse_json(t(@arthur,Arel.json(@name,@name)))
|
|
753
|
+
assert_equal ({"Arthur" => "Arthur", "Arthur2" => "ArthurArthur"}), parse_json(t(@arthur,Arel.json({@name => @name,@name+"2" => @name+@name})))
|
|
754
|
+
assert_equal ({"Arthur" => "Arthur","Arthur2" => 1}), parse_json(t(@arthur,Arel.json({@name => @name,@name+"2" => 1})))
|
|
755
|
+
assert_equal ([{"age" => 21},{"name" => "Arthur","score" => 65.62}]), parse_json(t(@arthur,Arel.json([{age: @age},{name: @name,score: @score}])))
|
|
1243
756
|
|
|
1244
|
-
def test_json_aggregate
|
|
1245
757
|
# aggregate
|
|
1246
|
-
assert_equal ({
|
|
1247
|
-
|
|
1248
|
-
assert_equal ({
|
|
1249
|
-
|
|
1250
|
-
assert_equal [{
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
#
|
|
1254
|
-
#
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
assert_equal
|
|
1263
|
-
h2
|
|
1264
|
-
|
|
1265
|
-
assert_equal
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
assert_equal ({'Arthur' => %w[toto tata], 'Arthur2' => 1}), parse_json(t(@arthur, h1.set(@name, %w[toto tata])))
|
|
1274
|
-
assert_equal ({'Arthur' => 'ArthurArthur', 'Arthur2' => 1, 'Arthur3' => 2}), parse_json(t(@arthur, h1.set(@name + '3', 2)))
|
|
1275
|
-
assert_equal ({'Arthur' => 'ArthurArthur', 'Arthur2' => 1, 'Arthur3' => nil}), parse_json(t(@arthur, h1.set(@name + '3', nil)))
|
|
1276
|
-
assert_equal ({'Arthur' => 'ArthurArthur', 'Arthur2' => 1, 'Arthur3' => {'a' => 2}}), parse_json(t(@arthur, h1.set(@name + '3', {a: 2})))
|
|
1277
|
-
end
|
|
1278
|
-
|
|
1279
|
-
def test_json_merge
|
|
1280
|
-
skip 'Not Yet Implemented' if $sqlite || %w[oracle mssql].include?(@env_db)
|
|
1281
|
-
# merge
|
|
1282
|
-
h1 = Arel.json({@name => @name + @name, @name + '2' => 1})
|
|
1283
|
-
assert_equal ({'Arthur' => %w[toto tata], 'Arthur2' => 1, 'Arthur3' => 2}), parse_json(t(@arthur, h1.merge({@name => %w[toto tata]}, {@name + '3' => 2})))
|
|
1284
|
-
assert_equal ({'Arthur' => %w[toto tata], 'Arthur2' => 1, 'Arthur3' => 2}), parse_json(t(@arthur, h1.merge({@name => %w[toto tata], @name + '3' => 2})))
|
|
1285
|
-
assert_equal ({'Arthur' => 'ArthurArthur', 'Arthur2' => 1}), parse_json(t(@arthur, h1.merge({})))
|
|
1286
|
-
end
|
|
1287
|
-
|
|
1288
|
-
def test_json_scalar_values
|
|
1289
|
-
assert_nil t(@arthur, Arel.json(nil))
|
|
1290
|
-
|
|
1291
|
-
assert_equal 42, parse_json(t(@arthur, Arel.json(42)))
|
|
1292
|
-
assert_equal({}, parse_json(t(@arthur, Arel.json({}))))
|
|
1293
|
-
assert_equal [], parse_json(t(@arthur, Arel.json([])))
|
|
1294
|
-
|
|
1295
|
-
assert_equal true, parse_json(t(@arthur, Arel.json(true)))
|
|
1296
|
-
assert_equal ({'Arthur' => false}), parse_json(t(@arthur, Arel.json({@name => false})))
|
|
1297
|
-
|
|
1298
|
-
assert_equal ({'Arthur' => true}), parse_json(t(@arthur, Arel.json({@name => @enabled})))
|
|
1299
|
-
assert_equal ({'Camille' => false}), parse_json(t(@camille, Arel.json({@name => @enabled})))
|
|
1300
|
-
assert_equal ({'Lucas' => nil}), parse_json(t(@lucas, Arel.json({@name => @enabled})))
|
|
1301
|
-
end
|
|
1302
|
-
|
|
1303
|
-
def test_json_special_chars
|
|
1304
|
-
assert_equal ({'Arthur' => 'say "hi"'}), parse_json(t(@arthur, Arel.json({@name => 'say "hi"'})))
|
|
1305
|
-
assert_equal ({'Arthur' => 'a\\b'}), parse_json(t(@arthur, Arel.json({@name => 'a\\b'})))
|
|
1306
|
-
assert_equal ({'Arthur' => "line1\nline2"}), parse_json(t(@arthur, Arel.json({@name => "line1\nline2"})))
|
|
1307
|
-
assert_equal ({'we"ird' => 'Arthur'}), parse_json(t(@arthur, Arel.json({'we"ird' => @name})))
|
|
1308
|
-
end
|
|
1309
|
-
|
|
1310
|
-
def test_json_date_values
|
|
1311
|
-
assert_equal ({'Arthur' => '2016-05-23'}), parse_json(t(@arthur, Arel.json({@name => @created_at})))
|
|
1312
|
-
res = parse_json(t(@laure, Arel.json({@name => @duration})))['Laure']
|
|
1313
|
-
assert_equal '12:42:21', res.sub(/\.\d+\z/, '') # MySQL (unlinke MariaDB) adds `.\d+` to a datetime column inside a json.
|
|
1314
|
-
|
|
1315
|
-
# the generic builder's `:datetime` branch is only used by sqlite and mssql.
|
|
1316
|
-
if $sqlite || @env_db == 'mssql'
|
|
1317
|
-
assert_equal ({'Lucas' => '2014-03-03T12:42:00'}), parse_json(t(@lucas, Arel.json({@name => @updated_at})))
|
|
1318
|
-
end
|
|
758
|
+
assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure"}),
|
|
759
|
+
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name}).group(false)))
|
|
760
|
+
assert_equal ({"5" => "Lucas", "15" => "Sophie", "23" => "Myung", "25" => "Laure", "Laure"=>25, "Lucas"=>5, "Myung"=>23, "Sophie"=>15}),
|
|
761
|
+
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16),Arel.json({@age => @name,@name => @age}).group(false)))
|
|
762
|
+
assert_equal ([{"5" => "Lucas"},{ "15" => "Sophie"},{ "23" => "Myung"},{ "25" => "Laure"}]),
|
|
763
|
+
parse_json(t(User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score),Arel.json({@age => @name}).group(true,[@age])))
|
|
764
|
+
|
|
765
|
+
#puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_sql
|
|
766
|
+
#puts User.group(:score).where(@age.is_not_null).where(@score == 20.16).select(@score,Arel.json({@age => @name}).group(true,[@age])).to_a
|
|
767
|
+
|
|
768
|
+
skip "Not Yet Implemented" if $sqlite || ['oracle','mssql'].include?(@env_db)
|
|
769
|
+
#get
|
|
770
|
+
h1 = Arel.json({@name => @name+@name,@name+"2" => 1})
|
|
771
|
+
assert_equal "ArthurArthur", parse_json(t(@arthur,h1.get(@name)))
|
|
772
|
+
h2 = Arel.json([{age: @age},{name: @name,score: @score}])
|
|
773
|
+
assert_equal ({"age" => 21}), parse_json(t(@arthur,h2.get(0)))
|
|
774
|
+
assert_equal 21, parse_json(t(@arthur,h2.get(0).get('age')))
|
|
775
|
+
assert_nil t(@arthur,h2.get('age'))
|
|
776
|
+
#set
|
|
777
|
+
assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1}), parse_json(t(@arthur,h1.set(@name, ['toto','tata'])))
|
|
778
|
+
assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.set(@name+"3",2)))
|
|
779
|
+
assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => nil}), parse_json(t(@arthur,h1.set(@name+"3",nil)))
|
|
780
|
+
assert_equal ({"Arthur" => "ArthurArthur", "Arthur2" => 1, "Arthur3" => {"a" => 2}}), parse_json(t(@arthur,h1.set(@name+"3",{a: 2})))
|
|
781
|
+
#merge
|
|
782
|
+
assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata']},{@name+"3" => 2})))
|
|
783
|
+
assert_equal ({"Arthur" => ["toto", "tata"], "Arthur2" => 1, "Arthur3" => 2}), parse_json(t(@arthur,h1.merge({@name => ['toto','tata'], @name+"3" => 2})))
|
|
784
|
+
assert_equal ({"Arthur" => "ArthurArthur","Arthur2" => 1}), parse_json(t(@arthur,h1.merge({})))
|
|
1319
785
|
end
|
|
1320
786
|
|
|
1321
787
|
def test_as_on_everything
|
|
1322
788
|
name = @arthur.select(@name.as('NaMe')).first.attributes
|
|
1323
|
-
assert_equal 'Arthur', name[
|
|
1324
|
-
assert_equal 'Arthur', @arthur.select(@name.as('Na Me')).first.attributes[
|
|
1325
|
-
assert_equal 'ArthurArthur', @arthur.select((@name
|
|
789
|
+
assert_equal 'Arthur', name["NaMe"] || name["name"] #because of Oracle
|
|
790
|
+
assert_equal 'Arthur', @arthur.select(@name.as('Na Me')).first.attributes["Na Me"]
|
|
791
|
+
assert_equal 'ArthurArthur', @arthur.select((@name+@name).as('Na-Me')).first.attributes["Na-Me"]
|
|
1326
792
|
end
|
|
1327
793
|
|
|
1328
|
-
def test_exists_in_subquery
|
|
1329
|
-
assert User.where(User.where(nil).arel.exists).first
|
|
1330
|
-
end
|
|
1331
794
|
end
|
|
1332
795
|
end
|
|
1333
796
|
end
|