mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Recoverable class method reset_password should use a bang!
This commit is contained in:
parent
ba7e74e1a1
commit
97ae1795bd
3 changed files with 6 additions and 6 deletions
|
@ -20,7 +20,7 @@ class PasswordsController < ApplicationController
|
|||
end
|
||||
|
||||
def update
|
||||
@password = User.reset_password(params[:password])
|
||||
@password = User.reset_password!(params[:password])
|
||||
if @password.errors.empty?
|
||||
flash[:notice] = 'Your password was changed successfully.'
|
||||
redirect_to new_session_path
|
||||
|
|
|
@ -52,7 +52,7 @@ module Devise
|
|||
# in perishable_token attribute.
|
||||
# Options must contain perishable_token, password and confirmation
|
||||
#
|
||||
def reset_password(options={})
|
||||
def reset_password!(options={})
|
||||
recoverable = find_or_initialize_with_error_by_perishable_token(options[:perishable_token])
|
||||
recoverable.reset_password!(options[:password], options[:password_confirmation]) unless recoverable.new_record?
|
||||
recoverable
|
||||
|
|
|
@ -61,26 +61,26 @@ class RecoverableTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test 'should find a user to reset it\'s password based on perishable_token' do
|
||||
reset_password_user = User.reset_password(:perishable_token => @user.perishable_token)
|
||||
reset_password_user = User.reset_password!(:perishable_token => @user.perishable_token)
|
||||
assert_not_nil reset_password_user
|
||||
assert_equal reset_password_user, @user
|
||||
end
|
||||
|
||||
test 'should return a new user when trying to reset it\'s password if no perishable_token is found' do
|
||||
reset_password_user = User.reset_password(:perishable_token => 'invalid_token')
|
||||
reset_password_user = User.reset_password!(:perishable_token => 'invalid_token')
|
||||
assert_not_nil reset_password_user
|
||||
assert reset_password_user.new_record?
|
||||
end
|
||||
|
||||
test 'should add error to new user email if no perishable token was found' do
|
||||
reset_password_user = User.reset_password(:perishable_token => "invalid_token")
|
||||
reset_password_user = User.reset_password!(:perishable_token => "invalid_token")
|
||||
assert reset_password_user.errors[:perishable_token]
|
||||
assert_equal 'invalid confirmation', reset_password_user.errors[:perishable_token]
|
||||
end
|
||||
|
||||
test 'should reset successfully user password given the new password and confirmation' do
|
||||
old_password = @user.password
|
||||
reset_password_user = User.reset_password(
|
||||
reset_password_user = User.reset_password!(
|
||||
:perishable_token => @user.perishable_token,
|
||||
:password => 'new_password',
|
||||
:password_confirmation => 'new_password'
|
||||
|
|
Loading…
Reference in a new issue