forked from hotsh/rstat.us
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|