1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Add cancel to registrations controller as a way to delete information from session.

This commit is contained in:
José Valim 2010-07-15 21:58:35 +02:00
parent d0d88cf259
commit ac8221aca7
6 changed files with 47 additions and 4 deletions

View file

@ -1,5 +1,5 @@
class Devise::RegistrationsController < ApplicationController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
include Devise::Controllers::InternalHelpers
@ -45,6 +45,14 @@ class Devise::RegistrationsController < ApplicationController
sign_out_and_redirect(self.resource)
end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now.
def cancel
expire_session_data_after_sign_in!
redirect_to new_registration_path(resource_name)
end
protected
# Build a devise resource passing in the session. Useful to move

View file

@ -216,8 +216,15 @@ module ActionDispatch::Routing
end
def devise_registration(mapping, controllers) #:nodoc:
resource :registration, :only => [:new, :create, :edit, :update, :destroy], :path => mapping.path_names[:registration],
:path_names => { :new => mapping.path_names[:sign_up] }, :controller => controllers[:registrations]
path_names = {
:new => mapping.path_names[:sign_up],
:cancel => mapping.path_names[:cancel]
}
resource :registration, :except => :show, :path => mapping.path_names[:registration],
:path_names => path_names, :controller => controllers[:registrations] do
get :cancel
end
end
def devise_oauth_callback(mapping, controllers) #:nodoc:

View file

@ -150,4 +150,16 @@ class RegistrationTest < ActionController::IntegrationTest
assert User.all.empty?
end
test 'a user should be able to cancel sign up by deleting data in the session' do
get "/set"
assert_equal "something", @request.session["user_facebook_oauth_token"]
get "/users/sign_up"
assert_equal "something", @request.session["user_facebook_oauth_token"]
get "/users/cancel"
assert_nil @request.session["user_facebook_oauth_token"]
assert_redirected_to new_user_registration_path
end
end

View file

@ -4,4 +4,9 @@ class HomeController < ApplicationController
def private
end
def set
session["user_facebook_oauth_token"] = "something"
head :ok
end
end

View file

@ -39,9 +39,10 @@ Rails.application.routes.draw do
:sign_in => "login", :sign_out => "logout",
:password => "secret", :confirmation => "verification",
:unlock => "unblock", :sign_up => "register",
:registration => "management"
:registration => "management", :cancel => "giveup"
}
end
match "/set", :to => "home#set"
root :to => "home#index"
end

View file

@ -86,6 +86,11 @@ class DefaultRoutingTest < ActionController::TestCase
assert_recognizes({:controller => 'devise/registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
end
test 'map cancel user registration' do
assert_recognizes({:controller => 'devise/registrations', :action => 'cancel'}, {:path => 'users/cancel', :method => :get})
assert_named_route "/users/cancel", :cancel_user_registration_path
end
test 'map oauth callbacks' do
assert_recognizes({:controller => 'devise/oauth_callbacks', :action => 'facebook'}, {:path => 'users/oauth/facebook/callback', :method => :get})
assert_recognizes({:controller => 'devise/oauth_callbacks', :action => 'github'}, {:path => 'users/oauth/github/callback', :method => :get})
@ -140,6 +145,11 @@ class CustomizedRoutingTest < ActionController::TestCase
test 'map account with custom path name for registration' do
assert_recognizes({:controller => 'devise/registrations', :action => 'new', :locale => 'en'}, '/en/accounts/management/register')
end
test 'map account with custom path name for cancel registration' do
assert_recognizes({:controller => 'devise/registrations', :action => 'cancel', :locale => 'en'}, '/en/accounts/management/giveup')
end
end
class ScopedRoutingTest < ActionController::TestCase