Skip to content

Commit

Permalink
Added forgot password views
Browse files Browse the repository at this point in the history
Added password reset view for user
Added tests for both forgot password and password reset workflows
Added redirect-with-flash
Added documentation for some methods and pages
  • Loading branch information
BRIMIL01 committed Mar 28, 2011
1 parent 104f579 commit ac87702
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions test/rstatus_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,96 @@ def test_successful_password_reset
assert_match "/", page.current_url
end

def test_user_password_reset
u = Factory(:user, :email => "[email protected]")
u.password = "password"
u.save
pass_hash = u.hashed_password
log_in_email(u)

visit "/users/password_reset"
assert_match "Password Reset", page.body

fill_in "password", :with => "password"
fill_in "password_confirm", :with => "password"
click_button "Reset"

u = User.first(:email => "[email protected]")
assert u.hashed_password != pass_hash
assert_match "Password successfully set", page.body
assert_match "/", page.current_url
end

def test_user_password_reset_not_logged_in
visit "/users/password_reset"

assert_match "/forgot_password", page.current_url
end

def test_user_password_reset_no_email
user = Factory(:user, :email => nil)
a = Factory(:authorization, :user => user)
log_in(user, a.uid)

visit "/users/password_reset"

assert_match "Set Password", page.body

fill_in "email", :with => "[email protected]"
fill_in "password", :with => "password"
fill_in "password_confirm", :with => "password"
click_button "Reset"

u = User.first(:id => user.id)
refute u.hashed_password.nil?
refute u.email.nil?
assert_match "Password successfully set", page.body
assert_match "/", page.current_url
end

def test_user_password_reset_email_needed
u = Factory(:user, :email => nil)
a = Factory(:authorization, :user => u)
log_in(u, a.uid)

visit "/users/password_reset"

assert_match "Set Password", page.body

fill_in "password", :with => "password"
fill_in "password_confirm", :with => "password"
click_button "Reset"

assert_match "Email must be provided", page.body
assert_match "/users/password_reset", page.current_url
end

def test_user_password_reset_passwords_dont_match
u = Factory(:user, :email => "[email protected]")
log_in_email(u)

visit "/users/password_reset"

fill_in "password", :with => "password"
fill_in "password_confirm", :with => "pasord"
click_button "Reset"

assert_match "Passwords do not match", page.body
assert_match "/users/password_reset", page.current_url
end

def test_user_password_reset_no_password_present
u = Factory(:user, :email => "[email protected]")
log_in_email(u)

visit "/users/password_reset"

click_button "Reset"

assert_match "Password must be present", page.body
assert_match "/users/password_reset", page.current_url
end

def test_following_displays_username_logged_in
u = Factory(:user, :username => "dfnkt")
a = Factory(:authorization, :user => u)
Expand Down

0 comments on commit ac87702

Please sign in to comment.