How do I access the session object in a Rails performance test?
I am writing some performance tests and I want the user to be logged in:
class CompaniesTest < Action开发者_运维百科Controller::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.
I would try removing this line:
@request = ActionController::TestRequest.new
PerformanceTest
is a subclass of IntegrationTest
so @request
should already be defined.
精彩评论