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

Add support for destory_user_session_path in another non-navigational formats such as JSON and XML

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Prem Sichanugrist 2011-01-16 20:31:37 +07:00 committed by José Valim
parent 73669e09c8
commit 0487e9eafe
2 changed files with 30 additions and 8 deletions

View file

@ -19,7 +19,15 @@ class Devise::SessionsController < ApplicationController
# GET /resource/sign_out
def destroy
signed_in = signed_in?(resource_name)
sign_out_and_redirect(resource_name)
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message :notice, :signed_out if signed_in
# We actually need to hard coded this, as Rails default responder doesn't
# support returning empty response on GET request
respond_to do |format|
format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name) }
format.xml { head :ok }
format.json { render :text => '{}', :status => :ok }
end
end
end

View file

@ -205,13 +205,6 @@ class AuthenticationRedirectTest < ActionController::IntegrationTest
assert_nil session[:"user_return_to"]
end
test 'sign in with xml format returns xml response' do
create_user
post user_session_path(:format => 'xml', :user => {:email => "user@test.com", :password => '123456'})
assert_response :success
assert_match /<\?xml version="1.0" encoding="UTF-8"\?>/, response.body
end
test 'redirect to configured home path for a given scope after sign in' do
sign_in_as_admin
assert_equal "/admin_area/home", @request.path
@ -354,6 +347,27 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin)
end
test 'sign in with xml format returns xml response' do
create_user
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '123456'}
assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end
test 'sign out with xml format returns ok response' do
sign_in_as_user
get destroy_user_session_path(:format => 'xml')
assert_response :ok
assert_not warden.authenticated?(:user)
end
test 'sign out with json format returns empty json response' do
sign_in_as_user
get destroy_user_session_path(:format => 'json')
assert_response :ok
assert_not warden.authenticated?(:user)
end
end
class AuthenticationRequestKeysTest < ActionController::IntegrationTest