开发者

How do I access the session object in a Rails performance test?

开发者 https://www.devze.com 2022-12-09 10:48 出处:网络
I am writing some performance tests and I want the user to be logged in: class CompaniesTest < Action开发者_运维百科Controller::PerformanceTest

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消