1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Got all the new tests passing

This commit is contained in:
Godfrey Chan 2014-01-20 05:04:19 -08:00
parent 20490adcbf
commit 8ca59237dd

View file

@ -57,11 +57,15 @@ module ActiveModel
include InstanceMethodsOnActivation
if options.fetch(:validations, true)
validates_confirmation_of :password, if: :password_confirmation_required?
validates_presence_of :password, on: :create
validates_presence_of :password_confirmation, if: :password_confirmation_required?
# This ensures the model has a password by checking whether the password_digest
# is present, so that this works with both new and existing records. However,
# when there is an error, the message is added to the password attribute instead
# so that the error message will makes sense to the end-user.
validate do |record|
record.errors.add(:password, :blank) unless record.password_digest.present?
end
before_create { raise "Password digest missing on new record" if password_digest.blank? }
validates_confirmation_of :password, if: ->{ self.password.present? }
end
if respond_to?(:attributes_protected_by_default)
@ -112,12 +116,6 @@ module ActiveModel
def password_confirmation=(unencrypted_password)
@password_confirmation = unencrypted_password
end
private
def password_confirmation_required?
password_confirmation && password.present?
end
end
end
end