Forum: Ruby on Rails testing question

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.
Franz S. (Guest)
on 2008-10-16 15:23
(Received via mailing list)
Hello folks,

I need to write a method that will return a PDF to the user.

Does anyone know of any documentation on how to test
such functionality?

Thanks in advance.

Regards,
Franz
Daniel B. (Guest)
on 2008-10-16 17:21
Franz S. wrote:
> Hello folks,
>
> I need to write a method that will return a PDF to the user.
>
> Does anyone know of any documentation on how to test
> such functionality?
>

I haven't needed to do such a thing so I'm of limited help.  I suppose
if you're doing downloads using rails then you've probably looked at the
streaming api:
  ActionController::Streaming
The send_data/send_file methods allow you to set the content-type and
other headers etc etc.

So in your functional tests for your download controller, you could
probably do something like

  def test_1a
    ...
    get :download , params
    assert_equal 'text/html',@response.headers[:type]
    ...

(Obviously replace 'text/html').
You can also access other headers eg content-length and the body
(@response.body).
I don't know if it's good form to be using @response.
Integration test api is a little different so might be worth checking
too.

Daniel
This topic is locked and can not be replied to.