File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -1474,8 +1474,36 @@ def test_statement_cache_values_differ_coerced
1474
1474
module ActiveRecord
1475
1475
module ConnectionAdapters
1476
1476
class SchemaCacheTest < ActiveRecord ::TestCase
1477
+ # Ruby 2.5 and 2.6 have issues to marshal Time before 1900. 2012.sql has one column with default value 1753
1478
+ coerce_tests! :test_marshal_dump_and_load_with_gzip , :test_marshal_dump_and_load_via_disk
1479
+ def test_marshal_dump_and_load_with_gzip_coerced
1480
+ with_marshable_time_defaults { original_test_marshal_dump_and_load_with_gzip }
1481
+ end
1482
+ def test_marshal_dump_and_load_via_disk_coerced
1483
+ with_marshable_time_defaults { original_test_marshal_dump_and_load_via_disk }
1484
+ end
1485
+
1477
1486
private
1478
1487
1488
+ def with_marshable_time_defaults
1489
+ # Detect problems
1490
+ if Gem ::Version . new ( RUBY_VERSION ) < Gem ::Version . new ( "2.7" )
1491
+ column = @connection . columns ( :sst_datatypes ) . find { |c | c . name == "datetime" }
1492
+ current_default = column . default if column . default . is_a? ( Time ) && column . default . year < 1900
1493
+ end
1494
+
1495
+ # Correct problems
1496
+ if current_default . present?
1497
+ @connection . change_column_default ( :sst_datatypes , :datetime , current_default . dup . change ( year : 1900 ) )
1498
+ end
1499
+
1500
+ # Run original test
1501
+ yield
1502
+ ensure
1503
+ # Revert changes
1504
+ @connection . change_column_default ( :sst_datatypes , :datetime , current_default ) if current_default . present?
1505
+ end
1506
+
1479
1507
# We need to give the full path for this to work.
1480
1508
def schema_dump_path
1481
1509
File . join ARTest ::SQLServer . root_activerecord , "test/assets/schema_dump_5_1.yml"
@@ -1876,5 +1904,3 @@ class BasePreventWritesLegacyTest < ActiveRecord::TestCase
1876
1904
end
1877
1905
end
1878
1906
end
1879
-
1880
-
You can’t perform that action at this time.
0 commit comments