mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-22 21:28:01 -05:00
Use persisted? instead of new_record?
In order to be more ActiveModel compliant, lets use persisted? whereever we can. Particularly for datamapper, new_record? causes api warnings. Better to stick to the ActiveModel api I think.
This commit is contained in:
@@ -49,7 +49,7 @@ module Devise
|
||||
|
||||
# Verifies whether a user is confirmed or not
|
||||
def confirmed?
|
||||
!new_record? && !confirmed_at.nil?
|
||||
persisted? && !confirmed_at.nil?
|
||||
end
|
||||
|
||||
# Send confirmation instructions by email
|
||||
@@ -138,7 +138,7 @@ module Devise
|
||||
# Options must contain the user email
|
||||
def send_confirmation_instructions(attributes={})
|
||||
confirmable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
|
||||
confirmable.resend_confirmation_token unless confirmable.new_record?
|
||||
confirmable.resend_confirmation_token if confirmable.persisted?
|
||||
confirmable
|
||||
end
|
||||
|
||||
@@ -148,7 +148,7 @@ module Devise
|
||||
# Options must have the confirmation_token
|
||||
def confirm_by_token(confirmation_token)
|
||||
confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
|
||||
confirmable.confirm! unless confirmable.new_record?
|
||||
confirmable.confirm! if confirmable.persisted?
|
||||
confirmable
|
||||
end
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ module Devise
|
||||
# Options must contain the user email
|
||||
def send_unlock_instructions(attributes={})
|
||||
lockable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
|
||||
lockable.resend_unlock_token unless lockable.new_record?
|
||||
lockable.resend_unlock_token if lockable.persisted?
|
||||
lockable
|
||||
end
|
||||
|
||||
@@ -129,7 +129,7 @@ module Devise
|
||||
# Options must have the unlock_token
|
||||
def unlock_access_by_token(unlock_token)
|
||||
lockable = find_or_initialize_with_error_by(:unlock_token, unlock_token)
|
||||
lockable.unlock_access! unless lockable.new_record?
|
||||
lockable.unlock_access! if lockable.persisted?
|
||||
lockable
|
||||
end
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ module Devise
|
||||
# Attributes must contain the user email
|
||||
def send_reset_password_instructions(attributes={})
|
||||
recoverable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
|
||||
recoverable.send_reset_password_instructions unless recoverable.new_record?
|
||||
recoverable.send_reset_password_instructions if recoverable.persisted?
|
||||
recoverable
|
||||
end
|
||||
|
||||
@@ -67,7 +67,7 @@ module Devise
|
||||
# Attributes must contain reset_password_token, password and confirmation
|
||||
def reset_password_by_token(attributes={})
|
||||
recoverable = find_or_initialize_with_error_by(:reset_password_token, attributes[:reset_password_token])
|
||||
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation]) unless recoverable.new_record?
|
||||
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation]) if recoverable.persisted?
|
||||
recoverable
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,7 +42,7 @@ module Devise
|
||||
# Passwords are always required if it's a new record, or if the password
|
||||
# or confirmation are being set somewhere.
|
||||
def password_required?
|
||||
new_record? || !password.nil? || !password_confirmation.nil?
|
||||
!persisted? || !password.nil? || !password_confirmation.nil?
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
Reference in New Issue
Block a user