How do you access the session in a Rails performance test?

114 views
Skip to first unread message

Cyrille

unread,
Oct 19, 2009, 5:51:34 PM10/19/09
to WellRailed
Hi guys,

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.

Anybody knows?

Cheers

Cyrille

Andy Newport

unread,
Oct 19, 2009, 9:11:04 PM10/19/09
to wellr...@googlegroups.com
I believe PerformanceTest extends IntegrationTest so you should be able to user the open_session(&block) type hook. See the second code example here => http://apidock.com/rails/v2.3.4/ActionController/IntegrationTest

Cyrille

unread,
Oct 25, 2009, 8:00:57 PM10/25/09
to WellRailed
Hi Andy,

thanks for pointing that out. It works a charm.

Cheers

Cyrille
Reply all
Reply to author
Forward
0 new messages