2011-05-16 01:15:15 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class PasswordsControllerTest < ActionController::TestCase
|
|
|
|
include Devise::TestHelpers
|
|
|
|
setup do
|
|
|
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
|
|
|
@user = users(:erik)
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'should send password reset instructions if email address is found' do
|
|
|
|
num_deliveries = ActionMailer::Base.deliveries.size
|
2013-12-02 21:47:02 +00:00
|
|
|
post :create, :user => {:email => @user.email}
|
2011-05-16 01:15:15 +00:00
|
|
|
assert_equal num_deliveries + 1, ActionMailer::Base.deliveries.size
|
|
|
|
assert_response :success
|
|
|
|
email = ActionMailer::Base.deliveries.last
|
|
|
|
assert_equal [@user.email], email.to
|
2012-06-18 17:49:28 +00:00
|
|
|
assert_equal 'Reset password instructions', email.subject
|
2011-05-16 01:15:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should not send password reset instructions if email address is not found' do
|
2013-12-02 21:47:02 +00:00
|
|
|
post :create, :user => {:email => 'not_found@example.com'}
|
2011-05-16 01:15:15 +00:00
|
|
|
assert_response :error
|
|
|
|
end
|
|
|
|
|
2011-08-30 03:50:03 +00:00
|
|
|
test 'should render edit view' do
|
2013-12-02 21:47:02 +00:00
|
|
|
get :edit, :reset_password_token => 'token'
|
2011-08-30 03:50:03 +00:00
|
|
|
assert_response :success
|
|
|
|
end
|
2011-05-16 01:15:15 +00:00
|
|
|
|
|
|
|
test 'should reset user password with an valid reset password token' do
|
2013-12-02 12:07:18 +00:00
|
|
|
token = @user.send_reset_password_instructions
|
2013-12-02 21:47:02 +00:00
|
|
|
put :update, :user => {:reset_password_token => token, :password => 'new_password'}
|
2011-05-16 01:15:15 +00:00
|
|
|
@user.reload
|
|
|
|
assert @user.valid_password?('new_password')
|
2011-08-30 03:50:03 +00:00
|
|
|
assert_response :redirect
|
2013-12-02 21:47:02 +00:00
|
|
|
assert_redirected_to :controller => 'main', :action => 'index'
|
2011-05-16 01:15:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'should not reset user password with an invalid reset password token' do
|
2013-12-02 12:07:18 +00:00
|
|
|
@user.send_reset_password_instructions
|
2013-12-02 21:47:02 +00:00
|
|
|
put :update, :user => {:reset_password_token => 'invalid_token', :password => 'new_password'}
|
2011-08-30 03:50:03 +00:00
|
|
|
@user.reload
|
|
|
|
assert !@user.valid_password?('new_password')
|
|
|
|
assert_response :redirect
|
2013-12-02 21:47:02 +00:00
|
|
|
assert_redirected_to :controller => 'main', :action => 'index'
|
2011-05-16 01:15:15 +00:00
|
|
|
end
|
|
|
|
end
|