1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix schema dumper when datetime infitnity defaults are set

Fixes #40751.
This commit is contained in:
Rafael Mendonça França 2020-12-08 18:09:32 +00:00
parent ef61c9c8a3
commit 6f6cac4c18
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
2 changed files with 13 additions and 1 deletions

View file

@ -16,6 +16,14 @@ module ActiveRecord
super
end
end
def type_cast_for_schema(value)
case value
when ::Float::INFINITY then "::Float::INFINITY"
when -::Float::INFINITY then "-::Float::INFINITY"
else super
end
end
end
end
end

View file

@ -510,6 +510,8 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
@connection.create_table :infinity_defaults, force: true do |t|
t.float :float_with_inf_default, default: Float::INFINITY
t.float :float_with_nan_default, default: Float::NAN
t.datetime :beginning_of_time, default: "-infinity"
t.datetime :end_of_time, default: "infinity"
end
end
end
@ -528,10 +530,12 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
assert_match %r{t\.decimal\s+"decimal_with_default",\s+precision: 20,\s+scale: 10,\s+default: "1234567890.0123456789"}, output
end
def test_schema_dump_with_float_column_infinity_default
def test_schema_dump_with_column_infinity_default
skip unless current_adapter?(:PostgreSQLAdapter)
output = dump_table_schema("infinity_defaults")
assert_match %r{t\.float\s+"float_with_inf_default",\s+default: ::Float::INFINITY}, output
assert_match %r{t\.float\s+"float_with_nan_default",\s+default: ::Float::NAN}, output
assert_match %r{t\.datetime\s+"beginning_of_time",\s+default: -::Float::INFINITY}, output
assert_match %r{t\.datetime\s+"end_of_time",\s+default: ::Float::INFINITY}, output
end
end