From aac9c40cbac62b815ebec17c01298f7603c6dd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 15 Feb 2011 09:41:35 +0100 Subject: [PATCH] Ensure after hooks are called on registrations controller, closes #852 --- .../devise/registrations_controller.rb | 4 +-- test/integration/registerable_test.rb | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index 4976e688..a3a2a823 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -78,8 +78,8 @@ class Devise::RegistrationsController < ApplicationController end # Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for. - def redirect_for_sign_in(scope, resource) #:nodoc: - redirect_to stored_location_for(scope) || after_sign_up_path_for(resource) + def redirect_location(scope, resource) #:nodoc: + stored_location_for(scope) || after_sign_up_path_for(resource) end # The path used after sign up for inactive accounts. You need to overwrite diff --git a/test/integration/registerable_test.rb b/test/integration/registerable_test.rb index e7f32411..c04fee73 100644 --- a/test/integration/registerable_test.rb +++ b/test/integration/registerable_test.rb @@ -15,11 +15,27 @@ class RegistrationTest < ActionController::IntegrationTest assert_contain 'Welcome! You have signed up successfully.' assert warden.authenticated?(:admin) + assert_current_url "/admin_area/home" admin = Admin.last :order => "id" assert_equal admin.email, 'new_user@test.com' end + test 'a guest admin should be able to sign in and be redirected to a custom location' do + Devise::RegistrationsController.any_instance.stubs(:after_sign_up_path_for).returns("/?custom=1") + get new_admin_session_path + click_link 'Sign up' + + fill_in 'email', :with => 'new_user@test.com' + fill_in 'password', :with => 'new_user123' + fill_in 'password confirmation', :with => 'new_user123' + click_button 'Sign up' + + assert_contain 'Welcome! You have signed up successfully.' + assert warden.authenticated?(:admin) + assert_current_url "/?custom=1" + end + test 'a guest user should be able to sign up successfully and be blocked by confirmation' do get new_user_registration_path @@ -30,6 +46,7 @@ class RegistrationTest < ActionController::IntegrationTest assert_contain 'You have signed up successfully. However, we could not sign you in because your account is unconfirmed.' assert_not_contain 'You have to confirm your account before continuing' + assert_current_url "/" assert_not warden.authenticated?(:user) @@ -38,6 +55,19 @@ class RegistrationTest < ActionController::IntegrationTest assert_not user.confirmed? end + test 'a guest user should be blocked by confirmation and redirected to a custom path' do + Devise::RegistrationsController.any_instance.stubs(:after_inactive_sign_up_path_for).returns("/?custom=1") + get new_user_registration_path + + fill_in 'email', :with => 'new_user@test.com' + fill_in 'password', :with => 'new_user123' + fill_in 'password confirmation', :with => 'new_user123' + click_button 'Sign up' + + assert_current_url "/?custom=1" + assert_not warden.authenticated?(:user) + end + test 'a guest user cannot sign up with invalid information' do get new_user_registration_path