aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2013-07-23 16:56:36 -0700
committerGuillermo Iguaran <guilleiguaran@gmail.com>2013-07-23 16:56:36 -0700
commit2aa20b36384f9ed2e492758840411d1c7cc081ca (patch)
treef71b8055cb23f3c47ff514246ec82c9f0cbe21a4 /activemodel/lib
parent844efb2bb0d6e40a2d830727f6bc235b37c3a1b1 (diff)
parent3be0cdfa55cadf35f7625e055fad9999d064c827 (diff)
downloadrails-2aa20b36384f9ed2e492758840411d1c7cc081ca.tar.gz
rails-2aa20b36384f9ed2e492758840411d1c7cc081ca.tar.bz2
rails-2aa20b36384f9ed2e492758840411d1c7cc081ca.zip
Merge pull request #11107 from nettsundere/password-confirmation-fix
Fix secure_password password_confirmation validations
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/secure_password.rb10
1 files changed, 8 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb
index 3d6de33e1e..cc9483e67b 100644
--- a/activemodel/lib/active_model/secure_password.rb
+++ b/activemodel/lib/active_model/secure_password.rb
@@ -56,9 +56,9 @@ module ActiveModel
include InstanceMethodsOnActivation
if options.fetch(:validations, true)
- validates_confirmation_of :password, if: lambda { |m| m.password.present? }
+ validates_confirmation_of :password, if: :should_confirm_password?
validates_presence_of :password, on: :create
- validates_presence_of :password_confirmation, if: lambda { |m| m.password.present? }
+ validates_presence_of :password_confirmation, if: :should_confirm_password?
before_create { raise "Password digest missing on new record" if password_digest.blank? }
end
@@ -109,6 +109,12 @@ module ActiveModel
def password_confirmation=(unencrypted_password)
@password_confirmation = unencrypted_password
end
+
+ private
+
+ def should_confirm_password?
+ password_confirmation && password.present?
+ end
end
end
end