views:

96

answers:

2

I am writing some performance tests and I want the user to be logged in:

class CompaniesTest < ActionController::PerformanceTest 
  fixtures :all 
  def setup 
    login_as(:cyrille) 
  end 
  def test_homepage 
    get '/' 
  end 
end

The problem is: how should I implement login_as?

I tried:

  private 
  def login_as(user) 
    @request    = ActionController::TestRequest.new 
    @request.session[:user] = user ? users(user).id : nil 
  end

But the session[:user] is empty when it gets checked by the application.

Obviously there must be a session object created by the PerformanceTest, but I can't see how I am supposed to access it.

A: 

I would try removing this line:

@request = ActionController::TestRequest.new

PerformanceTest is a subclass of IntegrationTest so @request should already be defined.

Olly
A: 

Thanks for your reply. I actually got an answer elsewhere:

http://groups.google.com/group/wellrailed/browse%5Fthread/thread/fa102a7ab4b530e4

Cheers

Cyrille Bonnet