diff options
author | Vladimir Kiselev <nettsundere@gmail.com> | 2013-06-26 04:46:21 +0400 |
---|---|---|
committer | Vladimir Kiselev <nettsundere@gmail.com> | 2013-07-24 03:14:15 +0400 |
commit | 3be0cdfa55cadf35f7625e055fad9999d064c827 (patch) | |
tree | a461dfbad843c0dd8e600b4015b8a55f349bd683 /activemodel/lib/active_model | |
parent | f38b5444428f418c4e6377bbb40d7518ea0c61a7 (diff) | |
download | rails-3be0cdfa55cadf35f7625e055fad9999d064c827.tar.gz rails-3be0cdfa55cadf35f7625e055fad9999d064c827.tar.bz2 rails-3be0cdfa55cadf35f7625e055fad9999d064c827.zip |
Fix secure_password password_confirmation validations
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/secure_password.rb | 10 |
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 |