Hi David - thanks for replying. The literal doesn't work either, because of all the params at the end, and i don't have named routes in this old, non-restful app. I see your point about the hash...is there any way to get the redirected-to url from 'response' and test against that? Then i could split it at "?" to ignore the params. (I'd rather not include the specific params in this test since i really just want to know about where it's redirected to).<br>
<br>So, ideally i could do something like this - <br><br>response.url.split("?").first.should eql("<a href="http://test.host/admin/users/batch_saved">http://test.host/admin/users/batch_saved</a>")<br><br>
I've been looking for documentation for methods for the response object, to get the url, but i can't find any in the api docs (i'm probably just looking in the wrong place). I can see the url data in the object but it's private.<br>
<br>thanks<br>max<br><br><div><span class="gmail_quote">On 13/02/2008, <b class="gmail_sendername">David Chelimsky</b> <<a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Feb 13, 2008 12:26 PM, Max Williams <<a href="mailto:toastkid.williams@gmail.com">toastkid.williams@gmail.com</a>> wrote:<br> ><br> > I'm testing a controller action that redirects to a different action/view,<br>
> sending through some params. In my test, i'm only specifying the controller<br> > and action that it should redirect to, but the additional params are making<br> > it fail! Here's my test:<br> ><br>
> it "should redirect to batch_saved after completing batch_save" do<br> > post 'batch_save', @params<br> > response.should redirect_to(:controller => 'admin/users', :action =><br>
> 'batch_saved')<br> > end<br> ><br> > and here's the failure report:<br> ><br> > 'Admin::UserController When logged in as an admin level user should redirect<br> > to batch_saved after batch_save' FAILED<br>
> expected redirect to {:controller=>"admin/users", :action=>"batch_saved"},<br> > got redirect to<br> > "<a href="http://test.host/admin/users/batch_saved?music_service_id=1&new_users%5B%5D%5Bemail%5D=mark%40zadeup.com&new_users%5B%5D%5Bfirstname%5D=Mark&new_users%5B%5D%5Bmusic_service_id%5D=1&new_users%5B%5D%5Bschool%5D=&new_users%5B%5D%5Bsurname%5D=Madeup">http://test.host/admin/users/batch_saved?music_service_id=1&new_users%5B%5D%5Bemail%5D=mark%40zadeup.com&new_users%5B%5D%5Bfirstname%5D=Mark&new_users%5B%5D%5Bmusic_service_id%5D=1&new_users%5B%5D%5Bschool%5D=&new_users%5B%5D%5Bsurname%5D=Madeup</a>"<br>
><br> > Now, i would expect that since i'm just specifying a controller and action,<br> > and we redirect to them, that the test would pass. But the params are<br> > breaking it (I know this because i changed the controller action to not send<br>
> params through at all and the test passed). How do i do the test so that it<br> > doesn't care about the params?<br> <br> <br>When you use a hash it checks the whole hash, so this is the expected behaviour.<br>
<br> You can either used a named route (if you've got one available) or a<br> String literal:<br> <br> response.should redirect_to(admin_users_batch_saved)<br> response.should redirect_to('/admin/users/batch_saved')<br>
<br> Based on Jay Field's latest advice<br> (<a href="http://blog.jayfields.com/2008/02/testing-expect-literals.html">http://blog.jayfields.com/2008/02/testing-expect-literals.html</a>) you<br> may want to consider the literal.<br>
<br> HTH,<br> David<br> <br> <br> ><br> ><br> > --<br> <br>> View this message in context: <a href="http://www.nabble.com/params-are-making-my-%22should-redirect_to%22-test-fail---why---tp15460582p15460582.html">http://www.nabble.com/params-are-making-my-%22should-redirect_to%22-test-fail---why---tp15460582p15460582.html</a><br>
> Sent from the rspec-users mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br> ><br> > _______________________________________________<br> > rspec-users mailing list<br> > <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>
> <a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br> ><br> _______________________________________________<br> rspec-users mailing list<br> <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br> </blockquote></div><br>