Skip to content

Commit

Permalink
Finish 12.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tliss committed Oct 11, 2018
1 parent 79a8373 commit 7ab3cd3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/password_resets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def update
render 'edit'
elsif @user.update_attributes(user_params)
log_in @user
@user.update_attribute(:reset_digest, nil)
flash[:success] = "Password has been reset."
redirect_to @user
else
Expand Down
3 changes: 1 addition & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def send_activation_email
# Sets the password reset attributes.
def create_reset_digest
self.reset_token = User.new_token
update_attribute(:reset_digest, User.digest(reset_token))
update_attribute(:reset_sent_at, Time.zone.now)
update_columns(reset_digest: User.digest(reset_token), reset_sent_at: Time.zone.now)
end

# Sends password reset email.
Expand Down
17 changes: 17 additions & 0 deletions test/integration/password_resets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,22 @@ def setup
assert is_logged_in?
assert_not flash.empty?
assert_redirected_to user
assert_nil @user.reload.reset_digest
end

test "expired token" do
get new_password_reset_path
post password_resets_path,
params: { password_reset: { email: @user.email } }

@user = assigns(:user)
@user.update_attribute(:reset_sent_at, 3.hours.ago)
patch password_reset_path(@user.reset_token),
params: { email: @user.email,
user: { password: "foobar",
password_confirmation: "foobar" } }
assert_response :redirect
follow_redirect!
assert_match /expired/i, response.body
end
end

0 comments on commit 7ab3cd3

Please sign in to comment.