Failing test with assert_redirected_to

I’m having a strange problem with an assert_redirected_to in my
controller test which hopefully someone can point out my failings with!
:wink:

Controller method -
def new
if request.post?
#Not important here.
else
flash[:notice] = ‘Please join a tree from this page.’
redirect_to :controller => ‘trees’, :action => ‘list’
end
end

And the failing test and result -

def test_new_using_get
get ‘new’
assert_response :redirect
assert_redirected_to :controller => ‘trees’, :action => ‘list’
end

Test::Unit::AssertionFailedError: response is not a redirection to all
of the options supplied (redirection is <{:action=>“list”,
:controller=>“trees”}>), difference: <{}>

I’m sure I’m missing something obvious but I haven’t managed to track it
down and Googling didn’t turn up anything of use. Surely an empty
difference is no difference?

Thanks in advance,

Ross

I hope u should have given validation in the models. I think that might
be the problem!! Please check that!!

Harish

Naga harish Kanegolla wrote:

I hope u should have given validation in the models. I think that might
be the problem!! Please check that!!

Harish

If a get request for ‘new’ is made to the controller it doesn’t even
create an empty model so I don’t think it can be a validation issue.

Ross

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs