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 @@ -1517,8 +1517,36 @@ def test_statement_cache_values_differ_coerced
1517
1517
module ActiveRecord
1518
1518
module ConnectionAdapters
1519
1519
class SchemaCacheTest < ActiveRecord ::TestCase
1520
+ # Ruby 2.5 and 2.6 have issues to marshal Time before 1900. 2012.sql has one column with default value 1753
1521
+ coerce_tests! :test_marshal_dump_and_load_with_gzip , :test_marshal_dump_and_load_via_disk
1522
+ def test_marshal_dump_and_load_with_gzip_coerced
1523
+ with_marshable_time_defaults { original_test_marshal_dump_and_load_with_gzip }
1524
+ end
1525
+ def test_marshal_dump_and_load_via_disk_coerced
1526
+ with_marshable_time_defaults { original_test_marshal_dump_and_load_via_disk }
1527
+ end
1528
+
1520
1529
private
1521
1530
1531
+ def with_marshable_time_defaults
1532
+ # Detect problems
1533
+ if Gem ::Version . new ( RUBY_VERSION ) < Gem ::Version . new ( "2.7" )
1534
+ column = @connection . columns ( :sst_datatypes ) . find { |c | c . name == "datetime" }
1535
+ current_default = column . default if column . default . is_a? ( Time ) && column . default . year < 1900
1536
+ end
1537
+
1538
+ # Correct problems
1539
+ if current_default . present?
1540
+ @connection . change_column_default ( :sst_datatypes , :datetime , current_default . dup . change ( year : 1900 ) )
1541
+ end
1542
+
1543
+ # Run original test
1544
+ yield
1545
+ ensure
1546
+ # Revert changes
1547
+ @connection . change_column_default ( :sst_datatypes , :datetime , current_default ) if current_default . present?
1548
+ end
1549
+
1522
1550
# We need to give the full path for this to work.
1523
1551
def schema_dump_path
1524
1552
File . join ARTest ::SQLServer . root_activerecord , "test/assets/schema_dump_5_1.yml"
@@ -1919,5 +1947,3 @@ class BasePreventWritesLegacyTest < ActiveRecord::TestCase
1919
1947
end
1920
1948
end
1921
1949
end
1922
-
1923
-
You can’t perform that action at this time.
0 commit comments