Skip to content

Instantly share code, notes, and snippets.

@Veejay
Created March 26, 2012 21:58
Show Gist options
  • Save Veejay/2210083 to your computer and use it in GitHub Desktop.
Save Veejay/2210083 to your computer and use it in GitHub Desktop.
Specs for password reset
require 'spec_helper'
describe RegistrationsController do
describe "Forgetful user gets to the user page. He should have a forgot password link" do
it "should display a template containing the string t('sessions.new.forgot_password')" do
end
end
describe "User provides an email address" do
it "should display a page containg an appropriate text field and a submit button" do
end
end
describe "We try to find the user based on that email address, set a perishable token and the current time" do
context "A user with that email address exists in the DB" do
it "should display a template containing t('registrations.password_reset.email_sent')" do
end
it "should set a token and a timestamp on the user" do
end
end
context "No user with that email address exists in the DB" do
it "should display a template containing t('registrations.password_reset.email_sent') anyway to avoid providing DB records hints" do
end
end
end
describe "We send an email to that email address with a link containing the token" do
# PSEUDO CODE: The forgetful user should receive send_password_reset
# The email should contain the token
end
describe "The user clicks on the link inside the email" do
describe "If the user clicked less than 2 hours after the token was set, we find the user based on that token, delete the token and redirect the user to the edit user page" do
it "We should find the user based on his token" do
end
it "should wipe the token out" do
end
it "should redirect to the user edit page" do
end
end
describe "The user clicks on the link too late" do
it "should display an error message saying that the token is too old to the user" do
end
end
describe "No user bearing that token exists in the DB" do
it "should redirect to root_url and log a possible issue" do
end
end
end
describe "The user should get to the edit user page and be able to set a new password/password confirmation" do
it "should render user/USER_ID/edit" do
end
end
describe "User provides a new password and password confirmation that match" do
it "should update the user's information to reflect his action" do
# PSEUDO CODE: The forgetful user's password_digest should change
end
it "should prevent the user from doing anything with the email anymore" do
# PSEUDO CODE: The user token should be invalid
end
end
describe "User provides non-matching password and password confirmation" do
it "should not update the user information" do
end
it "should display an error message and redirect to the user edit page" do
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment