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:
parent
ef61c9c8a3
commit
6f6cac4c18
2 changed files with 13 additions and 1 deletions
|
@ -16,6 +16,14 @@ module ActiveRecord
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -510,6 +510,8 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
|
||||||
@connection.create_table :infinity_defaults, force: true do |t|
|
@connection.create_table :infinity_defaults, force: true do |t|
|
||||||
t.float :float_with_inf_default, default: Float::INFINITY
|
t.float :float_with_inf_default, default: Float::INFINITY
|
||||||
t.float :float_with_nan_default, default: Float::NAN
|
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
|
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
|
assert_match %r{t\.decimal\s+"decimal_with_default",\s+precision: 20,\s+scale: 10,\s+default: "1234567890.0123456789"}, output
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_schema_dump_with_float_column_infinity_default
|
def test_schema_dump_with_column_infinity_default
|
||||||
skip unless current_adapter?(:PostgreSQLAdapter)
|
skip unless current_adapter?(:PostgreSQLAdapter)
|
||||||
output = dump_table_schema("infinity_defaults")
|
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_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\.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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue