Forum: Ruby on Rails How I provide a session object to Functional Tests?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
dan.bikle (Guest)
on 2005-11-19 09:31
(Received via mailing list)
People,

I'm looking at p. 152 in the Rails book where he talks about testing
controllers [ functional tests ].

First he shows a method, test_login_with_valid_user, which tests
that it's possible to login with a valid user/password combo.

Then, he talks about extracting the code he just wrote and placing it
into a login method inside of test_helper.rb

Once the method is there, he can re-use the login method in later
functional tests
of the LoginController class.

So, the discussion is easy to follow and I understand it.

My question:
Suppose I want to test other controllers besides the LoginController.
How do I make use of login in test_helper.rb to place the user object
in my session object?
Or in other words,
How do I make test_helper.login general enough to be used outside of
LoginController functional tests?

Thanks,

-Dan
michael.gorsuch (Guest)
on 2005-11-19 15:06
(Received via mailing list)
You can manipulate the session object as follows:

user = User.find(1)
@request.session[:user_id] = user.id

I just did the same last night when working out my own tests.

I hope this helps,

Michael
This topic is locked and can not be replied to.