Phoenix Rising
2011-Apr-06 08:46 UTC
Getting a 200 OK instead of a redirect with Rails 3 in test
Hey guys,
I have a weird situation where I have a route that specifically
redirects (in the routes file itself, not a corresponding controller
action), but when using RSpec to test it, for some reason it''s giving
me a 200 OK with an empty response body.
So, for example, take this route:
get "/search/users/:name(/:location)" => "search#users"
get "/search/users" => redirect(root_path)
The idea being that if you try to access /search/users, you''ll just be
redirected to the index, because you didn''t bother specifying criteria
for a search (such as a name or location parameter).
My corresponding spec looks like this:
context "a GET to /users (with no params)" do
it "should redirect to index" do
get :users
response.should redirect_to(root_path)
end
end
The response.should line fails because the response object isn''t a
redirect, it''s a 200 OK with a blank response body. However, if I try
it in my browser (under development mode) it seems to redirect exactly
as expected. This just presents a problem because I''m not sure how to
properly write a test for it.
Does anyone have any pointers on what I''m doing wrong here? Thanks
for any help you can provide :)
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Apr-06 21:22 UTC
Re: Getting a 200 OK instead of a redirect with Rails 3 in test
On Apr 6, 9:46 am, Phoenix Rising <polarisris...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The response.should line fails because the response object isn''t a > redirect, it''s a 200 OK with a blank response body. However, if I try > it in my browser (under development mode) it seems to redirect exactly > as expected. This just presents a problem because I''m not sure how to > properly write a test for it. >functional tests don''t go through routing. You may have to use something which tests the full stack like a cucumber story. Fred> Does anyone have any pointers on what I''m doing wrong here? Thanks > for any help you can provide :)-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.