aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations/numericality.rb
Commit message (Collapse)AuthorAgeFilesLines
* Do not use deprecated Object#!~ in Ruby 2.6Rafael Mendonça França2018-11-261-1/+5
| | | | Closes #34530.
* Fix numericality validator to still use value before type cast except Active ↵Ryuta Kamizono2018-08-241-4/+11
| | | | | | | | | | | | | | | | | | | 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.
* Fix numericality validator not to be affected by custom getterRyuta Kamizono2018-08-131-0/+2
| | | | | | | | | | | | | | | | | | | | Since fe9547b6, numericality validator would parse raw value only when a value came from user to work type casting to a value from database. But that was caused a regression that the validator would work against getter value instead of parsed raw value, a getter is sometimes customized by people. #33550 There we never guarantees that the value before type cast was going to the used in this validation (actually here is only place that getter value might not be used), but we should not change the behavior unless there is some particular reason. The purpose of fe9547b6 is to work type casting to a value from database. We could achieve the purpose by using `read_attribute`, without using getter value. Fixes #33550.
* Parse raw value only when a value came from user in numericality validatorRyuta Kamizono2018-05-281-2/+4
| | | | | | | | Since `parse_raw_value_as_a_number` may not always parse raw value from database as a number without type casting (e.g. "$150.55" as money format). Fixes #32531.
* Use frozen string literal in activemodel/Kir Shatrov2017-07-161-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Fix regression in Numericality validator where extra decimal places on Bradley Priest2017-05-271-1/+3
| | | a user input for a decimal column were ignored by numerically validations
* Fix regexp in the doc [ci skip]Ryuta Kamizono2017-04-241-1/+1
| | | | Follow up of #17148.
* Avoid converting integer as a string into floatnamusyaka2017-02-181-0/+1
|
* Remove `:doc:` for `NumericalityValidator` [ci skip]Ryuta Kamizono2017-02-171-5/+5
| | | | | | | The `:doc:` was added in cdb9d7f but `NumericalityValidator` is already `:nodoc:` class. `:doc:` is unneeded. https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validations/numericality.rb#L3
* change ActiveModel::Validation to ActiveModel::Validations in commentsSen Zhang2017-02-151-1/+1
|
* Privatize unneededly protected methods in Active ModelAkira Matsuda2016-12-241-12/+10
|
* validate_each in NumericalityValidator is never called in this case.Guillermo Iguaran2016-08-281-2/+0
| | | | | NumericalityValidator#validate_each is never called when allow_nil is true and the value is nil because it is already skipped in EachValidator#validate.
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-4/+4
|
* Support for unified Integer class in Ruby 2.4+Jeremy Daer2016-05-181-1/+1
| | | | | | | | Ruby 2.4 unifies Fixnum and Bignum into Integer: https://bugs.ruby-lang.org/issues/12005 * Forward compat with new unified Integer class in Ruby 2.4+. * Backward compat with separate Fixnum/Bignum in Ruby 2.2 & 2.3. * Drops needless Fixnum distinction in docs, preferring Integer.
* Convert non-`Numeric` values to FloatsRobert Eshleman2015-12-221-1/+1
|
* Fix Regression in Numericality ValidationsRobert Eshleman2015-12-221-2/+9
| | | | | | | | | | | | A regression (#22744) introduced in 7500dae caused certain numericality validations to raise an error when run against an attribute with a string value. Previously, these validations would successfully run against string values because the value was cast to a numeric class. This commit resolves the regression by converting string values to floats before performing numericality comparison validations. [fixes #22744]
* Conditionally convert the raw_value received by the numeric validator.Roque Pinel2015-07-111-12/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes the issue where you may be comparing (using a numeric validator such as `greater_than`) numbers of a specific Numeric type such as `BigDecimal`. Previous behavior took the numeric value to be validated and unconditionally converted to Float. For example, due to floating point precision, this can cause issues when comparing a Float to a BigDecimal. Consider the following: ``` validates :sub_total, numericality: { greater_than: BigDecimal('97.18') } ``` If the `:sub_total` value BigDecimal.new('97.18') was validated against the above, the following would be valid since `:sub_total` is converted to a Float regardless of its original type. The result therefore becomes Kernel.Float(97.18) > BigDecimal.new('97.18') The above illustrated behavior is corrected with this patch by conditionally converting the value to validate to float. Use the post-type-cast version of the attribute to validate numericality [Roque Pinel & Trevor Wistaff]
* Ensure numericality validations work with mutationSean Griffin2014-12-011-0/+11
| | | | | | | | | | | | | | | | | | | | | The detection of in-place changes caused a weird unexpected issue with numericality validations. That validator (out of necessity) works on the `_before_type_cast` version of the attribute, since on an `:integer` type column, a non-numeric string would type cast to 0. However, strings are mutable, and we changed strings to ensure that the post type cast version of the attribute was a different instance than the before type cast version (so the mutation detection can work properly). Even though strings are the only mutable type for which a numericality validation makes sense, special casing strings would feel like a strange change to make here. Instead, we can make the assumption that for all mutable types, we should work on the post-type-cast version of the attribute, since all cases which would return 0 for non-numeric strings are immutable. Fixes #17852
* Disallow appended newlines when parsing as integerMichael Genereux2014-10-021-1/+1
| | | \Z allows appended newlines where \z does not.
* `only_integer` of `NumericalityValidator` now allows procs and symbolsRobin Mehner2014-06-221-1/+13
|
* revises references to :allow_(nil|blank) in some docs [ci skip] [Steven Yang ↵Xavier Noria2014-01-261-1/+1
| | | | | | & Xavier Noria] Closes #11247.
* Make code simpler to read by using a case statementCarlos Antonio da Silva2013-11-151-2/+6
|
* Avoid a new hash allocationCarlos Antonio da Silva2013-11-151-1/+1
|
* Use a simple conditional rather than short circuit with nextCarlos Antonio da Silva2013-11-151-2/+3
|
* Simplify number parsing logic in numericality validationCarlos Antonio da Silva2013-11-151-10/+3
|
* Avoid creation of extra hash with merge just to set a valueCarlos Antonio da Silva2013-11-151-1/+3
|
* Convert ActiveModel to 1.9 hash syntax.Patrick Robertson2013-05-011-5/+5
| | | | | I also attempted to fix other styleguide violations such as { a: :b } over {a: :b} and foo(b: 'bar') over foo( b: 'bar' ).
* Reduce number of Strings a bitAkira Matsuda2013-01-071-2/+2
|
* minor edits and remove mixed titles in AM::Validations docs [ci skip]Francesco Rodriguez2012-10-251-2/+1
|
* minor edits in AM documentation [ci skip]Francesco Rodriguez2012-10-211-2/+2
|
* AM::Validations: remove documentation duplicatesBogdan Gusiev2012-07-101-14/+4
|
* update ActiveModel::Validations::HelperMethods documentation [ci skip]Francesco Rodriguez2012-07-051-24/+26
|
* add :nodoc: to internal implementations [ci skip]Francesco Rodriguez2012-06-251-1/+1
|
* fixing removed empty lines and examplesFrancesco Rodriguez2012-05-161-0/+1
|
* better format and fixes to validators docsFrancesco Rodriguez2012-05-161-19/+32
|
* added :other_than => :!= option to numericality validatorJakub Kuźma2011-12-211-2/+3
|
* Implemented strict validation conceptBogdan Gusiev2011-08-171-0/+2
| | | | | | | In order to deliver debug information to dev team instead of display error message to end user Implemented strict validation concept that suppose to define validation that always raise exception when fails
* Remove extra white spaces on ActiveModel docs.Sebastian Martinez2011-05-231-2/+2
|
* Remove unneeded merge with default false optionsAkira Matsuda2011-05-161-4/+0
|
* copy-edits 8d96b89Xavier Noria2011-02-211-1/+3
|
* Clarification of ActiveRecord ActiveModel validation documentationPeer Allan2011-02-181-1/+1
|
* Don't compute this string againSantiago Pastorino2010-12-021-1/+1
|
* Refactor previous commit a bit [#4057 state:resolved]José Valim2010-06-211-3/+3
|
* Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options ↵Jeroen van Dijk2010-06-211-4/+9
| | | | | | | | | | | | | | | | hash and make various Validators pass their (filtered) options. This makes it possible to pass additional options through Validators to message generation. E.g. plugin authors want to add validates_presence_of :foo, :format => "some format". Also, cleanup the :default vs :message options confusion in ActiveModel validation message generation. Also, deprecate ActiveModel::Errors#add_on_blank(attributes, custom_message) in favor of ActiveModel::Errors#add_on_blank(attributes, options). Also, refactoring of ActiveModel and ActiveRecord Validation tests. Test are a lot more DRY now. Better test coverage as well now. The first four points were reapplied from an older patch of Sven Fuchs which didn't apply cleanly anymore and was not complete yet. Signed-off-by: José Valim <jose.valim@gmail.com>
* Add titles to the rest of the files in active_model/validations/*Rizwan Reza2010-06-151-0/+2
|
* Fixed numericality validator in ActiveModel to reject hex numbers for floats ↵rohit2010-05-181-1/+1
| | | | | | completely [#4622 state:commited] Signed-off-by: José Valim <jose.valim@gmail.com>
* Valid hex strings aren't valid float column values, to match the integer ↵Jeremy Kemper2010-05-171-3/+8
| | | | restriction. [#4622 state:resolved]