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

Make it possible to unit-test extensions to Devise::SessionsController

This time with tests
This commit is contained in:
John Wilger 2011-04-10 11:43:52 +08:00 committed by José Valim
parent e4af6adaf7
commit 0e904dda79

View file

@ -11,6 +11,17 @@ class Devise::SessionsController < ApplicationController
# POST /resource/sign_in
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
# In the running app, the previous line would actually cause this method to
# exit by throwing `:warden` if the authentication failed. Unfortunately,
# this doesn't happen in the Rails test environment if you have included the
# Devise::TestHelpers (see `Devise::TestHelpers::TestWarden#authenticate!`),
# which makes it difficult to unit test extensions to this controller. Since
# the resource is nil if authentication fails, just short-circuit the method
# in that case. This should not affect the running app.
return if resource.nil?
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)