aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations
Commit message (Collapse)AuthorAgeFilesLines
* activemodel typo fixes.alkesh262019-01-311-1/+1
|
* Add missing require for `Float#to_d`yuuji.yaginuma2019-01-261-0/+2
| | | | | | | In master, tests pass because `bigdecimal/util` requires in `active_support/xml_mini`. But test fails in 5-2-stable because that require does not exist. Ref: https://travis-ci.org/rails/rails/jobs/484627996#L1969
* Fix NumericalityValidator on object responding to `to_f`:Edouard CHIN2019-01-221-8/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - If you had a PORO that acted like a Numeric, the validator would work correctly because it was previously using `Kernel.Float` which is implicitely calling `to_f` on the passed argument. Since rails/rails@d126c0d , we are now using `BigDecimal` which does not implicitely call `to_f` on the argument, making the validator fail with an underlying `TypeError` exception. This patch replate the `is_decimal?` check with `Kernel.Float`. Using `Kernel.Float` as argument for the BigDecimal call has two advantages: 1. It calls `to_f` implicetely for us. 2. It's also smart enough to detect that `Kernel.Float("a")` isn't a Numeric and will raise an error. We don't need the `is_decimal?` check thanks to that. Passing `Float::DIG` as second argument to `BigDecimal` is mandatory because the precision can't be omitted when passing a Float. `Float::DIG` is what is used internally by ruby when calling `123.to_d` https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L47 - Another small issue introduced in https://github.com/rails/rails/pull/34693 would now raise a TypeError because `Regexp#===` will just return false if the passed argument isn't a string or symbol, whereas `Regexp#match?` will.
* Module#{attr,attr_accessor,attr_reader,attr_writer} become public since Ruby 2.5Ryuta Kamizono2018-12-212-4/+4
| | | | https://bugs.ruby-lang.org/issues/14132
* Prevent infinit method_missing loop on attribute methodsRyuta Kamizono2018-12-151-0/+1
| | | | | | | | | | | | If a klass has acceptance validation and then `klass.undefine_attribute_methods` is happened before an attribute method is called, infinit loop is caused on the `method_missing` defined by the `LazilyDefineAttributes`. https://travis-ci.org/rails/rails/jobs/467053984#L1409 To prevent the infinit loop, the `method_missing` should ensure `klass.define_attribute_methods`.
* Merge pull request #34693 from ahorek/matchRyuta Kamizono2018-12-131-3/+3
|\ | | | | | | [perf] use #match?
| * use match?pavel2018-12-121-3/+3
|/
* Fix numericality equality validation on floatsGannon McGibbon2018-12-121-10/+22
|
* Do not use deprecated Object#!~ in Ruby 2.6Rafael Mendonça França2018-11-261-1/+5
| | | | Closes #34530.
* 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
|