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
15171517module ActiveRecord
15181518 module ConnectionAdapters
15191519 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+
15201529 private
15211530
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+
15221550 # We need to give the full path for this to work.
15231551 def schema_dump_path
15241552 File . join ARTest ::SQLServer . root_activerecord , "test/assets/schema_dump_5_1.yml"
@@ -1919,5 +1947,3 @@ class BasePreventWritesLegacyTest < ActiveRecord::TestCase
19191947 end
19201948 end
19211949end
1922-
1923-
You can’t perform that action at this time.
0 commit comments