mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Execute ConfirmationValidator
validation when _confirmation
's value is false
This commit is contained in:
parent
03ac95a140
commit
7308991630
3 changed files with 18 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
* Execute `ConfirmationValidator` validation when `_confirmation`'s value is `false`.
|
||||
|
||||
*bogdanvlviv*
|
||||
|
||||
* Allow passing a Proc or Symbol to length validator options.
|
||||
|
||||
*Matt Rohrer*
|
||||
|
|
|
@ -9,7 +9,7 @@ module ActiveModel
|
|||
end
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
if (confirmed = record.send("#{attribute}_confirmation"))
|
||||
unless (confirmed = record.send("#{attribute}_confirmation")).nil?
|
||||
unless confirmation_value_equal?(record, attribute, value, confirmed)
|
||||
human_attribute_name = record.class.human_attribute_name(attribute)
|
||||
record.errors.add(:"#{attribute}_confirmation", :confirmation, options.except(:case_sensitive).merge!(attribute: human_attribute_name))
|
||||
|
|
|
@ -37,6 +37,19 @@ class ConfirmationValidationTest < ActiveModel::TestCase
|
|||
assert t.valid?
|
||||
end
|
||||
|
||||
def test_validates_confirmation_of_with_boolean_attribute
|
||||
Topic.validates_confirmation_of(:approved)
|
||||
|
||||
t = Topic.new(approved: true, approved_confirmation: nil)
|
||||
assert t.valid?
|
||||
|
||||
t.approved_confirmation = false
|
||||
assert t.invalid?
|
||||
|
||||
t.approved_confirmation = true
|
||||
assert t.valid?
|
||||
end
|
||||
|
||||
def test_validates_confirmation_of_for_ruby_class
|
||||
Person.validates_confirmation_of :karma
|
||||
|
||||
|
|
Loading…
Reference in a new issue