1
0
Fork 0
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:
bogdanvlviv 2017-11-05 19:19:41 +00:00
parent 03ac95a140
commit 7308991630
No known key found for this signature in database
GPG key ID: E4ACD76A6DB6DFDD
3 changed files with 18 additions and 1 deletions

View file

@ -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*

View file

@ -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))

View file

@ -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