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?

On Apr 22, 2010, at 12:18 PM, Nathan B. wrote:


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.

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