In a few of my controllers I have a before_filter that checks if a user is logged in? for CRUD actions.
application.rb
def logged_in?
  unless current_user
    redirect_to root_path
  end
end
private
def current_user_session
  return @current_user_session if defined?(@current_user_session)
  @current_user_session = UserSession.find
end
def current_user
  return @current_user if defined?(@current_user)
  @current_user = current_user_session && current_user_session.record
end
But now my functional tests fail because its redirecting to root. So I need a way to simulate that a session has been created but nothing I've tried has worked. Heres what I have right now and the tests pretty much ignore it:
test_helper.rb
class ActionController::TestCase
  setup :activate_authlogic
end
posts_controller_test.rb
class PostsControllerTest < ActionController::TestCase
  setup do
    UserSession.create(:username => "dmix", :password => "12345")
  end
  test "should get new" do  
    get :new
    assert_response :success
  end
Am I missing something?
You should pass ActiveRecord object in UserSession.create
Something like:
u = users(:dmix)
UserSession.create(u)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With