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

simplification (sign_out_everybody => sign_out_all_scopes)

This commit is contained in:
Denis Lifanov 2010-06-24 21:38:49 +08:00 committed by José Valim
parent f864259f1e
commit 819db39263
5 changed files with 18 additions and 51 deletions

View file

@ -18,10 +18,6 @@ class Devise::SessionsController < ApplicationController
# GET /resource/sign_out
def destroy
set_flash_message :notice, :signed_out if signed_in?(resource_name)
if Devise.sign_out_scoped
sign_out_and_redirect(resource_name)
else
sign_out_everybody_and_redirect(resource_name)
end
sign_out_and_redirect(resource_name)
end
end

View file

@ -157,8 +157,8 @@ module Devise
@@warden_config = nil
@@warden_config_block = nil
mattr_accessor :sign_out_scoped
@@sign_out_scoped = true
mattr_accessor :sign_out_all_scopes
@@sign_out_all_scopes = true
# Default way to setup Devise. Run rails generate devise_install to create
# a fresh initializer with all configuration values.

View file

@ -66,7 +66,7 @@ module Devise
# Sign out all active users or scopes. This helper is useful for signing out all roles
# in one click.
def sign_out_everybody
def sign_out_all_scopes
# Not "warden.logout" since we need to sign_out only devise-defined scopes.
scopes = Devise.mappings.keys
scopes.each { |scope| warden.user(scope) }
@ -158,16 +158,6 @@ module Devise
root_path
end
# Method used by sessions controller to sign out all roles. You can overwrite
# it in your ApplicationController to provide a custom hook for a custom
# scope. Notice that differently from +after_sign_in_path_for+ this method
# receives a symbol with the scope, and not the resource.
#
# By default is the current sign_out_path_for.
def after_sign_out_everybody_path_for(resource_or_scope)
after_sign_out_path_for(resource_or_scope)
end
# Sign in an user and tries to redirect first to the stored location and
# then to the url specified by after_sign_in_path_for.
#
@ -184,18 +174,14 @@ module Devise
# after_sign_out_path_for.
def sign_out_and_redirect(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
sign_out(scope)
if Devise.sign_out_all_scopes
sign_out(scope)
else
sign_out_all_scopes
end
redirect_to after_sign_out_path_for(scope)
end
# Sign out all users and tries to redirect to the url specified by
# after_sign_out_everybody_path_for.
def sign_out_everybody_and_redirect(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope) # just to maintain sign_out paths
sign_out_everybody
redirect_to after_sign_out_everybody_path_for(scope)
end
# Define authentication filters and accessor helpers based on mappings.
# These filters should be used inside the controllers as before_filters,
# so you can control the scope of the user who should be signed in to

View file

@ -132,7 +132,7 @@ class ControllerAuthenticableTest < ActionController::TestCase
}
@mock_warden.expects(:logout).with(*Devise.mappings.keys).returns(true)
@controller.sign_out_everybody
@controller.sign_out_all_scopes
end
test 'stored location for returns the location for a given scope' do
@ -174,13 +174,6 @@ class ControllerAuthenticableTest < ActionController::TestCase
assert_equal root_path, @controller.after_sign_out_path_for(:user)
end
test 'after sign out everybody path defaults to the sign out path' do
@controller.expects(:after_sign_out_path_for).with(:admin).returns(:custom_admin_path)
@controller.expects(:after_sign_out_path_for).with(:user).returns(:custom_user_path)
assert_equal :custom_admin_path, @controller.after_sign_out_everybody_path_for(:admin)
assert_equal :custom_user_path, @controller.after_sign_out_everybody_path_for(:user)
end
test 'sign in and redirect uses the stored location' do
user = User.new
@controller.session[:"user_return_to"] = "/foo.bar"
@ -214,13 +207,6 @@ class ControllerAuthenticableTest < ActionController::TestCase
@controller.sign_out_and_redirect(:admin)
end
test 'sign out everybody and redirect uses the configured after sign out everybody path' do
@controller.expects(:sign_out_everybody).returns(true) # since we're know that it's a proxy
@controller.expects(:redirect_to).with(admin_root_path)
@controller.instance_eval "def after_sign_out_everybody_path_for(resource); admin_root_path; end"
@controller.sign_out_everybody_and_redirect(:admin)
end
test 'is not a devise controller' do
assert_not @controller.devise_controller?
end

View file

@ -3,11 +3,11 @@ require 'test_helper'
class AuthenticationSanityTest < ActionController::IntegrationTest
def setup
Devise.sign_out_scoped = true
Devise.sign_out_all_scopes = true
end
def teardown
Devise.sign_out_scoped = true
Devise.sign_out_all_scopes = true
end
test 'home should be accessible without sign in' do
@ -38,7 +38,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
assert warden.authenticated?(:admin)
end
test 'sign out as user should not touch admin authentication if sign_out_scoped' do
test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do
sign_in_as_user
sign_in_as_admin
@ -47,7 +47,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
assert warden.authenticated?(:admin)
end
test 'sign out as admin should not touch user authentication if sign_out_scoped' do
test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do
sign_in_as_user
sign_in_as_admin
@ -56,19 +56,18 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
assert warden.authenticated?(:user)
end
test 'sign out as user should also sign out admin unless sign_out_scoped' do
Devise.sign_out_scoped = false
test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do
Devise.sign_out_all_scopes = false
sign_in_as_user
sign_in_as_admin
get destroy_user_session_path
assert_not warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
Devise.sign_out_scoped = true
end
test 'sign out as admin should also sign out user unless sign_out_scoped' do
Devise.sign_out_scoped = false
test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do
Devise.sign_out_all_scopes = false
sign_in_as_user
sign_in_as_admin