diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-08-19 14:57:05 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-08-24 00:44:02 +0900 |
commit | 47a6d788ddbab08b2a04c72cd80352aac44090ab (patch) | |
tree | a3dbe86af22b7357be32a33a670e408ef1dcad57 /activemodel/test/cases/validations | |
parent | a0b57bbb21ce81071220bd8c6cfd8cdda342c6c6 (diff) | |
download | rails-47a6d788ddbab08b2a04c72cd80352aac44090ab.tar.gz rails-47a6d788ddbab08b2a04c72cd80352aac44090ab.tar.bz2 rails-47a6d788ddbab08b2a04c72cd80352aac44090ab.zip |
Fix numericality validator to still use value before type cast except Active Record
The purpose of fe9547b is to work type casting to value from database.
But that was caused not to use the value before type cast even except
Active Record.
There we never guarantees that the value before type cast was going to
the used in this validation, but we should not change the behavior
unless there is some particular reason.
To restore original behavior, still use the value before type cast if
`came_from_user?` is undefined (i.e. except Active Record).
Fixes #33651.
Fixes #33686.
Diffstat (limited to 'activemodel/test/cases/validations')
-rw-r--r-- | activemodel/test/cases/validations/numericality_validation_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/numericality_validation_test.rb b/activemodel/test/cases/validations/numericality_validation_test.rb index 01b78ae72e..ca3c3bc40d 100644 --- a/activemodel/test/cases/validations/numericality_validation_test.rb +++ b/activemodel/test/cases/validations/numericality_validation_test.rb @@ -262,6 +262,16 @@ class NumericalityValidationTest < ActiveModel::TestCase Person.clear_validators! end + def test_validates_numericality_using_value_before_type_cast_if_possible + Topic.validates_numericality_of :price + + topic = Topic.new(price: 50) + + assert_equal "$50.00", topic.price + assert_equal 50, topic.price_before_type_cast + assert_predicate topic, :valid? + end + def test_validates_numericality_with_exponent_number base = 10_000_000_000_000_000 Topic.validates_numericality_of :approved, less_than_or_equal_to: base |