NoamB/sorcery — pull request #247 by jamesroscoe (2012-03-29 21:45:25+00:00)
Title: Login fails after call to current_user

current_user returns false after login if it was called prior to login
during a given request (e.g. in a before_filter). Setting @current_user
to nil at start of login fixes this problem.

Sample:

application_controller:

class ApplicationController < ActionController::Base
before_filter :do_something_with_current_user

def do_something_with_current_user
logged_in? # calls current_user
end
end

session_controller:

class SessionController < ApplicationController
def create
raise Exception.new('login failed') unless login(params[:email], params[:password], params[:remember_me])
end
end

session_controller_test:

class SessionControllerTest < ActionController::TestCase
include Sorcery::TestCase::Rails

test "login" do
user = User.create!(email: 'user@sample.com', password: 'password')
post :create, email: user.email, password: user.password, remember_me: false
assert_response :success
end
end