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
14741474module ActiveRecord
14751475 module ConnectionAdapters
14761476 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+
14771486 private
14781487
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+
14791507 # We need to give the full path for this to work.
14801508 def schema_dump_path
14811509 File . join ARTest ::SQLServer . root_activerecord , "test/assets/schema_dump_5_1.yml"
@@ -1876,5 +1904,3 @@ class BasePreventWritesLegacyTest < ActiveRecord::TestCase
18761904 end
18771905 end
18781906end
1879-
1880-
You can’t perform that action at this time.
0 commit comments