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
2005-Nov-19 13:06 UTC
Re: How I provide a session object to Functional Tests?
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 On 11/19/05, Dan Bikle <dan.bikle-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >