aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorVladimir Kiselev <nettsundere@gmail.com>2013-06-26 04:46:21 +0400
committerVladimir Kiselev <nettsundere@gmail.com>2013-07-24 03:14:15 +0400
commit3be0cdfa55cadf35f7625e055fad9999d064c827 (patch)
treea461dfbad843c0dd8e600b4015b8a55f349bd683 /activemodel/lib
parentf38b5444428f418c4e6377bbb40d7518ea0c61a7 (diff)
downloadrails-3be0cdfa55cadf35f7625e055fad9999d064c827.tar.gz
rails-3be0cdfa55cadf35f7625e055fad9999d064c827.tar.bz2
rails-3be0cdfa55cadf35f7625e055fad9999d064c827.zip
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