Skip to content

Commit

Permalink
new scenario handled: signed in user clicks confirmation link again
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Croak committed Aug 4, 2009
1 parent 03406c0 commit 3b3b321
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
19 changes: 16 additions & 3 deletions 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
Expand All @@ -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?
Expand Down Expand Up @@ -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
Expand Up @@ -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

6 changes: 6 additions & 0 deletions shoulda_macros/clearance.rb
Expand Up @@ -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 = {})
Expand Down
16 changes: 11 additions & 5 deletions test/controllers/confirmations_controller_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 3b3b321

Please sign in to comment.