activerecord-sqlserver-adapter 6.0.0.rc1 → 6.0.0.rc2
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/.gitignore +1 -0
- data/.rubocop.yml +29 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +11 -5
- data/Guardfile +9 -8
- data/Rakefile +12 -16
- data/VERSION +1 -1
- data/activerecord-sqlserver-adapter.gemspec +3 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +0 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +1 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +3 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/query_methods.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +35 -32
- data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +7 -12
- data/lib/active_record/connection_adapters/sqlserver/errors.rb +0 -3
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +8 -8
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +7 -7
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +106 -103
- data/lib/active_record/connection_adapters/sqlserver/showplan.rb +6 -8
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +1 -1
- data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +1 -4
- data/lib/active_record/connection_adapters/sqlserver/transaction.rb +4 -8
- data/lib/active_record/connection_adapters/sqlserver/type.rb +35 -35
- data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/char.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/type/data.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/date.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/float.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/json.rb +0 -1
- data/lib/active_record/connection_adapters/sqlserver/type/money.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/real.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/string.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/text.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/time.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +6 -9
- data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +1 -2
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/utils.rb +8 -11
- data/lib/active_record/connection_adapters/sqlserver/version.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +85 -83
- data/lib/active_record/connection_adapters/sqlserver_column.rb +0 -2
- data/lib/active_record/sqlserver_base.rb +1 -1
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +26 -32
- data/lib/activerecord-sqlserver-adapter.rb +1 -1
- data/lib/arel/visitors/sqlserver.rb +18 -14
- data/lib/arel_sqlserver.rb +2 -2
- data/test/cases/adapter_test_sqlserver.rb +161 -182
- data/test/cases/change_column_null_test_sqlserver.rb +12 -12
- data/test/cases/coerced_tests.rb +88 -270
- data/test/cases/column_test_sqlserver.rb +281 -283
- data/test/cases/connection_test_sqlserver.rb +15 -20
- data/test/cases/execute_procedure_test_sqlserver.rb +18 -20
- data/test/cases/fetch_test_sqlserver.rb +14 -22
- data/test/cases/fully_qualified_identifier_test_sqlserver.rb +12 -18
- data/test/cases/helper_sqlserver.rb +13 -15
- data/test/cases/in_clause_test_sqlserver.rb +9 -9
- data/test/cases/index_test_sqlserver.rb +13 -15
- data/test/cases/json_test_sqlserver.rb +23 -25
- data/test/cases/migration_test_sqlserver.rb +22 -28
- data/test/cases/order_test_sqlserver.rb +51 -54
- data/test/cases/pessimistic_locking_test_sqlserver.rb +25 -33
- data/test/cases/rake_test_sqlserver.rb +31 -45
- data/test/cases/schema_dumper_test_sqlserver.rb +104 -108
- data/test/cases/schema_test_sqlserver.rb +18 -26
- data/test/cases/scratchpad_test_sqlserver.rb +2 -4
- data/test/cases/showplan_test_sqlserver.rb +24 -33
- data/test/cases/specific_schema_test_sqlserver.rb +66 -65
- data/test/cases/transaction_test_sqlserver.rb +16 -19
- data/test/cases/trigger_test_sqlserver.rb +12 -12
- data/test/cases/utils_test_sqlserver.rb +68 -70
- data/test/cases/uuid_test_sqlserver.rb +11 -13
- data/test/debug.rb +6 -6
- data/test/migrations/create_clients_and_change_column_null.rb +1 -1
- data/test/migrations/transaction_table/1_table_will_never_be_created.rb +2 -4
- data/test/models/sqlserver/booking.rb +1 -1
- data/test/models/sqlserver/customers_view.rb +1 -1
- data/test/models/sqlserver/dollar_table_name.rb +1 -1
- data/test/models/sqlserver/edge_schema.rb +1 -3
- data/test/models/sqlserver/fk_has_fk.rb +1 -1
- data/test/models/sqlserver/fk_has_pk.rb +1 -1
- data/test/models/sqlserver/natural_pk_data.rb +2 -2
- data/test/models/sqlserver/natural_pk_int_data.rb +1 -1
- data/test/models/sqlserver/no_pk_data.rb +1 -1
- data/test/models/sqlserver/object_default.rb +1 -1
- data/test/models/sqlserver/quoted_table.rb +2 -2
- data/test/models/sqlserver/quoted_view_1.rb +1 -1
- data/test/models/sqlserver/quoted_view_2.rb +1 -1
- data/test/models/sqlserver/sst_memory.rb +1 -1
- data/test/models/sqlserver/string_default.rb +1 -1
- data/test/models/sqlserver/string_defaults_big_view.rb +1 -1
- data/test/models/sqlserver/string_defaults_view.rb +1 -1
- data/test/models/sqlserver/tinyint_pk.rb +1 -1
- data/test/models/sqlserver/trigger.rb +2 -2
- data/test/models/sqlserver/trigger_history.rb +1 -1
- data/test/models/sqlserver/upper.rb +1 -1
- data/test/models/sqlserver/uppered.rb +1 -1
- data/test/models/sqlserver/uuid.rb +1 -1
- data/test/schema/sqlserver_specific_schema.rb +20 -22
- data/test/support/coerceable_test_sqlserver.rb +1 -4
- data/test/support/connection_reflection.rb +1 -2
- data/test/support/core_ext/query_cache.rb +1 -1
- data/test/support/load_schema_sqlserver.rb +3 -5
- data/test/support/minitest_sqlserver.rb +1 -1
- data/test/support/paths_sqlserver.rb +9 -11
- data/test/support/rake_helpers.rb +12 -10
- data/test/support/sql_counter_sqlserver.rb +0 -4
- data/test/support/test_in_memory_oltp.rb +7 -7
- metadata +5 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "cases/helper_sqlserver"
|
|
4
|
+
require "migrations/create_clients_and_change_column_null"
|
|
5
5
|
|
|
6
6
|
class ChangeColumnNullTestSqlServer < ActiveRecord::TestCase
|
|
7
7
|
before do
|
|
@@ -19,25 +19,25 @@ class ChangeColumnNullTestSqlServer < ActiveRecord::TestCase
|
|
|
19
19
|
table.find { |column| column.name == name }
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
let(:clients_table) { connection.columns(
|
|
23
|
-
let(:name_column) { find_column(clients_table,
|
|
24
|
-
let(:code_column) { find_column(clients_table,
|
|
25
|
-
let(:value_column) { find_column(clients_table,
|
|
22
|
+
let(:clients_table) { connection.columns("clients") }
|
|
23
|
+
let(:name_column) { find_column(clients_table, "name") }
|
|
24
|
+
let(:code_column) { find_column(clients_table, "code") }
|
|
25
|
+
let(:value_column) { find_column(clients_table, "value") }
|
|
26
26
|
|
|
27
|
-
describe
|
|
28
|
-
it
|
|
27
|
+
describe "#change_column_null" do
|
|
28
|
+
it "does not change the column limit" do
|
|
29
29
|
_(name_column.limit).must_equal 15
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
it
|
|
33
|
-
_(code_column.default).must_equal
|
|
32
|
+
it "does not change the column default" do
|
|
33
|
+
_(code_column.default).must_equal "n/a"
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
it
|
|
36
|
+
it "does not change the column precision" do
|
|
37
37
|
_(value_column.precision).must_equal 32
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
it
|
|
40
|
+
it "does not change the column scale" do
|
|
41
41
|
_(value_column.scale).must_equal 8
|
|
42
42
|
end
|
|
43
43
|
end
|
data/test/cases/coerced_tests.rb
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require "cases/helper_sqlserver"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require 'models/event'
|
|
5
|
+
require "models/event"
|
|
8
6
|
class UniquenessValidationTest < ActiveRecord::TestCase
|
|
9
7
|
# So sp_executesql swallows this exception. Run without prepared to see it.
|
|
10
8
|
coerce_tests! :test_validate_uniqueness_with_limit
|
|
@@ -30,16 +28,13 @@ class UniquenessValidationTest < ActiveRecord::TestCase
|
|
|
30
28
|
coerce_tests! :test_validate_case_sensitive_uniqueness_by_default
|
|
31
29
|
def test_validate_case_sensitive_uniqueness_by_default_coerced
|
|
32
30
|
database_collation = connection.select_one("SELECT collation_name FROM sys.databases WHERE name = 'activerecord_unittest'").values.first
|
|
33
|
-
skip if database_collation.include?(
|
|
31
|
+
skip if database_collation.include?("_CI_")
|
|
34
32
|
|
|
35
33
|
original_test_validate_case_sensitive_uniqueness_by_default_coerced
|
|
36
34
|
end
|
|
37
35
|
end
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
require 'models/event'
|
|
37
|
+
require "models/event"
|
|
43
38
|
module ActiveRecord
|
|
44
39
|
class AdapterTest < ActiveRecord::TestCase
|
|
45
40
|
# I really don`t think we can support legacy binds.
|
|
@@ -54,7 +49,7 @@ module ActiveRecord
|
|
|
54
49
|
def test_value_limit_violations_are_translated_to_specific_exception_coerced
|
|
55
50
|
connection.unprepared_statement do
|
|
56
51
|
error = assert_raises(ActiveRecord::ValueTooLong) do
|
|
57
|
-
Event.create(title:
|
|
52
|
+
Event.create(title: "abcdefgh")
|
|
58
53
|
end
|
|
59
54
|
assert_not_nil error.cause
|
|
60
55
|
end
|
|
@@ -69,9 +64,6 @@ module ActiveRecord
|
|
|
69
64
|
end
|
|
70
65
|
end
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
67
|
module ActiveRecord
|
|
76
68
|
class AdapterTestWithoutTransaction < ActiveRecord::TestCase
|
|
77
69
|
# SQL Server does not allow truncation of tables that are referenced by foreign key
|
|
@@ -125,15 +117,12 @@ module ActiveRecord
|
|
|
125
117
|
end
|
|
126
118
|
end
|
|
127
119
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
require 'models/topic'
|
|
120
|
+
require "models/topic"
|
|
132
121
|
class AttributeMethodsTest < ActiveRecord::TestCase
|
|
133
122
|
# Use IFF for boolean statement in SELECT
|
|
134
123
|
coerce_tests! %r{typecast attribute from select to false}
|
|
135
124
|
def test_typecast_attribute_from_select_to_false_coerced
|
|
136
|
-
Topic.create(:title =>
|
|
125
|
+
Topic.create(:title => "Budget")
|
|
137
126
|
topic = Topic.all.merge!(:select => "topics.*, IIF (1 = 2, 1, 0) as is_test").first
|
|
138
127
|
assert_not_predicate topic, :is_test?
|
|
139
128
|
end
|
|
@@ -141,21 +130,18 @@ class AttributeMethodsTest < ActiveRecord::TestCase
|
|
|
141
130
|
# Use IFF for boolean statement in SELECT
|
|
142
131
|
coerce_tests! %r{typecast attribute from select to true}
|
|
143
132
|
def test_typecast_attribute_from_select_to_true_coerced
|
|
144
|
-
Topic.create(:title =>
|
|
133
|
+
Topic.create(:title => "Budget")
|
|
145
134
|
topic = Topic.all.merge!(:select => "topics.*, IIF (1 = 1, 1, 0) as is_test").first
|
|
146
135
|
assert_predicate topic, :is_test?
|
|
147
136
|
end
|
|
148
137
|
end
|
|
149
138
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
139
|
class BasicsTest < ActiveRecord::TestCase
|
|
154
140
|
# Use square brackets as SQL Server escaped character
|
|
155
141
|
coerce_tests! :test_column_names_are_escaped
|
|
156
142
|
def test_column_names_are_escaped_coerced
|
|
157
143
|
conn = ActiveRecord::Base.connection
|
|
158
|
-
assert_equal
|
|
144
|
+
assert_equal "[t]]]", conn.quote_column_name("t]")
|
|
159
145
|
end
|
|
160
146
|
|
|
161
147
|
# Just like PostgreSQLAdapter does.
|
|
@@ -175,7 +161,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
175
161
|
end
|
|
176
162
|
|
|
177
163
|
def test_update_date_time_attributes_with_default_timezone_local
|
|
178
|
-
with_env_tz
|
|
164
|
+
with_env_tz "America/New_York" do
|
|
179
165
|
with_timezone_config default: :local do
|
|
180
166
|
Time.use_zone("Eastern Time (US & Canada)") do
|
|
181
167
|
topic = Topic.find(1)
|
|
@@ -200,9 +186,6 @@ class BasicsTest < ActiveRecord::TestCase
|
|
|
200
186
|
end
|
|
201
187
|
end
|
|
202
188
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
189
|
class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
207
190
|
# Since @client.firm is a single first/top, and we use FETCH the order clause is used.
|
|
208
191
|
coerce_tests! :test_belongs_to_does_not_use_order_by
|
|
@@ -227,9 +210,6 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
|
|
|
227
210
|
end
|
|
228
211
|
end
|
|
229
212
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
213
|
module ActiveRecord
|
|
234
214
|
class BindParameterTest < ActiveRecord::TestCase
|
|
235
215
|
# Same as original coerced test except log is found using `EXEC sp_executesql` wrapper.
|
|
@@ -257,9 +237,6 @@ module ActiveRecord
|
|
|
257
237
|
end
|
|
258
238
|
end
|
|
259
239
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
240
|
module ActiveRecord
|
|
264
241
|
class InstrumentationTest < ActiveRecord::TestCase
|
|
265
242
|
# Fix randomly failing test. The loading of the model's schema was affecting the test.
|
|
@@ -271,9 +248,6 @@ module ActiveRecord
|
|
|
271
248
|
end
|
|
272
249
|
end
|
|
273
250
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
251
|
class CalculationsTest < ActiveRecord::TestCase
|
|
278
252
|
# Fix randomly failing test. The loading of the model's schema was affecting the test.
|
|
279
253
|
coerce_tests! :test_offset_is_kept
|
|
@@ -286,7 +260,7 @@ class CalculationsTest < ActiveRecord::TestCase
|
|
|
286
260
|
coerce_tests! :test_should_return_decimal_average_of_integer_field
|
|
287
261
|
def test_should_return_decimal_average_of_integer_field_coerced
|
|
288
262
|
value = Account.average(:id)
|
|
289
|
-
assert_equal BigDecimal(
|
|
263
|
+
assert_equal BigDecimal("3.0").to_s, BigDecimal(value).to_s
|
|
290
264
|
end
|
|
291
265
|
|
|
292
266
|
# Match SQL Server limit implementation
|
|
@@ -317,9 +291,6 @@ class CalculationsTest < ActiveRecord::TestCase
|
|
|
317
291
|
coerce_tests! :test_having_with_strong_parameters
|
|
318
292
|
end
|
|
319
293
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
294
|
module ActiveRecord
|
|
324
295
|
class Migration
|
|
325
296
|
class ChangeSchemaTest < ActiveRecord::TestCase
|
|
@@ -351,9 +322,6 @@ module ActiveRecord
|
|
|
351
322
|
end
|
|
352
323
|
end
|
|
353
324
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
325
|
module ActiveRecord
|
|
358
326
|
module ConnectionAdapters
|
|
359
327
|
class QuoteARBaseTest < ActiveRecord::TestCase
|
|
@@ -361,22 +329,19 @@ module ActiveRecord
|
|
|
361
329
|
coerce_tests! :test_quote_ar_object
|
|
362
330
|
def test_quote_ar_object_coerced
|
|
363
331
|
value = DatetimePrimaryKey.new(id: @time)
|
|
364
|
-
assert_equal "'02-14-2017 12:34:56.79'",
|
|
332
|
+
assert_equal "'02-14-2017 12:34:56.79'", @connection.quote(value)
|
|
365
333
|
end
|
|
366
334
|
|
|
367
335
|
# Use our date format.
|
|
368
336
|
coerce_tests! :test_type_cast_ar_object
|
|
369
337
|
def test_type_cast_ar_object_coerced
|
|
370
338
|
value = DatetimePrimaryKey.new(id: @time)
|
|
371
|
-
assert_equal "02-14-2017 12:34:56.79",
|
|
339
|
+
assert_equal "02-14-2017 12:34:56.79", @connection.type_cast(value)
|
|
372
340
|
end
|
|
373
341
|
end
|
|
374
342
|
end
|
|
375
343
|
end
|
|
376
344
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
345
|
module ActiveRecord
|
|
381
346
|
class Migration
|
|
382
347
|
class ColumnAttributesTest < ActiveRecord::TestCase
|
|
@@ -391,16 +356,13 @@ module ActiveRecord
|
|
|
391
356
|
end
|
|
392
357
|
end
|
|
393
358
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
359
|
module ActiveRecord
|
|
398
360
|
class Migration
|
|
399
361
|
class ColumnsTest < ActiveRecord::TestCase
|
|
400
362
|
# Our defaults are real 70000 integers vs '70000' strings.
|
|
401
363
|
coerce_tests! :test_rename_column_preserves_default_value_not_null
|
|
402
364
|
def test_rename_column_preserves_default_value_not_null_coerced
|
|
403
|
-
add_column
|
|
365
|
+
add_column "test_models", "salary", :integer, :default => 70000
|
|
404
366
|
default_before = connection.columns("test_models").find { |c| c.name == "salary" }.default
|
|
405
367
|
assert_equal 70000, default_before
|
|
406
368
|
rename_column "test_models", "salary", "annual_salary"
|
|
@@ -416,9 +378,9 @@ module ActiveRecord
|
|
|
416
378
|
add_column "test_models", :hat_size, :integer
|
|
417
379
|
add_column "test_models", :hat_style, :string, :limit => 100
|
|
418
380
|
add_index "test_models", ["hat_style", "hat_size"], :unique => true
|
|
419
|
-
assert_equal 1, connection.indexes(
|
|
381
|
+
assert_equal 1, connection.indexes("test_models").size
|
|
420
382
|
remove_column("test_models", "hat_size")
|
|
421
|
-
assert_equal [], connection.indexes(
|
|
383
|
+
assert_equal [], connection.indexes("test_models").map(&:name)
|
|
422
384
|
end
|
|
423
385
|
|
|
424
386
|
# Choose `StatementInvalid` vs `ActiveRecordError`.
|
|
@@ -433,9 +395,6 @@ module ActiveRecord
|
|
|
433
395
|
end
|
|
434
396
|
end
|
|
435
397
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
398
|
class MigrationTest < ActiveRecord::TestCase
|
|
440
399
|
# We do not have do the DecimalWithoutScale type.
|
|
441
400
|
coerce_tests! :test_add_table_with_decimals
|
|
@@ -459,7 +418,7 @@ class MigrationTest < ActiveRecord::TestCase
|
|
|
459
418
|
assert_not_nil b.my_house_population
|
|
460
419
|
assert_not_nil b.value_of_e
|
|
461
420
|
assert_kind_of BigDecimal, b.world_population
|
|
462
|
-
assert_equal
|
|
421
|
+
assert_equal "6000000000.0", b.world_population.to_s
|
|
463
422
|
assert_kind_of Integer, b.my_house_population
|
|
464
423
|
assert_equal 3, b.my_house_population
|
|
465
424
|
assert_kind_of BigDecimal, b.bank_balance
|
|
@@ -475,9 +434,6 @@ class MigrationTest < ActiveRecord::TestCase
|
|
|
475
434
|
coerce_tests! :test_internal_metadata_stores_environment
|
|
476
435
|
end
|
|
477
436
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
437
|
class CoreTest < ActiveRecord::TestCase
|
|
482
438
|
# I think fixtures are using the wrong time zone and the `:first`
|
|
483
439
|
# `topics`.`bonus_time` attribute of 2005-01-30t15:28:00.00+01:00 is
|
|
@@ -485,9 +441,6 @@ class CoreTest < ActiveRecord::TestCase
|
|
|
485
441
|
coerce_tests! :test_pretty_print_persisted
|
|
486
442
|
end
|
|
487
443
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
444
|
module ActiveRecord
|
|
492
445
|
module ConnectionAdapters
|
|
493
446
|
# Just like PostgreSQLAdapter does.
|
|
@@ -501,23 +454,26 @@ module ActiveRecord
|
|
|
501
454
|
end
|
|
502
455
|
end
|
|
503
456
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
457
|
module ActiveRecord
|
|
508
458
|
# The original module is hardcoded for PostgreSQL/SQLite/MySQL tests.
|
|
509
459
|
module DatabaseTasksSetupper
|
|
510
460
|
def setup
|
|
511
461
|
@sqlserver_tasks =
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
462
|
+
Class.new do
|
|
463
|
+
def create; end
|
|
464
|
+
|
|
465
|
+
def drop; end
|
|
466
|
+
|
|
467
|
+
def purge; end
|
|
468
|
+
|
|
469
|
+
def charset; end
|
|
470
|
+
|
|
471
|
+
def collation; end
|
|
472
|
+
|
|
473
|
+
def structure_dump(*); end
|
|
474
|
+
|
|
475
|
+
def structure_load(*); end
|
|
476
|
+
end.new
|
|
521
477
|
|
|
522
478
|
$stdout, @original_stdout = StringIO.new, $stdout
|
|
523
479
|
$stderr, @original_stderr = StringIO.new, $stderr
|
|
@@ -580,7 +536,6 @@ module ActiveRecord
|
|
|
580
536
|
end
|
|
581
537
|
end
|
|
582
538
|
end
|
|
583
|
-
|
|
584
539
|
end
|
|
585
540
|
|
|
586
541
|
class DatabaseTasksCollationTest < ActiveRecord::TestCase
|
|
@@ -603,8 +558,8 @@ module ActiveRecord
|
|
|
603
558
|
def test_sqlserver_structure_dump
|
|
604
559
|
with_stubbed_new do
|
|
605
560
|
assert_called_with(
|
|
606
|
-
|
|
607
|
-
|
|
561
|
+
eval("@sqlserver_tasks"), :structure_dump,
|
|
562
|
+
["awesome-file.sql", nil]
|
|
608
563
|
) do
|
|
609
564
|
ActiveRecord::Tasks::DatabaseTasks.structure_dump({ "adapter" => :sqlserver }, "awesome-file.sql")
|
|
610
565
|
end
|
|
@@ -619,9 +574,9 @@ module ActiveRecord
|
|
|
619
574
|
def test_sqlserver_structure_load
|
|
620
575
|
with_stubbed_new do
|
|
621
576
|
assert_called_with(
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
577
|
+
eval("@sqlserver_tasks"),
|
|
578
|
+
:structure_load,
|
|
579
|
+
["awesome-file.sql", nil]
|
|
625
580
|
) do
|
|
626
581
|
ActiveRecord::Tasks::DatabaseTasks.structure_load({ "adapter" => :sqlserver }, "awesome-file.sql")
|
|
627
582
|
end
|
|
@@ -631,7 +586,7 @@ module ActiveRecord
|
|
|
631
586
|
|
|
632
587
|
class DatabaseTasksDumpSchemaCacheTest < ActiveRecord::TestCase
|
|
633
588
|
# Skip this test with /tmp/my_schema_cache.yml path on Windows.
|
|
634
|
-
coerce_tests! :test_dump_schema_cache if RbConfig::CONFIG[
|
|
589
|
+
coerce_tests! :test_dump_schema_cache if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
|
|
635
590
|
end
|
|
636
591
|
|
|
637
592
|
class DatabaseTasksCreateAllTest < ActiveRecord::TestCase
|
|
@@ -645,9 +600,6 @@ module ActiveRecord
|
|
|
645
600
|
end
|
|
646
601
|
end
|
|
647
602
|
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
603
|
class DefaultScopingTest < ActiveRecord::TestCase
|
|
652
604
|
# We are not doing order duplicate removal anymore.
|
|
653
605
|
coerce_tests! :test_order_in_default_scope_should_not_prevail
|
|
@@ -661,16 +613,13 @@ class DefaultScopingTest < ActiveRecord::TestCase
|
|
|
661
613
|
end
|
|
662
614
|
end
|
|
663
615
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
require 'models/post'
|
|
668
|
-
require 'models/subscriber'
|
|
616
|
+
require "models/post"
|
|
617
|
+
require "models/subscriber"
|
|
669
618
|
class EachTest < ActiveRecord::TestCase
|
|
670
619
|
# Quoting in tests does not cope with bracket quoting.
|
|
671
620
|
coerce_tests! :test_find_in_batches_should_quote_batch_order
|
|
672
621
|
def test_find_in_batches_should_quote_batch_order_coerced
|
|
673
|
-
|
|
622
|
+
Post.connection
|
|
674
623
|
assert_sql(/ORDER BY \[posts\]\.\[id\]/) do
|
|
675
624
|
Post.find_in_batches(:batch_size => 1) do |batch|
|
|
676
625
|
assert_kind_of Array, batch
|
|
@@ -682,7 +631,7 @@ class EachTest < ActiveRecord::TestCase
|
|
|
682
631
|
# Quoting in tests does not cope with bracket quoting.
|
|
683
632
|
coerce_tests! :test_in_batches_should_quote_batch_order
|
|
684
633
|
def test_in_batches_should_quote_batch_order_coerced
|
|
685
|
-
|
|
634
|
+
Post.connection
|
|
686
635
|
assert_sql(/ORDER BY \[posts\]\.\[id\]/) do
|
|
687
636
|
Post.in_batches(of: 1) do |relation|
|
|
688
637
|
assert_kind_of ActiveRecord::Relation, relation
|
|
@@ -692,9 +641,6 @@ class EachTest < ActiveRecord::TestCase
|
|
|
692
641
|
end
|
|
693
642
|
end
|
|
694
643
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
644
|
class EagerAssociationTest < ActiveRecord::TestCase
|
|
699
645
|
# Use LEN() vs length() function.
|
|
700
646
|
coerce_tests! :test_count_with_include
|
|
@@ -706,10 +652,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
|
|
|
706
652
|
coerce_tests! %r{including association based on sql condition and no database column}
|
|
707
653
|
end
|
|
708
654
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
require 'models/topic'
|
|
655
|
+
require "models/topic"
|
|
713
656
|
class FinderTest < ActiveRecord::TestCase
|
|
714
657
|
# We have implicit ordering, via FETCH.
|
|
715
658
|
coerce_tests! %r{doesn't have implicit ordering},
|
|
@@ -737,7 +680,7 @@ class FinderTest < ActiveRecord::TestCase
|
|
|
737
680
|
# Can not use array condition due to not finding right type and hence fractional second quoting.
|
|
738
681
|
coerce_tests! :test_condition_utc_time_interpolation_with_default_timezone_local
|
|
739
682
|
def test_condition_utc_time_interpolation_with_default_timezone_local_coerced
|
|
740
|
-
with_env_tz
|
|
683
|
+
with_env_tz "America/New_York" do
|
|
741
684
|
with_timezone_config default: :local do
|
|
742
685
|
topic = Topic.first
|
|
743
686
|
assert_equal topic, Topic.where(written_on: topic.written_on.getutc).first
|
|
@@ -748,7 +691,7 @@ class FinderTest < ActiveRecord::TestCase
|
|
|
748
691
|
# Can not use array condition due to not finding right type and hence fractional second quoting.
|
|
749
692
|
coerce_tests! :test_condition_local_time_interpolation_with_default_timezone_utc
|
|
750
693
|
def test_condition_local_time_interpolation_with_default_timezone_utc_coerced
|
|
751
|
-
with_env_tz
|
|
694
|
+
with_env_tz "America/New_York" do
|
|
752
695
|
with_timezone_config default: :utc do
|
|
753
696
|
topic = Topic.first
|
|
754
697
|
assert_equal topic, Topic.where(written_on: topic.written_on.getlocal).first
|
|
@@ -757,9 +700,6 @@ class FinderTest < ActiveRecord::TestCase
|
|
|
757
700
|
end
|
|
758
701
|
end
|
|
759
702
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
703
|
module ActiveRecord
|
|
764
704
|
class Migration
|
|
765
705
|
class ForeignKeyTest < ActiveRecord::TestCase
|
|
@@ -777,9 +717,6 @@ module ActiveRecord
|
|
|
777
717
|
end
|
|
778
718
|
end
|
|
779
719
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
720
|
class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
784
721
|
# We use OFFSET/FETCH vs TOP. So we always have an order.
|
|
785
722
|
coerce_tests! :test_has_one_does_not_use_order_by
|
|
@@ -796,9 +733,6 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
|
|
|
796
733
|
end
|
|
797
734
|
end
|
|
798
735
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
736
|
class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
|
803
737
|
# Asserted SQL to get one row different from original test.
|
|
804
738
|
coerce_tests! :test_has_one_through_executes_limited_query
|
|
@@ -810,16 +744,12 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
|
|
|
810
744
|
end
|
|
811
745
|
end
|
|
812
746
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
require 'models/company'
|
|
747
|
+
require "models/company"
|
|
818
748
|
class InheritanceTest < ActiveRecord::TestCase
|
|
819
749
|
# Rails test required inserting to a identity column.
|
|
820
750
|
coerce_tests! :test_a_bad_type_column
|
|
821
751
|
def test_a_bad_type_column_coerced
|
|
822
|
-
Company.connection.with_identity_insert_enabled(
|
|
752
|
+
Company.connection.with_identity_insert_enabled("companies") do
|
|
823
753
|
Company.connection.insert "INSERT INTO companies (id, #{QUOTED_TYPE}, name) VALUES(100, 'bad_class!', 'Not happening')"
|
|
824
754
|
end
|
|
825
755
|
assert_raise(ActiveRecord::SubclassNotFound) { Company.find(100) }
|
|
@@ -828,45 +758,36 @@ class InheritanceTest < ActiveRecord::TestCase
|
|
|
828
758
|
# Use Square brackets around column name
|
|
829
759
|
coerce_tests! :test_eager_load_belongs_to_primary_key_quoting
|
|
830
760
|
def test_eager_load_belongs_to_primary_key_quoting_coerced
|
|
831
|
-
|
|
761
|
+
Account.connection
|
|
832
762
|
assert_sql(/\[companies\]\.\[id\] = @0.* @0 = 1/) do
|
|
833
763
|
Account.all.merge!(:includes => :firm).find(1)
|
|
834
764
|
end
|
|
835
765
|
end
|
|
836
766
|
end
|
|
837
767
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
768
|
class LeftOuterJoinAssociationTest < ActiveRecord::TestCase
|
|
842
769
|
# Uses || operator in SQL. Just trust core gets value out of this test.
|
|
843
770
|
coerce_tests! :test_does_not_override_select
|
|
844
771
|
end
|
|
845
772
|
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
require 'models/developer'
|
|
850
|
-
require 'models/computer'
|
|
773
|
+
require "models/developer"
|
|
774
|
+
require "models/computer"
|
|
851
775
|
class NestedRelationScopingTest < ActiveRecord::TestCase
|
|
852
776
|
# Assert SQL Server limit implementation
|
|
853
777
|
coerce_tests! :test_merge_options
|
|
854
778
|
def test_merge_options_coerced
|
|
855
|
-
Developer.where(
|
|
779
|
+
Developer.where("salary = 80000").scoping do
|
|
856
780
|
Developer.limit(10).scoping do
|
|
857
781
|
devs = Developer.all
|
|
858
782
|
sql = devs.to_sql
|
|
859
|
-
assert_match
|
|
860
|
-
assert_match
|
|
783
|
+
assert_match "(salary = 80000)", sql
|
|
784
|
+
assert_match "FETCH NEXT 10 ROWS ONLY", sql
|
|
861
785
|
end
|
|
862
786
|
end
|
|
863
787
|
end
|
|
864
788
|
end
|
|
865
789
|
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
require 'models/topic'
|
|
790
|
+
require "models/topic"
|
|
870
791
|
class PersistenceTest < ActiveRecord::TestCase
|
|
871
792
|
# Rails test required updating a identity column.
|
|
872
793
|
coerce_tests! :test_update_columns_changing_id
|
|
@@ -890,10 +811,7 @@ class PersistenceTest < ActiveRecord::TestCase
|
|
|
890
811
|
end
|
|
891
812
|
end
|
|
892
813
|
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
require 'models/author'
|
|
814
|
+
require "models/author"
|
|
897
815
|
class UpdateAllTest < ActiveRecord::TestCase
|
|
898
816
|
# Rails test required updating a identity column.
|
|
899
817
|
coerce_tests! :test_update_all_doesnt_ignore_order
|
|
@@ -903,17 +821,14 @@ class UpdateAllTest < ActiveRecord::TestCase
|
|
|
903
821
|
_(mary.id).must_equal 2
|
|
904
822
|
_(david.name).wont_equal mary.name
|
|
905
823
|
assert_sql(/UPDATE.*\(SELECT \[authors\].\[id\] FROM \[authors\].*ORDER BY \[authors\].\[id\]/i) do
|
|
906
|
-
Author.where(
|
|
824
|
+
Author.where("[id] > 1").order(:id).update_all(name: "Test")
|
|
907
825
|
end
|
|
908
|
-
_(david.reload.name).must_equal
|
|
909
|
-
_(mary.reload.name).must_equal
|
|
826
|
+
_(david.reload.name).must_equal "David"
|
|
827
|
+
_(mary.reload.name).must_equal "Test"
|
|
910
828
|
end
|
|
911
829
|
end
|
|
912
830
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
require 'models/topic'
|
|
831
|
+
require "models/topic"
|
|
917
832
|
module ActiveRecord
|
|
918
833
|
class PredicateBuilderTest < ActiveRecord::TestCase
|
|
919
834
|
# Same as original test except string has `N` prefix to indicate unicode string.
|
|
@@ -930,9 +845,6 @@ module ActiveRecord
|
|
|
930
845
|
end
|
|
931
846
|
end
|
|
932
847
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
848
|
class PrimaryKeysTest < ActiveRecord::TestCase
|
|
937
849
|
# SQL Server does not have query for release_savepoint
|
|
938
850
|
coerce_tests! :test_create_without_primary_key_no_extra_query
|
|
@@ -945,10 +857,7 @@ class PrimaryKeysTest < ActiveRecord::TestCase
|
|
|
945
857
|
end
|
|
946
858
|
end
|
|
947
859
|
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
require 'models/task'
|
|
860
|
+
require "models/task"
|
|
952
861
|
class QueryCacheTest < ActiveRecord::TestCase
|
|
953
862
|
# SQL Server adapter not in list of supported adapters in original test.
|
|
954
863
|
coerce_tests! :test_cache_does_not_wrap_results_in_arrays
|
|
@@ -980,15 +889,12 @@ class QueryCacheTest < ActiveRecord::TestCase
|
|
|
980
889
|
Task.find(1)
|
|
981
890
|
end
|
|
982
891
|
|
|
983
|
-
assert_includes ActiveRecord::SQLCounter.log_all.first
|
|
892
|
+
assert_includes ActiveRecord::SQLCounter.log_all.first, "TC.CONSTRAINT_TYPE = N''PRIMARY KEY''"
|
|
984
893
|
end
|
|
985
894
|
end
|
|
986
895
|
end
|
|
987
896
|
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
require 'models/post'
|
|
897
|
+
require "models/post"
|
|
992
898
|
class RelationTest < ActiveRecord::TestCase
|
|
993
899
|
# Use LEN vs LENGTH function.
|
|
994
900
|
coerce_tests! :test_reverse_order_with_function
|
|
@@ -1029,7 +935,6 @@ class RelationTest < ActiveRecord::TestCase
|
|
|
1029
935
|
assert sql_log.all? { |sql| /order by \[posts\]\.\[id\]/i.match?(sql) }, "default ORDER BY ID was not used in the query: #{sql_log}"
|
|
1030
936
|
end
|
|
1031
937
|
|
|
1032
|
-
|
|
1033
938
|
# We are not doing order duplicate removal anymore.
|
|
1034
939
|
coerce_tests! :test_order_using_scoping
|
|
1035
940
|
|
|
@@ -1055,7 +960,7 @@ class RelationTest < ActiveRecord::TestCase
|
|
|
1055
960
|
|
|
1056
961
|
# Can't apply offset without ORDER
|
|
1057
962
|
coerce_tests! %r{using a custom table affects the wheres}
|
|
1058
|
-
test
|
|
963
|
+
test "using a custom table affects the wheres coerced" do
|
|
1059
964
|
post = posts(:welcome)
|
|
1060
965
|
|
|
1061
966
|
assert_equal post, custom_post_relation.where!(title: post.title).order(:id).take
|
|
@@ -1063,7 +968,7 @@ class RelationTest < ActiveRecord::TestCase
|
|
|
1063
968
|
|
|
1064
969
|
# Can't apply offset without ORDER
|
|
1065
970
|
coerce_tests! %r{using a custom table with joins affects the joins}
|
|
1066
|
-
test
|
|
971
|
+
test "using a custom table with joins affects the joins coerced" do
|
|
1067
972
|
post = posts(:welcome)
|
|
1068
973
|
|
|
1069
974
|
assert_equal post, custom_post_relation.joins(:author).where!(title: post.title).order(:id).take
|
|
@@ -1077,10 +982,7 @@ class RelationTest < ActiveRecord::TestCase
|
|
|
1077
982
|
end
|
|
1078
983
|
end
|
|
1079
984
|
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
require 'models/post'
|
|
985
|
+
require "models/post"
|
|
1084
986
|
class SanitizeTest < ActiveRecord::TestCase
|
|
1085
987
|
# Use nvarchar string (N'') in assert
|
|
1086
988
|
coerce_tests! :test_sanitize_sql_like_example_use_case
|
|
@@ -1090,7 +992,7 @@ class SanitizeTest < ActiveRecord::TestCase
|
|
|
1090
992
|
where("title LIKE ?", sanitize_sql_like(term, "!"))
|
|
1091
993
|
end
|
|
1092
994
|
|
|
1093
|
-
scope :search_as_scope, ->
|
|
995
|
+
scope :search_as_scope, ->(term) {
|
|
1094
996
|
where("title LIKE ?", sanitize_sql_like(term, "!"))
|
|
1095
997
|
}
|
|
1096
998
|
end
|
|
@@ -1105,9 +1007,6 @@ class SanitizeTest < ActiveRecord::TestCase
|
|
|
1105
1007
|
end
|
|
1106
1008
|
end
|
|
1107
1009
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
1010
|
class SchemaDumperTest < ActiveRecord::TestCase
|
|
1112
1011
|
# We have precision to 38.
|
|
1113
1012
|
coerce_tests! :test_schema_dump_keeps_large_precision_integer_columns_as_decimal
|
|
@@ -1134,26 +1033,17 @@ class SchemaDumperTest < ActiveRecord::TestCase
|
|
|
1134
1033
|
end
|
|
1135
1034
|
end
|
|
1136
1035
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
1036
|
class SchemaDumperDefaultsTest < ActiveRecord::TestCase
|
|
1141
1037
|
# These date formats do not match ours. We got these covered in our dumper tests.
|
|
1142
1038
|
coerce_tests! :test_schema_dump_defaults_with_universally_supported_types
|
|
1143
1039
|
end
|
|
1144
1040
|
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
1041
|
class TestAdapterWithInvalidConnection < ActiveRecord::TestCase
|
|
1149
1042
|
# We trust Rails on this since we do not want to install mysql.
|
|
1150
1043
|
coerce_tests! %r{inspect on Model class does not raise}
|
|
1151
1044
|
end
|
|
1152
1045
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
require 'models/topic'
|
|
1046
|
+
require "models/topic"
|
|
1157
1047
|
class TransactionTest < ActiveRecord::TestCase
|
|
1158
1048
|
# SQL Server does not have query for release_savepoint
|
|
1159
1049
|
coerce_tests! :test_releasing_named_savepoints
|
|
@@ -1167,10 +1057,7 @@ class TransactionTest < ActiveRecord::TestCase
|
|
|
1167
1057
|
end
|
|
1168
1058
|
end
|
|
1169
1059
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
require 'models/tag'
|
|
1060
|
+
require "models/tag"
|
|
1174
1061
|
class TransactionIsolationTest < ActiveRecord::TestCase
|
|
1175
1062
|
# SQL Server will lock the table for counts even when both
|
|
1176
1063
|
# connections are `READ COMMITTED`. So we bypass with `READPAST`.
|
|
@@ -1180,7 +1067,7 @@ class TransactionIsolationTest < ActiveRecord::TestCase
|
|
|
1180
1067
|
assert_equal 0, Tag.count
|
|
1181
1068
|
Tag2.transaction do
|
|
1182
1069
|
Tag2.create
|
|
1183
|
-
assert_equal 0, Tag.lock(
|
|
1070
|
+
assert_equal 0, Tag.lock("WITH(READPAST)").count
|
|
1184
1071
|
end
|
|
1185
1072
|
end
|
|
1186
1073
|
assert_equal 1, Tag.count
|
|
@@ -1190,10 +1077,7 @@ class TransactionIsolationTest < ActiveRecord::TestCase
|
|
|
1190
1077
|
coerce_tests! %r{repeatable read}
|
|
1191
1078
|
end
|
|
1192
1079
|
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
require 'models/book'
|
|
1080
|
+
require "models/book"
|
|
1197
1081
|
class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
|
|
1198
1082
|
# We have a few view tables. use includes vs equality.
|
|
1199
1083
|
coerce_tests! :test_views
|
|
@@ -1205,13 +1089,10 @@ class ViewWithPrimaryKeyTest < ActiveRecord::TestCase
|
|
|
1205
1089
|
coerce_tests! :test_does_not_assume_id_column_as_primary_key
|
|
1206
1090
|
def test_does_not_assume_id_column_as_primary_key_coerced
|
|
1207
1091
|
model = Class.new(ActiveRecord::Base) { self.table_name = "ebooks" }
|
|
1208
|
-
assert_equal
|
|
1092
|
+
assert_equal "id", model.primary_key
|
|
1209
1093
|
end
|
|
1210
1094
|
end
|
|
1211
1095
|
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
1096
|
class ViewWithoutPrimaryKeyTest < ActiveRecord::TestCase
|
|
1216
1097
|
# We have a few view tables. use includes vs equality.
|
|
1217
1098
|
coerce_tests! :test_views
|
|
@@ -1220,23 +1101,17 @@ class ViewWithoutPrimaryKeyTest < ActiveRecord::TestCase
|
|
|
1220
1101
|
end
|
|
1221
1102
|
end
|
|
1222
1103
|
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
require 'models/author'
|
|
1104
|
+
require "models/author"
|
|
1227
1105
|
class YamlSerializationTest < ActiveRecord::TestCase
|
|
1228
1106
|
coerce_tests! :test_types_of_virtual_columns_are_not_changed_on_round_trip
|
|
1229
1107
|
def test_types_of_virtual_columns_are_not_changed_on_round_trip_coerced
|
|
1230
|
-
author = Author.select(
|
|
1108
|
+
author = Author.select("authors.*, 5 as posts_count").first
|
|
1231
1109
|
dumped = YAML.load(YAML.dump(author))
|
|
1232
1110
|
assert_equal 5, author.posts_count
|
|
1233
1111
|
assert_equal 5, dumped.posts_count
|
|
1234
1112
|
end
|
|
1235
1113
|
end
|
|
1236
1114
|
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
1115
|
class DateTimePrecisionTest < ActiveRecord::TestCase
|
|
1241
1116
|
# Original test had `7` which we support vs `8` which we use.
|
|
1242
1117
|
coerce_tests! :test_invalid_datetime_precision_raises_error
|
|
@@ -1252,7 +1127,7 @@ class DateTimePrecisionTest < ActiveRecord::TestCase
|
|
|
1252
1127
|
coerce_tests! :test_datetime_precision_is_truncated_on_assignment
|
|
1253
1128
|
def test_datetime_precision_is_truncated_on_assignment_coerced
|
|
1254
1129
|
@connection.create_table(:foos, force: true)
|
|
1255
|
-
@connection.add_column :foos, :created_at,
|
|
1130
|
+
@connection.add_column :foos, :created_at, :datetime, precision: 0
|
|
1256
1131
|
@connection.add_column :foos, :updated_at, :datetime, precision: 6
|
|
1257
1132
|
|
|
1258
1133
|
time = ::Time.now.change(nsec: 123456789)
|
|
@@ -1269,9 +1144,6 @@ class DateTimePrecisionTest < ActiveRecord::TestCase
|
|
|
1269
1144
|
end
|
|
1270
1145
|
end
|
|
1271
1146
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
1147
|
class TimePrecisionTest < ActiveRecord::TestCase
|
|
1276
1148
|
# datetime is rounded to increments of .000, .003, or .007 seconds
|
|
1277
1149
|
coerce_tests! :test_time_precision_is_truncated_on_assignment
|
|
@@ -1297,9 +1169,6 @@ class TimePrecisionTest < ActiveRecord::TestCase
|
|
|
1297
1169
|
coerce_tests! :test_no_time_precision_isnt_truncated_on_assignment
|
|
1298
1170
|
end
|
|
1299
1171
|
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
1172
|
class DefaultNumbersTest < ActiveRecord::TestCase
|
|
1304
1173
|
# We do better with native types and do not return strings for everything.
|
|
1305
1174
|
coerce_tests! :test_default_positive_integer
|
|
@@ -1326,9 +1195,6 @@ class DefaultNumbersTest < ActiveRecord::TestCase
|
|
|
1326
1195
|
end
|
|
1327
1196
|
end
|
|
1328
1197
|
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
1198
|
module ActiveRecord
|
|
1333
1199
|
class CollectionCacheKeyTest < ActiveRecord::TestCase
|
|
1334
1200
|
# Will trust rails has this sorted since you cant offset without a limit.
|
|
@@ -1336,9 +1202,6 @@ module ActiveRecord
|
|
|
1336
1202
|
end
|
|
1337
1203
|
end
|
|
1338
1204
|
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
1205
|
module ActiveRecord
|
|
1343
1206
|
class CacheKeyTest < ActiveRecord::TestCase
|
|
1344
1207
|
# Like Mysql2 and PostgreSQL, SQL Server doesn't return a string value for updated_at. In the Rails tests
|
|
@@ -1349,9 +1212,6 @@ module ActiveRecord
|
|
|
1349
1212
|
end
|
|
1350
1213
|
end
|
|
1351
1214
|
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
1215
|
require "models/book"
|
|
1356
1216
|
module ActiveRecord
|
|
1357
1217
|
class StatementCacheTest < ActiveRecord::TestCase
|
|
@@ -1370,28 +1230,23 @@ module ActiveRecord
|
|
|
1370
1230
|
end
|
|
1371
1231
|
end
|
|
1372
1232
|
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
1233
|
module ActiveRecord
|
|
1377
1234
|
module ConnectionAdapters
|
|
1378
1235
|
class SchemaCacheTest < ActiveRecord::TestCase
|
|
1379
1236
|
private
|
|
1237
|
+
|
|
1380
1238
|
# We need to give the full path for this to work.
|
|
1381
1239
|
def schema_dump_path
|
|
1382
|
-
File.join ARTest::SQLServer.root_activerecord,
|
|
1240
|
+
File.join ARTest::SQLServer.root_activerecord, "test/assets/schema_dump_5_1.yml"
|
|
1383
1241
|
end
|
|
1384
1242
|
end
|
|
1385
1243
|
end
|
|
1386
1244
|
end
|
|
1387
1245
|
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
1246
|
class UnsafeRawSqlTest < ActiveRecord::TestCase
|
|
1392
|
-
|
|
1247
|
+
# Use LEN() vs length() function.
|
|
1393
1248
|
coerce_tests! %r{order: always allows Arel}
|
|
1394
|
-
test
|
|
1249
|
+
test "order: always allows Arel" do
|
|
1395
1250
|
ids_depr = with_unsafe_raw_sql_deprecated { Post.order(Arel.sql("len(title)")).pluck(:title) }
|
|
1396
1251
|
ids_disabled = with_unsafe_raw_sql_disabled { Post.order(Arel.sql("len(title)")).pluck(:title) }
|
|
1397
1252
|
|
|
@@ -1420,9 +1275,6 @@ class UnsafeRawSqlTest < ActiveRecord::TestCase
|
|
|
1420
1275
|
end
|
|
1421
1276
|
end
|
|
1422
1277
|
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
1278
|
class ReservedWordTest < ActiveRecord::TestCase
|
|
1427
1279
|
coerce_tests! :test_change_columns
|
|
1428
1280
|
def test_change_columns_coerced
|
|
@@ -1433,33 +1285,27 @@ class ReservedWordTest < ActiveRecord::TestCase
|
|
|
1433
1285
|
end
|
|
1434
1286
|
end
|
|
1435
1287
|
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
1288
|
class OptimisticLockingTest < ActiveRecord::TestCase
|
|
1440
1289
|
# We do not allow updating identities, but we can test using a non-identity key
|
|
1441
1290
|
coerce_tests! :test_update_with_dirty_primary_key
|
|
1442
1291
|
def test_update_with_dirty_primary_key_coerced
|
|
1443
1292
|
assert_raises(ActiveRecord::RecordNotUnique) do
|
|
1444
|
-
record = StringKeyObject.find(
|
|
1445
|
-
record.id =
|
|
1293
|
+
record = StringKeyObject.find("record1")
|
|
1294
|
+
record.id = "record2"
|
|
1446
1295
|
record.save!
|
|
1447
1296
|
end
|
|
1448
1297
|
|
|
1449
|
-
record = StringKeyObject.find(
|
|
1450
|
-
record.id =
|
|
1298
|
+
record = StringKeyObject.find("record1")
|
|
1299
|
+
record.id = "record42"
|
|
1451
1300
|
record.save!
|
|
1452
1301
|
|
|
1453
|
-
assert StringKeyObject.find(
|
|
1302
|
+
assert StringKeyObject.find("record42")
|
|
1454
1303
|
assert_raises(ActiveRecord::RecordNotFound) do
|
|
1455
|
-
StringKeyObject.find(
|
|
1304
|
+
StringKeyObject.find("record1")
|
|
1456
1305
|
end
|
|
1457
1306
|
end
|
|
1458
1307
|
end
|
|
1459
1308
|
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
1309
|
class RelationMergingTest < ActiveRecord::TestCase
|
|
1464
1310
|
# Use nvarchar string (N'') in assert
|
|
1465
1311
|
coerce_tests! :test_merging_with_order_with_binds
|
|
@@ -1469,9 +1315,6 @@ class RelationMergingTest < ActiveRecord::TestCase
|
|
|
1469
1315
|
end
|
|
1470
1316
|
end
|
|
1471
1317
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
1318
|
module ActiveRecord
|
|
1476
1319
|
class DatabaseTasksTruncateAllTest < ActiveRecord::TestCase
|
|
1477
1320
|
# SQL Server does not allow truncation of tables that are referenced by foreign key
|
|
@@ -1481,9 +1324,6 @@ module ActiveRecord
|
|
|
1481
1324
|
end
|
|
1482
1325
|
end
|
|
1483
1326
|
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
1327
|
require "models/book"
|
|
1488
1328
|
class EnumTest < ActiveRecord::TestCase
|
|
1489
1329
|
# Need to remove index as SQL Server considers NULLs on a unique-index to be equal unlike PostgreSQL/MySQL/SQLite.
|
|
@@ -1527,13 +1367,8 @@ class EnumTest < ActiveRecord::TestCase
|
|
|
1527
1367
|
end
|
|
1528
1368
|
end
|
|
1529
1369
|
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
require 'models/task'
|
|
1370
|
+
require "models/task"
|
|
1535
1371
|
class QueryCacheExpiryTest < ActiveRecord::TestCase
|
|
1536
|
-
|
|
1537
1372
|
# SQL Server does not support skipping or upserting duplicates.
|
|
1538
1373
|
coerce_tests! :test_insert_all
|
|
1539
1374
|
def test_insert_all_coerced
|
|
@@ -1563,9 +1398,7 @@ class QueryCacheExpiryTest < ActiveRecord::TestCase
|
|
|
1563
1398
|
end
|
|
1564
1399
|
end
|
|
1565
1400
|
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
require 'models/citation'
|
|
1401
|
+
require "models/citation"
|
|
1569
1402
|
class EagerLoadingTooManyIdsTest < ActiveRecord::TestCase
|
|
1570
1403
|
# Original Rails test fails with SQL Server error message "The query processor ran out of internal resources and
|
|
1571
1404
|
# could not produce a query plan". This error goes away if you change database compatibility level to 110 (SQL 2012)
|
|
@@ -1587,9 +1420,6 @@ class EagerLoadingTooManyIdsTest < ActiveRecord::TestCase
|
|
|
1587
1420
|
end
|
|
1588
1421
|
end
|
|
1589
1422
|
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
1423
|
class LogSubscriberTest < ActiveRecord::TestCase
|
|
1594
1424
|
# Call original test from coerced test. Fixes issue on CI with Rails installed as a gem.
|
|
1595
1425
|
coerce_tests! :test_vebose_query_logs
|
|
@@ -1598,9 +1428,6 @@ class LogSubscriberTest < ActiveRecord::TestCase
|
|
|
1598
1428
|
end
|
|
1599
1429
|
end
|
|
1600
1430
|
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
1431
|
class ActiveRecordSchemaTest < ActiveRecord::TestCase
|
|
1605
1432
|
# Workaround for randomly failing test.
|
|
1606
1433
|
coerce_tests! :test_has_primary_key
|
|
@@ -1610,9 +1437,6 @@ class ActiveRecordSchemaTest < ActiveRecord::TestCase
|
|
|
1610
1437
|
end
|
|
1611
1438
|
end
|
|
1612
1439
|
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
1440
|
module ActiveRecord
|
|
1617
1441
|
module ConnectionAdapters
|
|
1618
1442
|
class ReaperTest < ActiveRecord::TestCase
|
|
@@ -1622,19 +1446,13 @@ module ActiveRecord
|
|
|
1622
1446
|
end
|
|
1623
1447
|
end
|
|
1624
1448
|
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
1449
|
class FixturesTest < ActiveRecord::TestCase
|
|
1629
1450
|
# Skip test on Windows. Skip can be removed when Rails PR https://github.com/rails/rails/pull/39234 has been merged.
|
|
1630
|
-
coerce_tests! :test_binary_in_fixtures if RbConfig::CONFIG[
|
|
1451
|
+
coerce_tests! :test_binary_in_fixtures if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
|
|
1631
1452
|
end
|
|
1632
1453
|
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
1454
|
class ReloadModelsTest < ActiveRecord::TestCase
|
|
1637
1455
|
# Skip test on Windows. The number of arguements passed to `IO.popen` in
|
|
1638
1456
|
# `activesupport/lib/active_support/testing/isolation.rb` exceeds what Windows can handle.
|
|
1639
|
-
coerce_tests! :test_has_one_with_reload if RbConfig::CONFIG[
|
|
1457
|
+
coerce_tests! :test_has_one_with_reload if RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
|
|
1640
1458
|
end
|