aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations
Commit message (Collapse)AuthorAgeFilesLines
* 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
* code gardening: removes redundant selfsXavier Noria2016-08-081-16/+16
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-072-2/+0
|
* applies remaining conventions across the projectXavier Noria2016-08-0611-12/+0
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-17/+17
|
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-4/+2
|
* modernizes hash syntax in activemodelXavier Noria2016-08-061-1/+1
|
* applies new string literal convention in activemodel/testXavier Noria2016-08-0616-215/+215
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* 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.
* Add edge cases to Time/Date/DateTime inclusion validation testsojab2016-03-241-3/+17
|
* remove args from assert_nothing_raised in testsTara Scherner de la Fuente2016-02-222-4/+4
|
* Failing Tests for Validating String NumbericalityRobert Eshleman2015-12-221-0/+42
| | | | | | | | | | | Covers Regressions: * <= * < * == * > * >= * other than
* Deprecate passing string to define callback.yui-knk2015-12-161-0/+1
|
* Really fix test failures caused by #19851Sean Griffin2015-10-201-5/+6
| | | | | | | Ok, this explains why the branch showed as green. We don't run files in isolation for PRs, only for master. Active Support monkeypatches `BigDecimal#to_s`, so the generated error message was different depending on if the file was run in isolation
* Fix test failures caused by #19851Sean Griffin2015-10-201-5/+5
| | | | | | | | | The error message when asserting `greater_than: BigDecimal.new` will give an error message based on how BigDecimal displays itself. Big decimal appears to always use scientific notation. This might not be the best error message for the general case, but the general case wouldn't use big decimal for the validation. And if they do, they likely need this level of precision.
* Merge pull request #19851 from repinel/numericality-validation2Sean Griffin2015-10-201-1/+36
|\ | | | | 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-1/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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]
* | Validate multiple contexts on `valid?` and `invalid?` at once.Dmitry Polushkin2015-09-071-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Example: ```ruby class Person include ActiveModel::Validations attr_reader :name, :title validates_presence_of :name, on: :create validates_presence_of :title, on: :update end person = Person.new person.valid?([:create, :update]) # => true person.errors.messages # => {:name=>["can't be blank"], :title=>["can't be blank"]} ```