mirror of https://github.com/rails/rails
Don't mark Float::INFINITY as changed when reassigning it
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
This commit is contained in:
parent
9c8585156e
commit
19869e765e
|
@ -42,7 +42,8 @@ module ActiveModel
|
||||||
end
|
end
|
||||||
|
|
||||||
def number_to_non_number?(old_value, new_value_before_type_cast)
|
def number_to_non_number?(old_value, new_value_before_type_cast)
|
||||||
old_value != nil && non_numeric_string?(new_value_before_type_cast.to_s)
|
old_value != nil && !new_value_before_type_cast.is_a?(::Numeric) &&
|
||||||
|
non_numeric_string?(new_value_before_type_cast.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def non_numeric_string?(value)
|
def non_numeric_string?(value)
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
|
* Don't mark Float::INFINITY as changed when reassigning it
|
||||||
|
|
||||||
|
When saving a record with a float infinite value, it shouldn't mark as changed
|
||||||
|
|
||||||
|
*Maicol Bentancor*
|
||||||
|
|
||||||
* Support `RETURNING` clause for MariaDB
|
* Support `RETURNING` clause for MariaDB
|
||||||
|
|
||||||
*fatkodima*, *Nikolay Kondratyev*
|
*fatkodima*, *Nikolay Kondratyev*
|
||||||
|
|
|
@ -48,4 +48,20 @@ class PostgresqlNumberTest < ActiveRecord::PostgreSQLTestCase
|
||||||
assert_equal new_single, record.single
|
assert_equal new_single, record.single
|
||||||
assert_equal new_double, record.double
|
assert_equal new_double, record.double
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_reassigning_infinity_does_not_mark_record_as_changed
|
||||||
|
record = PostgresqlNumber.create!(single: Float::INFINITY, double: -Float::INFINITY)
|
||||||
|
record.reload
|
||||||
|
record.single = Float::INFINITY
|
||||||
|
record.double = -Float::INFINITY
|
||||||
|
assert_not_predicate record, :changed?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_reassigning_nan_does_not_mark_record_as_changed
|
||||||
|
record = PostgresqlNumber.create!(single: Float::NAN, double: Float::NAN)
|
||||||
|
record.reload
|
||||||
|
record.single = Float::NAN
|
||||||
|
record.double = Float::NAN
|
||||||
|
assert_not_predicate record, :changed?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue