aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations
Commit message (Collapse)AuthorAgeFilesLines
* Don't require 'active_support/all' in an individual test case!!!Akira Matsuda2019-08-011-1/+0
| | | | and Git taught me that this crap was added via this commit... https://github.com/rails/rails/commit/68db6bc431fbff0b2291f1f60ccf974b4eece596
* Switch to use `class_attribute`:Edouard CHIN2019-07-161-0/+13
| | | | | | | | | - Since `ActiveModel::Error` can now be inherited by `ActiveModel::NestedError`, when the latter generates a `full_message`, the `i18n_customize_full_message` accessor set in the parent class is not set. This commit fixes that by using a `class_attribute` instead.
* Move the `ActiveModel:Errors#full_message` method to the `Error` class:Edouard CHIN2019-07-161-43/+43
| | | | | | | | | | | | | | | | - One regression introduced by the "AM errors as object" features is about the `full_messages` method. It's currently impossible to call that method if the `base` object passed in the constructor of `AM::Errors` doesn't respond to the `errors` method. That's because `full_messages` now makes a weird back and forth trip `AM::Errors#full_messages` -> `AM::Error#full_message` -> `AM::Errors#full_message` Since `full_message` (singular) isn't needed by AM::Errors, I moved it to the `AM::Error` (singular) class. This way we don't need to grab the `AM::Errors` object from the base.
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-132-2/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Merge pull request #32313 from lulalala/model_error_as_objectRafael França2019-04-243-8/+23
|\ | | | | Model error as object
| * Raise deprecation for calling `[:f] = 'b'` or `[:f] << 'b'`lulalala2019-03-312-6/+6
| | | | | | | | Revert some tests to ensure back compatibility
| * Fix spec as generate_message is no longer called during validationlulalala2019-03-311-0/+15
| |
| * Fix misalignment caused by SHA eebb9ddf9ba559a510975c486fe59a4edc9da97dlulalala2019-03-311-2/+2
| |
* | Ensure acceptance validator is not applied more than once to PersonChris Salzberg2019-04-141-46/+52
| |
* | Ensure multiple anonymous modules are not included into Topic in testsChris Salzberg2019-04-141-18/+32
|/ | | | | | | | | | | Each acceptance validator applied to a model class includes an instance of a module builder (LazilyDefineAttributes) into that class. In tests, if the original model class is not subclassed, these modules pile up and cannot be removed, potentially leading to flakey specs and false positive/negatives. To avoid this, always use subclasses in tests whose names (constants) can be removed when the test is done.
* Rename `i18n_full_message` config option to `i18n_customize_full_message`Prathamesh Sonpatki2019-03-291-13/+13
| | | | | | - I feel `i18n_customize_full_messages` explains the meaning of the config better. - Followup of https://github.com/rails/rails/pull/32956
* activemodel typo fix.alkesh262019-02-251-3/+3
|
* activemodel typo fixes.alkesh262019-01-311-1/+1
|
* Fix NumericalityValidator on object responding to `to_f`:Edouard CHIN2019-01-221-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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.
* Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-211-18/+16
| | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-212-6/+6
| | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* Fix numericality equality validation on floatsGannon McGibbon2018-12-121-0/+7
|
* Merge pull request #33615 from ↵Rafael França2018-09-071-1/+58
|\ | | | | | | | | Larochelle/i18n_full_message_with_nested_attributes `ActiveModel.full_message` interaction with `index_errors`
| * Call human_attribute_name with a string instead of a symboleMartin Larochelle2018-08-161-1/+1
| |
| * `ActiveModel.full_message` interaction with `index_errors`Martin Larochelle2018-08-141-0/+57
| |
* | Fix numericality validator to still use value before type cast except Active ↵Ryuta Kamizono2018-08-241-0/+10
|/ | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #32956 from Shopify/i18n_activemodel_errors_full_messageRafael França2018-06-111-0/+59
|\ | | | | Allow to override the full_message error format
| * Add global config for config.active_model.i18n_full_messageMartin Larochelle2018-06-051-0/+23
| |
| * Allow to override the full_message error formatMartin Larochelle2018-05-221-0/+36
| |
* | Fix `CustomCops/AssertNot` to allow it to have failure messageRyuta Kamizono2018-05-131-1/+1
|/ | | | Follow up of #32605.
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-252-9/+9
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-2512-274/+274
|
* Change test case name to FormatValidationTestPatrik Bóna2018-01-141-1/+1
| | | | I believe that this was caused by a copy/paste mistake.
* Fix validation callbacks on multiple contextYoshiyuki Hirano2017-12-201-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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"] ```
* Suppress `warning: BigDecimal.new is deprecated` in Active ModelYasuo Honda2017-12-141-14/+14
| | | | | | | | | | | | | | | | | | | | | | | `BigDecimal.new` has been deprecated in BigDecimal 1.3.3 which will be a default for Ruby 2.5. Refer ruby/bigdecimal@5337373 * This commit has been made as follows: ```ruby $ cd activemodel/ $ git grep -l BigDecimal.new | grep \.rb | xargs sed -i -e "s/BigDecimal.new/BigDecimal/g" ``` * This commit has been tested with these Ruby versions: ``` ruby 2.5.0dev (2017-12-15 trunk 61262) [x86_64-linux] ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux] ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux] ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-linux] ```
* Merge pull request #31061 from ↵Rafael França2017-11-063-6/+57
|\ | | | | | | | | bogdanvlviv/test-if-unless-options-for-validations Add cases to test combining validation conditions
| * Add cases to test combining validation conditionsbogdanvlviv2017-11-063-6/+57
| | | | | | | | | | | | | | | | | | - Test condition that is defined by array of conditions - Test condition that is defined by combining :if and :unless - Test local condition that is defined by :if - Test local condition that is defined by :unless See http://edgeguides.rubyonrails.org/active_record_validations.html#combining-validation-conditions
* | Execute `ConfirmationValidator` validation when `_confirmation`'s value is ↵bogdanvlviv2017-11-051-0/+13
|/ | | | `false`
* Allow passing a Proc or Symbol as an argument to length validator valuesMatt Rohrer2017-10-261-0/+31
| | | | | This brings the Length validator in line with the Numericality validator, which currently supports Proc & Symbol arguments
* Remove deprecated `:if` and `:unless` string filter for callbacksRafael Mendonça França2017-10-232-104/+2
|
* Use frozen string literal in activemodel/Kir Shatrov2017-07-1616-0/+32
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-0216-16/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-0116-0/+16
|
* Replace \Z to \zRyuta Kamizono2017-04-241-3/+3
| | | | \Z was a mistake of \z. Replace \Z to \z to prevent newly \Z added.
* Avoid converting integer as a string into floatnamusyaka2017-02-181-0/+9
|
* Remove deprecated behavior that halts callbacks when the return is falseRafael Mendonça França2017-02-071-8/+6
|
* Deprecate passing string to `:if` and `:unless` conditional options on ↵Ryuta Kamizono2017-02-042-10/+30
| | | | `set_callback` and `skip_callback`
* Do not rely on Ruby implementation in AM testKir Shatrov2016-11-191-3/+3
| | | | | | | | | | | | Now a few tests in ActiveModel rely on Ruby implementation and the fact that in MRI `97.18` as a float is greater than `97.18` as a BigDecimal. This is only relevant for MRI. On JRuby, comparing float to BigDecimal would be conversion of them to the same type and they will be equal. I'd like the ActiveModel test suite to be Ruby implementation-agnostic. Here we test ActiveModel, not the Ruby internals. This PR fixes a couple more JRuby tests.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-297-21/+21
|
* Removed deprecated :tokenizer in the length validatorRafael Mendonça França2016-10-101-36/+0
|
* improve error message when include assertions failMichael Grosser2016-09-162-11/+11
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-1/+1
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Add test for allow_blank in numericality validationNicolai Reuschling2016-08-281-0/+7
| | | | Signed-off-by: Guillermo Iguaran <guilleiguaran@gmail.com>
* Add three new rubocop rulesRafael Mendonça França2016-08-167-16/+16
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* Fix broken alignments caused by auto-correct commit 411ccbdRyuta Kamizono2016-08-101-1/+2
| | | | Hash syntax auto-correcting breaks alignments. 411ccbdab2608c62aabdb320d52cb02d446bb39c