Nathan Beyer
2010-Apr-22 19:18 UTC
How does one set an HTTP header in @request for a functional test
I have a very simple functional test for a controller, but I need to set a header field in the request before the invocation of the action, but the headers seem to be getting reset, even though I''m not doing multiple requests. Is this not how functional tests are to be used? test "test the show requires system header" do @request.headers["System-Name"] = "Test System" get :show assert_response :success ... end The controller doesn''t return a success unless the header is set, so it fails immediately. Is there another idiom that''s more appropriate? -- 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.
steve ross
2010-Apr-22 19:40 UTC
Re: How does one set an HTTP header in @request for a functional test
On Apr 22, 2010, at 12:18 PM, Nathan Beyer wrote:> > I have a very simple functional test for a controller, but I need to > set a header field in the request before the invocation of the action, > but the headers seem to be getting reset, even though I''m not doing > multiple requests. Is this not how functional tests are to be used? > > test "test the show requires system header" do > @request.headers["System-Name"] = "Test System" > get :show > assert_response :success > ... > end > > The controller doesn''t return a success unless the header is set, so > it fails immediately. > > Is there another idiom that''s more appropriate?I use something along the lines of: request.env[''HTTP_ACCEPT''] = ''application/json, text/javascript, */*'' request.env[''HTTP_X_REQUESTED_WITH''] = ''XMLHttpRequest'' to set up headers for an xhr. You should be able to do something similar for custom headers. Hope this helps. -- 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.