Forum: Ruby on Rails How to test for a correct header?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Damian T. (Guest)
on 2007-03-05 17:49
(Received via mailing list)
Hi, all!
I'm writing a functional test and I would like to test if my controller
gives out right content type for an AJAX Request.

Firstly I do

xhr :post, :my_controller, my_params, {'Accept' => 'text/javascript'}

to simulate the request, but I don't know how to write an assertion. I
hoped it would be

assert_equal headers['Content-Type'], 'text/javascript'

but that turned out to give an error.

Could you please give me a hint for correct syntax?
Bala P. (Guest)
on 2007-03-05 19:53
(Received via mailing list)
Do a puts and check the value of header['Content-Type']
Damian T. (Guest)
on 2007-03-08 15:55
(Received via mailing list)
I did it in controller and was very surprised that request.headers are
empty, though I supply them in the test:

xhr :post, :login, my_params, {'Accept' => 'text/javascript'}

But my original point was to check them from within the test. And the
test doesn't have a request or response variable, nor header or
headers. I wished to know how I can access that information from the
test.
Eden L. (Guest)
on 2007-03-08 17:42
(Received via mailing list)
If you use the default test that gets generated with your controller,
you should be able to access the response headers via the
@response.headers hash.
Damian T. (Guest)
on 2007-03-09 17:18
(Received via mailing list)
On Mar 8, 2007, at 18:40, eden li wrote:

> If you use the default test that gets generated with your controller,
> you should be able to access the response headers via the
> @response.headers hash.

Many thanks!

Assigning values to @request hash solved my another problem!

I am so happy!

Yours sincerely,
Damian/Three-eyed Fish
This topic is locked and can not be replied to.