aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations
Commit message (Collapse)AuthorAgeFilesLines
* Add `Style/RedundantFreeze` to remove redudant `.freeze`Yasuo Honda2018-09-291-1/+1
| | | | | | | | | | | | | | | | | | | | | Since Rails 6.0 will support Ruby 2.4.1 or higher `# frozen_string_literal: true` magic comment is enough to make string object frozen. This magic comment is enabled by `Style/FrozenStringLiteralComment` cop. * Exclude these files not to auto correct false positive `Regexp#freeze` - 'actionpack/lib/action_dispatch/journey/router/utils.rb' - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb' It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333 Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed. * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required - 'actionpack/test/controller/test_case_test.rb' - 'activemodel/test/cases/type/string_test.rb' - 'activesupport/lib/active_support/core_ext/string/strip.rb' - 'activesupport/test/core_ext/string_ext_test.rb' - 'railties/test/generators/actions_test.rb'
* 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.
* Update validates_inclusion_of exampleCassidy Kobewka2018-04-171-1/+1
|
* Use string-based fields. [ci skip]Cassidy Kobewka2018-04-161-1/+1
|
* Inclusive Language in Documentation Examples [ci skip]Cassidy Kobewka2018-04-151-1/+1
|
* Rails 6 requires Ruby 2.3+Jeremy Daer2018-02-172-7/+2
|
* Refactor to `Array(options[:on])` only once in defining validationsRyuta Kamizono2018-01-011-8/+10
|
* Fix validation callbacks on multiple contextYoshiyuki Hirano2017-12-201-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I found a bug that validation callbacks don't fire on multiple context. So I've fixed it. Example: ```ruby class Dog include ActiveModel::Validations include ActiveModel::Validations::Callbacks attr_accessor :history def initialize @history = [] end before_validation :set_before_validation_on_a, on: :a before_validation :set_before_validation_on_b, on: :b after_validation :set_after_validation_on_a, on: :a after_validation :set_after_validation_on_b, on: :b def set_before_validation_on_a; history << "before_validation on a"; end def set_before_validation_on_b; history << "before_validation on b"; end def set_after_validation_on_a; history << "after_validation on a" ; end def set_after_validation_on_b; history << "after_validation on b" ; end end ``` Before: ``` d = Dog.new d.valid?([:a, :b]) d.history # [] ``` After: ``` d = Dog.new d.valid?([:a, :b]) d.history # ["before_validation on a", "before_validation on b", "after_validation on a", "after_validation on b"] ```
* Update validates.rbLonre Wang2017-12-101-1/+1
|
* Execute `ConfirmationValidator` validation when `_confirmation`'s value is ↵bogdanvlviv2017-11-051-1/+1
| | | | `false`
* Allow passing a Proc or Symbol as an argument to length validator valuesMatt Rohrer2017-10-261-2/+8
| | | | | This brings the Length validator in line with the Numericality validator, which currently supports Proc & Symbol arguments
* [Active Model] require => require_relativeAkira Matsuda2017-10-212-2/+2
| | | | This basically reverts ee5cfc01a5797f854c8441539b0cae326a81b963
* Use frozen string literal in activemodel/Kir Shatrov2017-07-1614-0/+28
|
* [Active Model] require => require_relativeAkira Matsuda2017-07-012-2/+2
|
* 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
* remove uniqueness validators from ActiveModel examplesstve2017-05-021-3/+2
|
* Fix regexp in the doc [ci skip]Ryuta Kamizono2017-04-241-1/+1
| | | | Follow up of #17148.
* :scissors:Ryuta Kamizono2017-04-132-2/+0
| | | | [ci skip]
* 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-1510-10/+10
|
* Remove unused requireRyuta Kamizono2017-02-121-2/+0
| | | | | | These files are not using `strip_heredoc`. Closes #27976
* Remove deprecated behavior that halts callbacks when the return is falseRafael Mendonça França2017-02-071-1/+0
|
* Privatize unneededly protected methods in Active ModelAkira Matsuda2016-12-243-17/+15
|
* Describe what we are protectingAkira Matsuda2016-12-231-0/+2
|
* Merge pull request #26905 from bogdanvlviv/docsAndrew White2016-11-132-2/+2
|\ | | | | Add missing `+` around a some literals.
| * Add missing `+` around a some literals.bogdanvlviv2016-10-272-2/+2
| | | | | | | | | | | | Mainly around `nil` [ci skip]
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-292-2/+2
| |
* | let Regexp#match? be globally availableXavier Noria2016-10-271-1/+0
|/ | | | | | Regexp#match? should be considered to be part of the Ruby core library. We are emulating it for < 2.4, but not having to require the extension is part of the illusion of the emulation.
* Missing require extract_optionsAkira Matsuda2016-10-251-0/+2
|
* Removed deprecated :tokenizer in the length validatorRafael Mendonça França2016-10-101-34/+1
|
* 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.
* revises most Lint/EndAlignment offensesXavier Noria2016-08-071-5/+5
| | | | Some case expressions remain, need to think about those ones.
* applies remaining conventions across the projectXavier Noria2016-08-067-7/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-066-91/+91
|
* applies new string literal convention in activemodel/libXavier Noria2016-08-065-6/+6
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* systematic revision of =~ usage in AMoXavier Noria2016-07-241-2/+3
|
* 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.
* - removing redundant 'happens' in documentation [ci skip]Mohit Natoo2016-05-191-4/+2
|
* Chomp: prefer String#chomp where we can for a clarity boostlvl0nax2016-04-291-5/+1
| | | | | | Closes #24766, #24767 Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* fix length validation error typoPareshGupta2016-04-071-1/+1
|
* Use Range#cover? for Date inclusion validatorojab2016-03-241-3/+4
|
* 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]
* Merge pull request #19851 from repinel/numericality-validation2Sean Griffin2015-10-201-12/+11
|\ | | | | Use the post-type-cast version of the attribute to validate numericality
| * 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]
* | `validates_acceptance_of` shouldn't require a database connectionSean Griffin2015-09-251-4/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | The implementation of `attribute_method?` on Active Record requires establishing a database connection and querying the schema. As a general rule, we don't want to require database connections for any class macro, as the class should be able to be loaded without a database (e.g. for things like compiling assets). Instead of eagerly defining these methods, we do it lazily the first time they are accessed via `method_missing`. This should not cause any performance hits, as it will only hit `method_missing` once for the entire class.
* | Fix the AS::Callbacks terminator regression from 4.2.3Roque Pinel2015-09-221-0/+1
| | | | | | | | | | | | Rails 4.2.3 AS::Callbacks will not halt chain if `false` is returned. That is the behavior of specific callbacks like AR::Callbacks and AM::Callbacks.