Set the new default of sign_out_via config
This commit is contained in:
parent
896521be73
commit
1ddca80cee
|
@ -218,19 +218,8 @@ module Devise
|
||||||
@@sign_out_all_scopes = true
|
@@sign_out_all_scopes = true
|
||||||
|
|
||||||
# The default method used while signing out
|
# The default method used while signing out
|
||||||
# TODO: 4.1 Do: @@sign_out_via = :delete
|
mattr_accessor :sign_out_via
|
||||||
mattr_reader :sign_out_via
|
@@sign_out_via = :delete
|
||||||
@@sign_out_via = :get
|
|
||||||
|
|
||||||
def self.sign_out_via=(sign_out_via)
|
|
||||||
app_set_configs << :sign_out_via
|
|
||||||
@@sign_out_via = sign_out_via
|
|
||||||
end
|
|
||||||
|
|
||||||
def sign_out_via=(sign_out_via)
|
|
||||||
app_set_configs << :sign_out_via
|
|
||||||
@@sign_out_via = sign_out_via
|
|
||||||
end
|
|
||||||
|
|
||||||
# The parent controller all Devise controllers inherits from.
|
# The parent controller all Devise controllers inherits from.
|
||||||
# Defaults to ApplicationController. This should be set early
|
# Defaults to ApplicationController. This should be set early
|
||||||
|
@ -295,8 +284,6 @@ module Devise
|
||||||
# a fresh initializer with all configuration values.
|
# a fresh initializer with all configuration values.
|
||||||
def self.setup
|
def self.setup
|
||||||
yield self
|
yield self
|
||||||
|
|
||||||
warn_default_config_changed(:sign_out_via, ':get', ':delete')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.warn_default_config_changed(config, current_default, new_default)
|
def self.warn_default_config_changed(config, current_default, new_default)
|
||||||
|
|
|
@ -35,24 +35,6 @@ class DeviseTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'setup block warns about defaults changing' do
|
|
||||||
Devise.app_set_configs = Set.new
|
|
||||||
|
|
||||||
ActiveSupport::Deprecation.expects(:warn).with() { |value| value =~ /sign_out_via/ }
|
|
||||||
|
|
||||||
Devise.setup do
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test 'setup block doest not warns when the change is explicit set' do
|
|
||||||
ActiveSupport::Deprecation.expects(:warn).never
|
|
||||||
|
|
||||||
swap Devise, sign_out_via: :get do
|
|
||||||
Devise.setup do
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
test 'stores warden configuration' do
|
test 'stores warden configuration' do
|
||||||
assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
|
assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
|
||||||
assert_equal :user, Devise.warden_config.default_scope
|
assert_equal :user, Devise.warden_config.default_scope
|
||||||
|
|
|
@ -30,7 +30,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||||
swap Devise, sign_out_all_scopes: false do
|
swap Devise, sign_out_all_scopes: false do
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
sign_in_as_admin
|
sign_in_as_admin
|
||||||
get destroy_user_session_path
|
delete destroy_user_session_path
|
||||||
assert_not warden.authenticated?(:user)
|
assert_not warden.authenticated?(:user)
|
||||||
assert warden.authenticated?(:admin)
|
assert warden.authenticated?(:admin)
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
sign_in_as_admin
|
sign_in_as_admin
|
||||||
|
|
||||||
get destroy_admin_session_path
|
delete destroy_admin_session_path
|
||||||
assert_not warden.authenticated?(:admin)
|
assert_not warden.authenticated?(:admin)
|
||||||
assert warden.authenticated?(:user)
|
assert warden.authenticated?(:user)
|
||||||
end
|
end
|
||||||
|
@ -52,7 +52,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
sign_in_as_admin
|
sign_in_as_admin
|
||||||
|
|
||||||
get destroy_user_session_path
|
delete destroy_user_session_path
|
||||||
assert_not warden.authenticated?(:user)
|
assert_not warden.authenticated?(:user)
|
||||||
assert_not warden.authenticated?(:admin)
|
assert_not warden.authenticated?(:admin)
|
||||||
end
|
end
|
||||||
|
@ -63,7 +63,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
sign_in_as_admin
|
sign_in_as_admin
|
||||||
|
|
||||||
get destroy_admin_session_path
|
delete destroy_admin_session_path
|
||||||
assert_not warden.authenticated?(:admin)
|
assert_not warden.authenticated?(:admin)
|
||||||
assert_not warden.authenticated?(:user)
|
assert_not warden.authenticated?(:user)
|
||||||
end
|
end
|
||||||
|
@ -109,7 +109,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||||
sign_in_as_admin
|
sign_in_as_admin
|
||||||
assert warden.authenticated?(:admin)
|
assert warden.authenticated?(:admin)
|
||||||
|
|
||||||
get destroy_admin_session_path
|
delete destroy_admin_session_path
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_redirected_to root_path
|
assert_redirected_to root_path
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'unauthenticated admin set message on sign out' do
|
test 'unauthenticated admin set message on sign out' do
|
||||||
get destroy_admin_session_path
|
delete destroy_admin_session_path
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_redirected_to root_path
|
assert_redirected_to root_path
|
||||||
|
|
||||||
|
@ -501,34 +501,34 @@ class AuthenticationOthersTest < Devise::IntegrationTest
|
||||||
|
|
||||||
test 'sign out with html redirects' do
|
test 'sign out with html redirects' do
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
get destroy_user_session_path
|
delete destroy_user_session_path
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_current_url '/'
|
assert_current_url '/'
|
||||||
|
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
get destroy_user_session_path(format: 'html')
|
delete destroy_user_session_path(format: 'html')
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_current_url '/'
|
assert_current_url '/'
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'sign out with xml format returns no content' do
|
test 'sign out with xml format returns no content' do
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
get destroy_user_session_path(format: 'xml')
|
delete destroy_user_session_path(format: 'xml')
|
||||||
assert_response :no_content
|
assert_response :no_content
|
||||||
assert_not warden.authenticated?(:user)
|
assert_not warden.authenticated?(:user)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'sign out with json format returns no content' do
|
test 'sign out with json format returns no content' do
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
get destroy_user_session_path(format: 'json')
|
delete destroy_user_session_path(format: 'json')
|
||||||
assert_response :no_content
|
assert_response :no_content
|
||||||
assert_not warden.authenticated?(:user)
|
assert_not warden.authenticated?(:user)
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'sign out with non-navigational format via XHR does not redirect' do
|
test 'sign out with non-navigational format via XHR does not redirect' do
|
||||||
swap Devise, navigational_formats: ['*/*', :html] do
|
swap Devise, navigational_formats: ['*/*', :html] do
|
||||||
sign_in_as_user
|
sign_in_as_admin
|
||||||
get destroy_user_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
|
get destroy_sign_out_via_get_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
|
||||||
assert_response :no_content
|
assert_response :no_content
|
||||||
assert_not warden.authenticated?(:user)
|
assert_not warden.authenticated?(:user)
|
||||||
end
|
end
|
||||||
|
@ -538,7 +538,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
|
||||||
test 'sign out with navigational format via XHR does redirect' do
|
test 'sign out with navigational format via XHR does redirect' do
|
||||||
swap Devise, navigational_formats: ['*/*', :html] do
|
swap Devise, navigational_formats: ['*/*', :html] do
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
get destroy_user_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "text/html,*/*" }
|
delete destroy_user_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "text/html,*/*" }
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_not warden.authenticated?(:user)
|
assert_not warden.authenticated?(:user)
|
||||||
end
|
end
|
||||||
|
|
|
@ -182,7 +182,7 @@ class RememberMeTest < Devise::IntegrationTest
|
||||||
get users_path
|
get users_path
|
||||||
assert warden.authenticated?(:user)
|
assert warden.authenticated?(:user)
|
||||||
|
|
||||||
get destroy_user_session_path
|
delete destroy_user_session_path
|
||||||
assert_not warden.authenticated?(:user)
|
assert_not warden.authenticated?(:user)
|
||||||
assert_nil warden.cookies['remember_user_token']
|
assert_nil warden.cookies['remember_user_token']
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ class SessionTimeoutTest < Devise::IntegrationTest
|
||||||
user = sign_in_as_user
|
user = sign_in_as_user
|
||||||
get expire_user_path(user)
|
get expire_user_path(user)
|
||||||
|
|
||||||
get destroy_user_session_path
|
delete destroy_user_session_path
|
||||||
|
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_redirected_to root_path
|
assert_redirected_to root_path
|
||||||
|
|
|
@ -16,7 +16,7 @@ class TrackableHooksTest < Devise::IntegrationTest
|
||||||
assert_equal user.current_sign_in_at, user.last_sign_in_at
|
assert_equal user.current_sign_in_at, user.last_sign_in_at
|
||||||
assert user.current_sign_in_at >= user.created_at
|
assert user.current_sign_in_at >= user.created_at
|
||||||
|
|
||||||
visit destroy_user_session_path
|
delete destroy_user_session_path
|
||||||
new_time = 2.seconds.from_now
|
new_time = 2.seconds.from_now
|
||||||
Time.stubs(:now).returns(new_time)
|
Time.stubs(:now).returns(new_time)
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class TrackableHooksTest < Devise::IntegrationTest
|
||||||
user.reload
|
user.reload
|
||||||
assert_equal 1, user.sign_in_count
|
assert_equal 1, user.sign_in_count
|
||||||
|
|
||||||
visit destroy_user_session_path
|
delete destroy_user_session_path
|
||||||
sign_in_as_user
|
sign_in_as_user
|
||||||
user.reload
|
user.reload
|
||||||
assert_equal 2, user.sign_in_count
|
assert_equal 2, user.sign_in_count
|
||||||
|
@ -80,7 +80,7 @@ class TrackableHooksTest < Devise::IntegrationTest
|
||||||
end
|
end
|
||||||
user.reload
|
user.reload
|
||||||
assert_equal 0, user.sign_in_count
|
assert_equal 0, user.sign_in_count
|
||||||
visit destroy_user_session_path
|
delete destroy_user_session_path
|
||||||
|
|
||||||
sign_in_as_user do
|
sign_in_as_user do
|
||||||
header 'devise.skip_trackable', false
|
header 'devise.skip_trackable', false
|
||||||
|
|
|
@ -35,8 +35,8 @@ class MappingTest < ActiveSupport::TestCase
|
||||||
assert_equal [], Devise.mappings[:skip_admin].used_routes
|
assert_equal [], Devise.mappings[:skip_admin].used_routes
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'sign_out_via defaults to :get' do
|
test 'sign_out_via defaults to :delete' do
|
||||||
assert_equal :get, Devise.mappings[:user].sign_out_via
|
assert_equal :delete, Devise.mappings[:user].sign_out_via
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'allows custom sign_out_via to be given' do
|
test 'allows custom sign_out_via to be given' do
|
||||||
|
|
|
@ -114,6 +114,7 @@ Rails.application.routes.draw do
|
||||||
namespace :sign_out_via, module: "devise" do
|
namespace :sign_out_via, module: "devise" do
|
||||||
devise_for :deletes, sign_out_via: :delete, class_name: "Admin"
|
devise_for :deletes, sign_out_via: :delete, class_name: "Admin"
|
||||||
devise_for :posts, sign_out_via: :post, class_name: "Admin"
|
devise_for :posts, sign_out_via: :post, class_name: "Admin"
|
||||||
|
devise_for :gets, sign_out_via: :get, class_name: "Admin"
|
||||||
devise_for :delete_or_posts, sign_out_via: [:delete, :post], class_name: "Admin"
|
devise_for :delete_or_posts, sign_out_via: [:delete, :post], class_name: "Admin"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class DefaultRoutingTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'map destroy user session' do
|
test 'map destroy user session' do
|
||||||
assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: 'users/sign_out', method: :get})
|
assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: 'users/sign_out', method: :delete})
|
||||||
assert_named_route "/users/sign_out", :destroy_user_session_path
|
assert_named_route "/users/sign_out", :destroy_user_session_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ class CustomizedRoutingTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'map account with custom path name for session sign out' do
|
test 'map account with custom path name for session sign out' do
|
||||||
assert_recognizes({controller: 'devise/sessions', action: 'destroy', locale: 'en'}, '/en/accounts/logout')
|
assert_recognizes({controller: 'devise/sessions', action: 'destroy', locale: 'en'}, {path: '/en/accounts/logout', method: :delete })
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'map account with custom path name for password' do
|
test 'map account with custom path name for password' do
|
||||||
|
|
Loading…
Reference in New Issue