Skip to content

Commit

Permalink
Add integration test for "reset password"
Browse files Browse the repository at this point in the history
Note that we actually extract the activation URL from the e-mail and
pass it directly to 'visit'.
  • Loading branch information
emk committed Dec 27, 2008
1 parent d40725e commit cd63c14
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions test/integration/login_test.rb
Expand Up @@ -5,33 +5,58 @@ def setup
@site = Site.make
@user = User.make(:login => "sarah", :password => "password",
:admin => true, :password_confirmation => "password")
assert User.authenticate_for(@site, "sarah", "password")
visit "/admin"
end

test "should log in with valid username and password" do
visit "/admin"
log_in_with "sarah", "password"
assert_logged_in_as @user
end

test "should remember users when 'Remember me' is checked" do
visit "/admin"
log_in_with "sarah", "password", :remember_me => true
assert_logged_in_as @user, :remembered => true
end

test "should fail to log in with invalid user" do
visit "/admin"
log_in_with "invalid", "password"
assert_not_logged_in
assert_equal('Could not log you in. Are you sure your Login name ' +
'and Password are correct?', flash[:error])
end

test "should fail to log in with invalid password" do
visit "/admin"
log_in_with "sarah", "invalid"
assert_not_logged_in
end

test "should reset password if given valid email" do
@emails = ActionMailer::Base.deliveries
@emails.clear

assert_difference @emails, :size, 1 do
click_link "reset password"
fill_in "email", :with => @user.email
click_button "Reset"
end
assert_equal @user.email, @emails.first.to.first
assert_not_logged_in

# Extract the activation URL from the e-mail.
@emails.first.body =~ %r{(http://[^ ]*)}
activation_url = $1
assert_not_nil activation_url

visit activation_url
assert_logged_in_as @user

fill_in "Password", :with => "newpass"
fill_in "Password confirmation", :with => "newpass"
click_button "Save my profile"

assert User.authenticate_for(@site, @user.login, "newpass")
end

def log_in_with login, password, options={}
options[:remember_me] ||= false

Expand Down

0 comments on commit cd63c14

Please sign in to comment.