Skip to content

Instantly share code, notes, and snippets.

@kylefox kylefox/test.rb
Created Nov 13, 2009

Embed
What would you like to do?
require 'test_helper'
class PasswordResetTest < ActionController::IntegrationTest
def setup
@site = Factory(:site, :short_name => "example")
@site.domains.create(:name => 'www.example.com', :activated => Time.now.utc)
@user = Factory(:user, :site => @site)
@user.password
Factory(:alpha_theme, :site => @site, :activated_at => Time.now.utc, :html_template => "{{page.content}}")
@emails = ActionMailer::Base.deliveries
@emails.clear
end
def test_password_reset_with_valid_email
visit login_path
click_link "Forgot password?"
fill_in "Your email address", :with => @user.email
click_button "Send Password Reset"
assert_equal 1, @emails.length
assert_contain "Please check your email. We've sent you a secure link that will allow you to reset your password."
reset_url = /https?:\/\/[a-z0-9\.\-\_=&\+\/\?]+/i.match(@emails.first.body).to_s
visit reset_url
fill_in "New Password", :with => "mynewpassword"
fill_in "Confirm New Password", :with => "mynewpassword"
response = click_button "Save New Password"
assert_equal "Your password has been changed and you've been logged in.", flash[:notice]
assert @controller.user_logged_in?
end
def test_password_reset_with_invalid_email
visit login_path
click_link "Forgot password?"
fill_in "Your email address", :with => "nobody@example.com"
click_button "Send Password Reset"
assert_equal "No user with that email exists.", flash[:errors]
assert_equal path, forgot_password_path
end
def test_invalid_reset_token
visit reset_password_url(:token => "some-invalid-token")
assert_equal "That password reset link is no longer valid.", flash[:errors]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.