Set the new default of sign_out_via config

This commit is contained in:
Ulisses Almeida 2016-04-26 19:12:05 -03:00
parent 896521be73
commit 1ddca80cee
9 changed files with 25 additions and 55 deletions

View File

@ -218,19 +218,8 @@ module Devise
@@sign_out_all_scopes = true
# The default method used while signing out
# TODO: 4.1 Do: @@sign_out_via = :delete
mattr_reader :sign_out_via
@@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
mattr_accessor :sign_out_via
@@sign_out_via = :delete
# The parent controller all Devise controllers inherits from.
# Defaults to ApplicationController. This should be set early
@ -295,8 +284,6 @@ module Devise
# a fresh initializer with all configuration values.
def self.setup
yield self
warn_default_config_changed(:sign_out_via, ':get', ':delete')
end
def self.warn_default_config_changed(config, current_default, new_default)

View File

@ -35,24 +35,6 @@ class DeviseTest < ActiveSupport::TestCase
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
assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
assert_equal :user, Devise.warden_config.default_scope

View File

@ -30,7 +30,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
swap Devise, sign_out_all_scopes: false do
sign_in_as_user
sign_in_as_admin
get destroy_user_session_path
delete destroy_user_session_path
assert_not warden.authenticated?(:user)
assert warden.authenticated?(:admin)
end
@ -41,7 +41,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
sign_in_as_user
sign_in_as_admin
get destroy_admin_session_path
delete destroy_admin_session_path
assert_not warden.authenticated?(:admin)
assert warden.authenticated?(:user)
end
@ -52,7 +52,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
sign_in_as_user
sign_in_as_admin
get destroy_user_session_path
delete destroy_user_session_path
assert_not warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
end
@ -63,7 +63,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
sign_in_as_user
sign_in_as_admin
get destroy_admin_session_path
delete destroy_admin_session_path
assert_not warden.authenticated?(:admin)
assert_not warden.authenticated?(:user)
end
@ -109,7 +109,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
sign_in_as_admin
assert warden.authenticated?(:admin)
get destroy_admin_session_path
delete destroy_admin_session_path
assert_response :redirect
assert_redirected_to root_path
@ -119,7 +119,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
end
test 'unauthenticated admin set message on sign out' do
get destroy_admin_session_path
delete destroy_admin_session_path
assert_response :redirect
assert_redirected_to root_path
@ -501,34 +501,34 @@ class AuthenticationOthersTest < Devise::IntegrationTest
test 'sign out with html redirects' do
sign_in_as_user
get destroy_user_session_path
delete destroy_user_session_path
assert_response :redirect
assert_current_url '/'
sign_in_as_user
get destroy_user_session_path(format: 'html')
delete destroy_user_session_path(format: 'html')
assert_response :redirect
assert_current_url '/'
end
test 'sign out with xml format returns no content' do
sign_in_as_user
get destroy_user_session_path(format: 'xml')
delete destroy_user_session_path(format: 'xml')
assert_response :no_content
assert_not warden.authenticated?(:user)
end
test 'sign out with json format returns no content' do
sign_in_as_user
get destroy_user_session_path(format: 'json')
delete destroy_user_session_path(format: 'json')
assert_response :no_content
assert_not warden.authenticated?(:user)
end
test 'sign out with non-navigational format via XHR does not redirect' do
swap Devise, navigational_formats: ['*/*', :html] do
sign_in_as_user
get destroy_user_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
sign_in_as_admin
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_not warden.authenticated?(:user)
end
@ -538,7 +538,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
test 'sign out with navigational format via XHR does redirect' do
swap Devise, navigational_formats: ['*/*', :html] do
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_not warden.authenticated?(:user)
end

View File

@ -182,7 +182,7 @@ class RememberMeTest < Devise::IntegrationTest
get users_path
assert warden.authenticated?(:user)
get destroy_user_session_path
delete destroy_user_session_path
assert_not warden.authenticated?(:user)
assert_nil warden.cookies['remember_user_token']

View File

@ -89,7 +89,7 @@ class SessionTimeoutTest < Devise::IntegrationTest
user = sign_in_as_user
get expire_user_path(user)
get destroy_user_session_path
delete destroy_user_session_path
assert_response :redirect
assert_redirected_to root_path

View File

@ -16,7 +16,7 @@ class TrackableHooksTest < Devise::IntegrationTest
assert_equal user.current_sign_in_at, user.last_sign_in_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
Time.stubs(:now).returns(new_time)
@ -56,7 +56,7 @@ class TrackableHooksTest < Devise::IntegrationTest
user.reload
assert_equal 1, user.sign_in_count
visit destroy_user_session_path
delete destroy_user_session_path
sign_in_as_user
user.reload
assert_equal 2, user.sign_in_count
@ -80,7 +80,7 @@ class TrackableHooksTest < Devise::IntegrationTest
end
user.reload
assert_equal 0, user.sign_in_count
visit destroy_user_session_path
delete destroy_user_session_path
sign_in_as_user do
header 'devise.skip_trackable', false

View File

@ -35,8 +35,8 @@ class MappingTest < ActiveSupport::TestCase
assert_equal [], Devise.mappings[:skip_admin].used_routes
end
test 'sign_out_via defaults to :get' do
assert_equal :get, Devise.mappings[:user].sign_out_via
test 'sign_out_via defaults to :delete' do
assert_equal :delete, Devise.mappings[:user].sign_out_via
end
test 'allows custom sign_out_via to be given' do

View File

@ -114,6 +114,7 @@ Rails.application.routes.draw do
namespace :sign_out_via, module: "devise" do
devise_for :deletes, sign_out_via: :delete, 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"
end

View File

@ -14,7 +14,7 @@ class DefaultRoutingTest < ActionController::TestCase
end
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
end
@ -146,7 +146,7 @@ class CustomizedRoutingTest < ActionController::TestCase
end
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
test 'map account with custom path name for password' do