Here is my unit test code.
post :login, :user=>{ :login => "bob", :password => "test"}
assert_response :redirect
assert_session_has :user
assert_redirected_to :action => 'welcome'
Here is the failure I’m getting when I run my tests.
- Failure:
test_login_required(UserControllerTest)
[test/functional/user_controller_test.rb:122]:
response is not a redirection to all of the options supplied
(redirection is <“http://test.host/user/welcome”>), difference:
<{:controller=>“user”}>
assert_redirected_to :action => ‘welcome’ should mean :controller is set
to the current controller (i.e. user). If I try asserting the following
it doesn’t work either:
assert_redirected_to :controller => ‘user’, :action => ‘welcome’
WTF! Please help.
Charlie
Charlie wrote:
Here is my unit test code.
post :login, :user=>{ :login => "bob", :password => "test"}
assert_response :redirect
assert_session_has :user
assert_redirected_to :action => 'welcome'
Here is the failure I’m getting when I run my tests.
- Failure:
test_login_required(UserControllerTest)
[test/functional/user_controller_test.rb:122]:
response is not a redirection to all of the options supplied
(redirection is <“http://test.host/user/welcome”>), difference:
<{:controller=>“user”}>
assert_redirected_to :action => ‘welcome’ should mean :controller is set
to the current controller (i.e. user). If I try asserting the following
it doesn’t work either:
assert_redirected_to :controller => ‘user’, :action => ‘welcome’
WTF! Please help.
Charlie
I remember butting heads with that about a week ago. I think I remember
it having something to do with differences between calling redirect_to
and assert_redirected_to with pre-built urls versus hash arguments
lists, etc. Perhaps trying changing your assertion to
“assert_redirected_to url_for(:action=>‘welcome’)”
I think that’s how I fixed it in the past, but its awfully brittle and
is probably a bug in the assertion code.
Eric,
Thanks that worked! I changed my code from
assert_redirected_to :action => ‘login’
to
assert_redirected_to @controller.url_for( :action => ‘login’ )
and it worked.
I found similar brittleness with follow_redirect method. The functional
test support is not very robust, breaks often, and fails to work as
advertised.
Charlie
Eric D. Nielsen wrote:
Charlie wrote:
Here is my unit test code.
post :login, :user=>{ :login => "bob", :password => "test"}
assert_response :redirect
assert_session_has :user
assert_redirected_to :action => 'welcome'
Here is the failure I’m getting when I run my tests.
- Failure:
test_login_required(UserControllerTest)
[test/functional/user_controller_test.rb:122]:
response is not a redirection to all of the options supplied
(redirection is <“http://test.host/user/welcome”>), difference:
<{:controller=>“user”}>
assert_redirected_to :action => ‘welcome’ should mean :controller is set
to the current controller (i.e. user). If I try asserting the following
it doesn’t work either:
assert_redirected_to :controller => ‘user’, :action => ‘welcome’
WTF! Please help.
Charlie
I remember butting heads with that about a week ago. I think I remember
it having something to do with differences between calling redirect_to
and assert_redirected_to with pre-built urls versus hash arguments
lists, etc. Perhaps trying changing your assertion to
“assert_redirected_to url_for(:action=>‘welcome’)”
I think that’s how I fixed it in the past, but its awfully brittle and
is probably a bug in the assertion code.
Charlie wrote:
Eric,
Thanks that worked! I changed my code from
assert_redirected_to :action => ‘login’
to
assert_redirected_to @controller.url_for( :action => ‘login’ )
and it worked.
Charlie
Eric D. Nielsen wrote:
Charlie wrote:
Here is my unit test code.
post :login, :user=>{ :login => "bob", :password => "test"}
assert_response :redirect
assert_session_has :user
assert_redirected_to :action => 'welcome'
Here is the failure I’m getting when I run my tests.
- Failure:
test_login_required(UserControllerTest)
[test/functional/user_controller_test.rb:122]:
response is not a redirection to all of the options supplied
(redirection is <“http://test.host/user/welcome”>), difference:
<{:controller=>“user”}>
assert_redirected_to :action => ‘welcome’ should mean :controller is set
to the current controller (i.e. user). If I try asserting the following
I remember butting heads with that about a week ago. I think I remember
it having something to do with differences between calling redirect_to
and assert_redirected_to with pre-built urls versus hash arguments
lists, etc. Perhaps trying changing your assertion to
“assert_redirected_to url_for(:action=>‘welcome’)”
OK I’ve filled a defect report; I’m trying to work on a patch, but its a
little bit beyond my comfort level. If anyone is up for a little bit of
“Remote Pairing” via IM or or something, please let me know.
Eric