jimchoi (3) [Avatar] Offline
#1
Listing 5.43 introduces the following line to the LocationsControllerTest class, which seems magical to me:

login_as :ludwig

Is "login_as" a function? Where does it come from?

Thanks!
peterarmstrong (94) [Avatar] Offline
#2
Re: Listing 5.43: where does login_as come from?
Yeah, it's a function in AuthenticatedTestHelper, which is mixed in.

module AuthenticatedTestHelper
# Sets the current user in the session from the user fixtures.
def login_as(user)
@request.session[:user] = user ? users(user).id : nil
end
...

I probably should have mentioned it. (My decision was to almost completely avoid a discussion of testing, rather than do a bad, incomplete job of it. Testing is a book length topic on its own. However, a bit of an explanation may have helped...)

At this point, it's too late to fix this though...