2009/1/20 Brian Hogan <[email protected]> > > Colin: > > Double-check your understanding of functional tests. Each test is run > in a vaccuum. Sessions do not persist between tests which is why the > get,put,post,delete methods accept session info as a third parameter. > > As long as you change the session before you do the call to get, post, > put, delete, it works just fine. Don't believe me? Try it out. >
Brian: I was refering to multiple gets (or whatever) within one test, not across tests. Changing the user_id in the session between gets within one test will not change the user. I also suggested this is not something that one should do, generally I would expect this to be multiple tests. Colin > > > > On Tue, Jan 20, 2009 at 4:29 PM, Colin Law <[email protected]> wrote: > > Whichever method you use note that you cannot change the logged in user > > within one test by changing the id in the session, though probably you > > should not be doing this anyway. Changing the id in the session has no > > effect as the user is already logged in. > > > > 2009/1/20 Brian Hogan <[email protected]> > >> > >> You could skip passing it and do it directly. > >> > >> In your functional test, declare a setup method that gets run before > >> everything else. Load fixutres and use Quentin (first fixture) and add > >> his ID to the session directly. > >> > >> fixtures :all > >> def setup > >> @request.session[:current_user] = users(:quentin).id > >> end > >> > >> > >> This saves lots of time testing the controllers because you're not > >> passing sessions. For cases where you want to test that redirection to > >> the login page works, just set it to nil. > >> > >> def test_should_go_to_the_login_page_when_not_logged_in > >> @request.session[:current_user] = nil > >> get :index > >> assert_redirected_to new_session_path > >> end > >> > >> > >> Look at Shoulda, a nice library to help you with your testing. It lets > >> you define "contexts" for your tests so you can set the session up > >> before just a subset of your tests rather than all or nothing. > >> > >> > >> On Tue, Jan 20, 2009 at 4:00 PM, Colin Law <[email protected]> > wrote: > >> > If necessary debug into the logged_in? method in > authenticated_system.rb > >> > to > >> > check what is happening. That should call current_user then > >> > login_from_session should pick up the user_id and log you in. > >> > > >> > 2009/1/20 John Small <[email protected]> > >> >> > >> >> Colin Law wrote: > >> >> > I must admit I am having difficulty finding documentaion on this. I > >> >> > got > >> >> > it > >> >> > from section 13.3 (Functional Testing) of Agile Development With > >> >> > Rails > >> >> > (Pragmatic Bookshelf) and it certainly works. > >> >> > When you say it doesn't work was there an error or did the login > >> >> > simulation > >> >> > not work? > >> >> > > >> >> > 2009/1/20 John Small <[email protected]> > >> >> > >> >> OK, I see the reference. That's probably the only place it's ever > >> >> written down, you either know it or you don't. It doesn't seem to be > in > >> >> the online docs. > >> >> > >> >> I'll fiddle with it to see if I can get it to work. You say you can > so > >> >> it must be possible. I'm not sure where the error is, I just see that > I > >> >> don't have a variable @current_user available in my views unless I go > >> >> via login in integration. > >> >> > >> >> I'll be a while. I'm out till Thursday. Thanks all the same. > >> >> > >> >> John Small > >> >> -- > >> >> Posted via http://www.ruby-forum.com/. > >> >> > >> >> > >> > > >> > > >> > > > >> > > >> > >> > > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

