diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb b/activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb index 0fe72e01ea..633d7ddd9e 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb @@ -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 diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 6331c575b3..1fb9815ec6 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -598,6 +598,8 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase t.float :float_with_nan_default, default: Float::NAN t.datetime :beginning_of_time, default: "-infinity" t.datetime :end_of_time, default: "infinity" + t.date :date_with_neg_inf_default, default: -::Float::INFINITY + t.date :date_with_pos_inf_default, default: ::Float::INFINITY end end end @@ -623,5 +625,7 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase 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 + assert_match %r{t\.date\s+"date_with_neg_inf_default",\s+default: -::Float::INFINITY}, output + assert_match %r{t\.date\s+"date_with_pos_inf_default",\s+default: ::Float::INFINITY}, output end end