Permalink
Browse files

Added ability to override redirect_to path after sending reset passwo…

…rd instructions
  • Loading branch information...
1 parent efc42d7 commit ddec65673883e3eb872d48ce2658cacc80b9691a @0x000000 0x000000 committed Mar 29, 2012
@@ -14,7 +14,7 @@ def create
if resource.errors.empty?
set_flash_message :notice, :send_instructions
- redirect_to new_session_path(resource_name)
+ redirect_to after_sending_reset_password_instructions_path_for(resource_name)
else
render_with_scope :new
end
@@ -38,4 +38,10 @@ def update
render_with_scope :edit
end
end
+
+ protected
+
+ def after_sending_reset_password_instructions_path_for(resource_name)
+ new_session_path(resource_name)
+ end
end
@@ -32,6 +32,12 @@ def reset_password(options={}, &block)
click_button 'Change my password'
end
+ def redefine_after_reset_password_path
+ PasswordsController.send :define_method, :after_sending_reset_password_instructions_path_for do |r_name|
+ '/any_url_you_wish'
+ end
+ end
+
test 'authenticated user should not be able to visit forgot password page' do
sign_in_as_user
assert warden.authenticated?(:user)
@@ -50,6 +56,15 @@ def reset_password(options={}, &block)
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
end
+ test 'programmers should be able to redefine redirect path after user resets password' do
+ create_user
+ redefine_after_reset_password_path
+ request_forgot_password
+
+ assert_response :success
+ assert_template 'home/index'
+ end
+
test 'not authenticated user with invalid email should receive an error message' do
request_forgot_password do
fill_in 'email', :with => 'invalid.test@test.com'
@@ -20,6 +20,7 @@
map.admin_root '/admin_area/home', :controller => "admins", :action => "index"
map.connect '/sign_in', :controller => "sessions", :action => "new"
+ map.connect '/any_url_you_wish', :controller => 'home', :action => 'index'
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end

0 comments on commit ddec656

Please sign in to comment.