I''m getting a weird error in a call to assert_redirected_to in one of
my functional tests. Here is the test:
def test_signin
admin = users(:adminuser)
post :signin, {:login => admin.email, :realpass => @password}
assert_redirected_to :action => ''list'' # failure
happens on this line
assert_equal admin.id, session[:user].id
end
The error is:
2) Error:
test_signin(UserControllerTest):
RuntimeError: The number of parameters does not match the number of
substitutions.
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_controller/assertions.rb:92:in
`assert_redirected_to''
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_controller/assertions.rb:313:in
`clean_backtrace''
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_controller/assertions.rb:74:in
`assert_redirected_to''
./test/functional/user_controller_test.rb:31:in `test_signin''
My signin method redirects the user to ''/'' if they request the
signin
page directly as is happening in this functional test. This route
gets translated to :controller => ''user'', :action =>
''list''. So the
redirection should be working fine, except that assert_redirected_to
doesn''t seem to know that ''/'' translates into that
controller and
action, so it is getting this error.
If I change my authentication method so that it redirects explicitly
to :controller => ''user'', action =>
''list'' then this error goes away.
However, this isn''t as flexible of a solution for me, because I would
like to be able to change where ''/'' points to in one place (my
routes.rb file) and have the entire app adjust accordingly, whereas if
I have the default location explicitly coded in my authentication
method then I have to update it there too.
An ideal solution would probably be something like the opposite of
url_for, which would take a url and return a controller/action/id/etc
hash.
Thanks in advance for your help.
Carl