aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations/numericality.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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]
* Revert "Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an ↵José Valim2010-05-151-4/+4
| | | | | | | | options hash and make various Validators pass their (filtered) options." Having a huge array to whitelist options is not the proper way to handle this case. This means that the ActiveModel::Errors object should know about the options given in *all* validators and break the extensibility added by the validators itself. If the intent is to whitelist options before sending them to I18n, each validator should clean its respective options instead of throwing the responsibility to the Errors object. This reverts commit bc1c8d58ec45593acba614d1d0fecb49adef08ff.
* Make ActiveModel::Errors#add_on_blank and #add_on_empty accept an options ↵Jeroen van Dijk2010-05-151-4/+4
| | | | | | | | | | | | | | | | | | | | 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). Original patch by Sven Fuchs, some minor changes and has been changed to be applicable to master again [#4057 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
* validation macros can now be used within an instanceJosh Kalderimis2010-05-131-1/+1
|
* Fix validates_numericaly_of only integer error message [#4406 state:resolved]reu2010-04-251-11/+18
| | | | Signed-off-by: José Valim <jose.valim@gmail.com>
* Fix typos and add tests to ensure they will be caught the next time.José Valim2010-01-111-2/+2
|
* Allow validates to map some types to specific options. So now you can do:José Valim2010-01-081-3/+4
| | | | | | validates :email, :presence => true, :format => /@/ validates :genre, :inclusion => %w(m f) validates :password, :length => 6..20
* Add validates method as shortcut to setup validators for a given set of ↵jamie2010-01-071-2/+1
| | | | | | | | | | | | | | | attributes: class Person < ActiveRecord::Base include MyValidators validates :name, :presence => true, :uniqueness => true, :length => { :maximum => 100 } validates :email, :presence => true, :email => true end [#3058 status:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
* ActiveRecord::Validations are now built on top of Validator as well.José Valim2009-12-231-2/+5
|
* Added check_validity! to EachValidator and refactor existing ones.José Valim2009-12-231-39/+39
|
* Move validations in ActiveModel to validators, however all validatity checks ↵José Valim2009-12-231-51/+54
| | | | are still in the class method.
* added proc and symbol support to validates_numericality_of [#3049 ↵Kane2009-08-311-1/+20
| | | | | | state:resolved] Signed-off-by: Joshua Peek <josh@joshpeek.com>
* Properly require ActiveModel validation dependenciesJoshua Peek2009-06-081-2/+2
|
* Move validate_on_create and validate_on_update from ActiveModel to ActiveRecordPratik Naik2009-03-211-1/+1
|
* Add I18n translations to ActiveModel and move more AR specific parts to ↵Pratik Naik2009-03-201-10/+15
| | | | ActiveRecord::Validations
* Move all the Active Record validations to Active ModelPratik Naik2009-03-191-11/+12
|
* Merge docrails:Pratik Naik2008-05-091-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | commit e6afd8b2736364322b673bbdcca3e9b38b6d3da0 Author: Xavier Noria <fxn@hashref.com> Date: Thu May 8 23:49:36 2008 +0200 Overall documentation improvement and markup corrections. Zillion changes. commit 2fead68b3192332eee27945ed95a94a64ca73f70 Author: Austin Putman <austin@emmanuel.local> Date: Wed May 7 19:35:46 2008 -0700 Documented class methods on ActionController::Routing. These are dangerous, and mostly used for testing. commit f5b84182dbc39bea79c8ee319c688d00fa99f9d1 Author: Teflon Ted <github@rudiment.net> Date: Wed May 7 16:08:49 2008 -0400 Added explanation about errant inflections not being patched in the future in order to avoid breaking legacy applications. commit 370f4f51722cec49ace17093d29e9ce9e8f15cfb Author: Sunny Ripert <negatif@gmail.com> Date: Wed May 7 14:00:59 2008 +0200 Applied list conventions in AR::Base commit 5bd18429f09d44e75191bec42a6db04bd33f3030 Author: Sunny Ripert <negatif@gmail.com> Date: Wed May 7 13:53:35 2008 +0200 Renamed Options list to Attributes list whenever they weren't option hashes in AR::Base commit d912bd5672316454457ae83f6e9dda5197beeb6f Author: Yaroslav Markin <yaroslav@markin.net> Date: Wed May 7 13:50:28 2008 +0400 Add a filter_parameter_logging usage hint to generated ApplicationController. This may help to remind the developer to filter sensitive information from application logs. Closes #11578 commit b243de0db3c2605121e055079854af5090d06374 Author: Jack Danger Canty <git@6brand.com> Date: Tue May 6 23:39:47 2008 -0700 doc: disambiguating an example ActiveRecord class commit f81d771f0657ae8375b84a77a059812cce5d6fd9 Author: Jack Danger Canty <git@6brand.com> Date: Tue May 6 23:35:05 2008 -0700 doc: ActiveRecord::Reflection::AssociationReflection#through_reflection Added documentation demonstrating the use of #through_reflection for finding intervening reflection objects for HasManyThrough and HasOneThrough. commit ae6b46f00b5b8b2939c6b37ce3329c83de7e71db Author: Cheah Chu Yeow <chuyeow@gmail.com> Date: Wed May 7 13:47:41 2008 +0800 Document AttributeAssignmentError and MultiparameterAssignmentErrors. commit 8f463550b597db2156b67733f31aed13487fbc3a Author: John Barnette <jbarnette@gmail.com> Date: Tue May 6 22:46:44 2008 -0700 Killing/fixing a bunch of outdated language in the AR README. commit aca44bcd92ef783abdf484b58abdde6786db0f89 Author: Cheah Chu Yeow <chuyeow@gmail.com> Date: Wed May 7 13:34:52 2008 +0800 Make a note about ActiveResource::Timeouterror being raised when ARes calls timeout. commit 284a930a93fbee16e25d06392779dbf2f03e9e12 Author: Jonathan Dance <jd@wuputah.com> Date: Tue May 6 14:58:26 2008 -0400 improvements to the page caching docs commit 9482da621390c874da7c921c8bd6230caae7035a Author: Sunny Ripert <negatif@gmail.com> Date: Mon May 5 18:13:40 2008 +0200 validates_numericality_of() "integer" option really is "only_integer" commit e9afd6790a8f530528f6597a7f59bb283be754f6 Author: Sunny Ripert <negatif@gmail.com> Date: Mon May 5 12:11:59 2008 +0200 Harmonized hash notation in AR::Base commit 67ebf14a91ffd970b582be4ff2991d691a9cf3e1 Author: Sunny Ripert <negatif@gmail.com> Date: Mon May 5 12:06:19 2008 +0200 Turned options into rdoc-lists in AR::Base commit 0ec7c0a41d889d4e5382b9dff72f1aaba89bf297 Author: Marshall Huss <mwhuss@Macbook.local> Date: Sun May 4 23:21:33 2008 -0400 Added information of how to set element_name in the case the user has a name confliction with an existing model Signed-off-by: Pratik Naik <pratiknaik@gmail.com>