I'm trying to run some functional tests for actions that are behind
authentication (via act as authenticated plugin), but am having
problems getting "current_user" set for the controller.
I found that the default "authenticated_test_helper.rb" file was
throwing an error about the "users" method being undefined with the
following function:
def login_as(user)
@request.session[:user] = user ? users(user).id : nil
end
So I changed it to this:
def login_as(user)
@request.session[:user] = user ? User.find_by_login(user) : nil
end
This seemed to fix the problem. Is this an OK modification to make?
Why didn't the code that it shipped with work?
I found that the default "authenticated_test_helper.rb" file was
throwing an error about the "users" method being undefined with the
following function:
And you are using the out-of-the-box fixtures system, with fixtures :users above every call to login_as?
def login_as(user)
@request.session[:user] = user ? users(user).id : nil
end
So I changed it to this:
def login_as(user)
@request.session[:user] = user ? User.find_by_login(user) : nil
end
This seemed to fix the problem. Is this an OK modification to make?
sessions should only contain numbers (for various definitions of "should"), so you are missing an .id
Why didn't the code that it shipped with work?
Works for me. How sure are you that this assertion would pass before your login_as?
assert_not_nil users(:jeremy)
Then, I suspect something reconstitutes current_user at page hit time, via User.find_by_id(session[:user])
Storing entire objects in your session table is bad JuJu.