0

My functional tests are failing because current_user is not recognizing my authenticated users.

Here is part of application_controller (there are other require_* filters too):

def current_user
  return @current_user if defined?(@current_user)
  @current_user = current_user_session && current_user_session.user
end

def require_user
  unless current_user
    store_location_with_url
    redirect_to login_url
    return false
  end
end

I am creating logged in users using Authlogic, Factory Girl, and Test::Unit:

# test_helper.rb
require 'authlogic/test_case'

# functional test
class LinksControllerTest < ActionController::TestCase
  setup :activate_authlogic
  setup do
    @link = FactoryGirl.create :link
    @employer = @link.employer
    @user = @employer.user
    UserSession.create(@user)
  end
end

But, my functional tests ALL fail because despite my creating a logged in user, each controller method fails at require_user.

How can I fix this?

sscirrus
  • 55,407
  • 41
  • 135
  • 228
  • [This question](http://stackoverflow.com/questions/2634298/problem-with-authlogic-and-unit-functional-tests-in-rails) may be of some help. – max Nov 02 '13 at 09:09
  • @papirtiger Thanks! I looked at that question already, but from what I can see the answers aren't presenting anything different from what I've already done. – sscirrus Nov 02 '13 at 09:10

0 Answers0