mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
sign_out_everybody helper (as a convenient proxy to warden)
This commit is contained in:
parent
7a45043bc8
commit
1924a915a8
2 changed files with 40 additions and 0 deletions
|
@ -64,6 +64,13 @@ module Devise
|
|||
warden.logout(scope)
|
||||
end
|
||||
|
||||
def sign_out_everybody
|
||||
# Not "warden.logout" since we need to sign_out only devise-defined scopes.
|
||||
Devise.mappings.keys.each { |scope| warden.user(scope) }
|
||||
warden.raw_session.inspect
|
||||
warden.logout(*Devise.mappings.keys)
|
||||
end
|
||||
|
||||
# Returns and delete the url stored in the session for the given scope. Useful
|
||||
# for giving redirect backs after sign up:
|
||||
#
|
||||
|
@ -148,6 +155,10 @@ module Devise
|
|||
root_path
|
||||
end
|
||||
|
||||
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.
|
||||
#
|
||||
|
@ -168,6 +179,12 @@ module Devise
|
|||
redirect_to after_sign_out_path_for(scope)
|
||||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -126,6 +126,15 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|||
@controller.sign_out(User.new)
|
||||
end
|
||||
|
||||
test 'sign out everybody proxy to logout on warden' do
|
||||
Devise.mappings.keys.each { |scope|
|
||||
@mock_warden.expects(:user).with(scope).returns(true)
|
||||
}
|
||||
|
||||
@mock_warden.expects(:logout).with(*Devise.mappings.keys).returns(true)
|
||||
@controller.sign_out_everybody
|
||||
end
|
||||
|
||||
test 'stored location for returns the location for a given scope' do
|
||||
assert_nil @controller.stored_location_for(:user)
|
||||
@controller.session[:"user_return_to"] = "/foo.bar"
|
||||
|
@ -165,6 +174,13 @@ 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"
|
||||
|
@ -198,6 +214,13 @@ 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
|
||||
|
|
Loading…
Add table
Reference in a new issue