[Rails] functional test problems
Johan Sörensen
johans at gmail.com
Thu Nov 11 11:12:37 GMT 2004
Hi list.
Just starting to wrap my heads around the whole unit testing deal.
I've run into a bit of a (small) problem when testing a
LoginController.
my main login method that I'm looking to test looks like this:
def checkauth
if currentuser = User.checkauth(@params["login"]["username"],
@params["login"]["password"])
@session["user_id"] = currentuser.id
@session["username"] = currentuser.username
# some more stuff, like redirects on sucess etc
end
and my simple testcase looks like this:
def test_session_vars
process 'checkauth', "username" => 'foo', "password" => 'bar'
assert_session_has 'user_id'
assert_session_has 'username'
assert_session_has_no 'admin'
end
All results in this semicryptic error:
1) Error:
test_session_vars(LoginControllerTest):
NoMethodError: undefined method `[]' for nil:NilClass
./test/functional/login_controller_test.rb:5:in `rescue_action'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-0.9.0/lib/action_controller/rescue.rb:70:in
`perform_action'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-0.9.0/lib/action_controller/base.rb:254:in
`process'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-0.9.0/lib/action_controller/test_process.rb:192:in
`process'
./test/functional/login_controller_test.rb:16:in `test_session_vars'
By accident I've come to the conclusion that the reason for the error
most likely is because of this in my controller method:
User.checkauth(@params["login"]["username"],
@params["login"]["password"]. If I change the @params values to omit
the ["login"] part it works.
So. My question basicly is, how can I add the "login" part to process()?
I've tried what I thought would be the most obvious:
process "checkauth", ["login"]["username"]=>'foo', ..and so on, but
that gives me a TypeError ("cannot convert String into Integer")
Thank you in advance,
johan
PS. Thanks Steve Kellock for writing that testing tutorial PDF, it
explains the concepts really well..
--
Johan Sørensen
Professional Futurist
www.johansorensen.com
More information about the Rails
mailing list