View refactor_start.rb
def change_password
@user = User.find(params[:id])
authorize! :update, @user
@user_input = params.require(:user)
if (@user.valid_password?(@user_input['old_password']))
if (@user_input['password'] == @user_input['password_confirmation'])
@user.password = @user_input['password']
save_successful = @user.save
View refactor_without_exceptions.rb
def change_password
@user = get_and_authorize_user
@user_input = params.require(:user)
if (old_password_match)
if (new_password_confirmation_match)
@user.password = @user_input['password']
save_user_and_display_eventual_error
else
error_message_and_retry 'messages.users.password_dont_match'
View refactor_exceptions.rb
def change_password
@user = get_and_authorize_user
@user_input = params.require(:user)
begin
check_old_password_match
check_new_password_confirmation_match
@user.password = @user_input['password']
save_user
redirect_to root_path, :notice => 'Mot de passe mis à jour'