mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Renaming get_or_create_*_token to ensure_*_token to match API in token authenticatable
This commit is contained in:
parent
b5909f9b93
commit
b194882b23
4 changed files with 18 additions and 15 deletions
|
@ -93,7 +93,7 @@ module Devise
|
||||||
self.confirmation_token = nil if reconfirmation_required?
|
self.confirmation_token = nil if reconfirmation_required?
|
||||||
@reconfirmation_required = false
|
@reconfirmation_required = false
|
||||||
|
|
||||||
generate_confirmation_token! if self.confirmation_token.blank?
|
ensure_confirmation_token!
|
||||||
|
|
||||||
opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { }
|
opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { }
|
||||||
send_devise_notification(:confirmation_instructions, opts)
|
send_devise_notification(:confirmation_instructions, opts)
|
||||||
|
@ -107,9 +107,9 @@ module Devise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_or_create_confirmation_token
|
# Generate a confirmation token unless already exists and save the record.
|
||||||
|
def ensure_confirmation_token!
|
||||||
generate_confirmation_token! if should_generate_confirmation_token?
|
generate_confirmation_token! if should_generate_confirmation_token?
|
||||||
self.confirmation_token
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overwrites active_for_authentication? for confirmation
|
# Overwrites active_for_authentication? for confirmation
|
||||||
|
|
|
@ -44,13 +44,13 @@ module Devise
|
||||||
|
|
||||||
# Resets reset password token and send reset password instructions by email
|
# Resets reset password token and send reset password instructions by email
|
||||||
def send_reset_password_instructions
|
def send_reset_password_instructions
|
||||||
generate_reset_password_token! if should_generate_reset_token?
|
ensure_reset_password_token!
|
||||||
send_devise_notification(:reset_password_instructions)
|
send_devise_notification(:reset_password_instructions)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_or_create_reset_password_token
|
# Generate reset password token unless already exists and save the record.
|
||||||
|
def ensure_reset_password_token!
|
||||||
generate_reset_password_token! if should_generate_reset_token?
|
generate_reset_password_token! if should_generate_reset_token?
|
||||||
self.reset_password_token
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Checks if the reset password token sent is within the limit time.
|
# Checks if the reset password token sent is within the limit time.
|
||||||
|
|
|
@ -300,16 +300,17 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||||
user = create_user
|
user = create_user
|
||||||
user.update_attribute(:confirmation_sent_at, 4.days.ago)
|
user.update_attribute(:confirmation_sent_at, 4.days.ago)
|
||||||
old = user.confirmation_token
|
old = user.confirmation_token
|
||||||
token = user.get_or_create_confirmation_token
|
user.ensure_confirmation_token!
|
||||||
assert_not_equal user.confirmation_token, old
|
assert_not_equal user.confirmation_token, old
|
||||||
assert_equal user.confirmation_token, token
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'should not generate a new token when a valid one exists' do
|
test 'should not generate a new token when a valid one exists' do
|
||||||
user = create_user
|
user = create_user
|
||||||
assert_not_nil user.confirmation_token
|
assert_not_nil user.confirmation_token
|
||||||
assert_equal user.confirmation_token, user.get_or_create_confirmation_token
|
old = user.confirmation_token
|
||||||
|
user.ensure_confirmation_token!
|
||||||
|
assert_equal user.confirmation_token, old
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
test 'should find a user to reset his password based on reset_password_token' do
|
test 'should find a user to reset his password based on reset_password_token' do
|
||||||
user = create_user
|
user = create_user
|
||||||
user.get_or_create_reset_password_token
|
user.ensure_reset_password_token!
|
||||||
|
|
||||||
reset_password_user = User.reset_password_by_token(:reset_password_token => user.reset_password_token)
|
reset_password_user = User.reset_password_by_token(:reset_password_token => user.reset_password_token)
|
||||||
assert_equal reset_password_user, user
|
assert_equal reset_password_user, user
|
||||||
|
@ -130,7 +130,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
test 'should return a new record with errors if password is blank' do
|
test 'should return a new record with errors if password is blank' do
|
||||||
user = create_user
|
user = create_user
|
||||||
user.get_or_create_reset_password_token
|
user.ensure_reset_password_token!
|
||||||
|
|
||||||
reset_password_user = User.reset_password_by_token(:reset_password_token => user.reset_password_token, :password => '')
|
reset_password_user = User.reset_password_by_token(:reset_password_token => user.reset_password_token, :password => '')
|
||||||
assert_not reset_password_user.errors.empty?
|
assert_not reset_password_user.errors.empty?
|
||||||
|
@ -140,7 +140,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||||
test 'should reset successfully user password given the new password and confirmation' do
|
test 'should reset successfully user password given the new password and confirmation' do
|
||||||
user = create_user
|
user = create_user
|
||||||
old_password = user.password
|
old_password = user.password
|
||||||
user.get_or_create_reset_password_token
|
user.ensure_reset_password_token!
|
||||||
|
|
||||||
User.reset_password_by_token(
|
User.reset_password_by_token(
|
||||||
:reset_password_token => user.reset_password_token,
|
:reset_password_token => user.reset_password_token,
|
||||||
|
@ -179,7 +179,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||||
swap Devise, :reset_password_within => 1.hour do
|
swap Devise, :reset_password_within => 1.hour do
|
||||||
user = create_user
|
user = create_user
|
||||||
old_password = user.password
|
old_password = user.password
|
||||||
user.get_or_create_reset_password_token
|
user.ensure_reset_password_token!
|
||||||
user.reset_password_sent_at = 2.days.ago
|
user.reset_password_sent_at = 2.days.ago
|
||||||
user.save!
|
user.save!
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||||
user = create_user
|
user = create_user
|
||||||
assert_nil user.reset_password_token
|
assert_nil user.reset_password_token
|
||||||
|
|
||||||
token = user.get_or_create_reset_password_token
|
user.ensure_reset_password_token!
|
||||||
assert_not_nil user.reset_password_token
|
assert_not_nil user.reset_password_token
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -215,6 +215,8 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||||
user = create_user
|
user = create_user
|
||||||
user.send :generate_reset_password_token!
|
user.send :generate_reset_password_token!
|
||||||
assert_not_nil user.reset_password_token
|
assert_not_nil user.reset_password_token
|
||||||
assert_equal user.reset_password_token, user.get_or_create_reset_password_token
|
old = user.reset_password_token
|
||||||
|
user.ensure_reset_password_token!
|
||||||
|
assert_equal user.reset_password_token, old
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue