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.
2f24c382600d9fd71085a74251fd5a39?d=identicon&s=25 Damian Terentyev (Guest)
on 2007-03-05 16: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?
E3640176765dae2465d33ef6eb114691?d=identicon&s=25 Bala Paranj (Guest)
on 2007-03-05 18:53
(Received via mailing list)
Do a puts and check the value of header['Content-Type']
2f24c382600d9fd71085a74251fd5a39?d=identicon&s=25 Damian Terentyev (Guest)
on 2007-03-08 14: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.
8bc543795b502900b5333aea73ad5533?d=identicon&s=25 Eden Li (edenli)
on 2007-03-08 16: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.
2f24c382600d9fd71085a74251fd5a39?d=identicon&s=25 Damian Terentyev (Guest)
on 2007-03-09 16: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.