diff --git a/app/controllers/clearance/confirmations_controller.rb b/app/controllers/clearance/confirmations_controller.rb index 9f1e1250d..4c30ff3d0 100644 --- a/app/controllers/clearance/confirmations_controller.rb +++ b/app/controllers/clearance/confirmations_controller.rb @@ -1,9 +1,10 @@ class Clearance::ConfirmationsController < ApplicationController unloadable - before_filter :forbid_confirmed_user, :only => [:new, :create] - before_filter :forbid_missing_token, :only => [:new, :create] - before_filter :forbid_non_existent_user, :only => [:new, :create] + before_filter :redirect_signed_in_confirmed_user, :only => [:new, :create] + before_filter :forbid_confirmed_user, :only => [:new, :create] + before_filter :forbid_missing_token, :only => [:new, :create] + before_filter :forbid_non_existent_user, :only => [:new, :create] filter_parameter_logging :token def new @@ -21,6 +22,14 @@ def create private + def redirect_signed_in_confirmed_user + user = ::User.find_by_id(params[:user_id]) + if user && user.email_confirmed? && current_user == user + flash_success_after_create + redirect_to(url_after_create) + end + end + def forbid_confirmed_user user = ::User.find_by_id(params[:user_id]) if user && user.email_confirmed? @@ -49,4 +58,8 @@ def flash_success_after_create def url_after_create root_url end + + def url_already_confirmed + sign_up_url + end end diff --git a/generators/clearance_features/templates/features/sign_up.feature b/generators/clearance_features/templates/features/sign_up.feature index 27492d93a..b93277225 100644 --- a/generators/clearance_features/templates/features/sign_up.feature +++ b/generators/clearance_features/templates/features/sign_up.feature @@ -26,3 +26,11 @@ Feature: Sign up Then I should see "Confirmed email and signed in" And I should be signed in + Scenario: Signed in user clicks confirmation link again + Given I signed up with "email@person.com/password" + When I follow the confirmation link sent to "email@person.com" + Then I should be signed in + When I follow the confirmation link sent to "email@person.com" + Then I should see "Confirmed email and signed in" + And I should be signed in + diff --git a/shoulda_macros/clearance.rb b/shoulda_macros/clearance.rb index cc44b7ddd..10bc99c9e 100644 --- a/shoulda_macros/clearance.rb +++ b/shoulda_macros/clearance.rb @@ -132,6 +132,12 @@ def should_redirect_to_url_after_destroy end end + def should_redirect_to_url_already_confirmed + should_redirect_to("the already confirmed url") do + @controller.send(:url_already_confirmed) + end + end + # VALIDATIONS def should_validate_confirmation_of(attribute, opts = {}) diff --git a/test/controllers/confirmations_controller_test.rb b/test/controllers/confirmations_controller_test.rb index d41270794..540176948 100644 --- a/test/controllers/confirmations_controller_test.rb +++ b/test/controllers/confirmations_controller_test.rb @@ -45,12 +45,18 @@ class ConfirmationsControllerTest < ActionController::TestCase end end - context "a user with email confirmed" do - setup { @user = Factory(:email_confirmed_user) } - - should_forbid "on GET to #new with correct id" do - get :new, :user_id => @user.to_param + context "a signed in, confirmed user on GET to #new with token" do + setup do + @user = Factory(:user) + @token = @user.token + @user.confirm_email! + sign_in_as @user + get :new, :user_id => @user.to_param, :token => @token end + + should_set_the_flash_to /confirmed email/i + should_be_signed_in_as { @user } + should_redirect_to_url_after_create end context "no users" do