Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for `destory_user_session_path` in another non-navigation…

…al formats such as JSON and XML

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 0487e9eafece72c85197241ff814d87d7896b79b 1 parent 73669e0
@sikachu sikachu authored josevalim committed
View
10 app/controllers/devise/sessions_controller.rb
@@ -19,7 +19,15 @@ def create
# 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
28 test/integration/authenticatable_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.