Re: Testing download in controller

David Kahn
2011-04-30T14:44:13Z

On Sat, Apr 30, 2011 at 8:14 AM, Jeffrey L. Taylor
<ror-f/t7CGFWhwGcvWdFBKKxig@public.gmane.org>wrote:

> How can download of files be tested?  The processing of the file is being
> tested okay, but I don''t know how to simulate the controller call.
>

What are you using to test? This is a bit off your topic as it sounds like
you are writing controller specific tests. I used to do that, but in the
last year I have started convering my ui and views heavily with testing and
since doing this I find that I can achieve reasonably also testing the
controller actions. I am sure some will argue against this but in the
interest in time and quality I think I get more bang for my time covering
how the user will use my ui. That said, I use rspec with capybara (steak)
and using capybara, if there is a download link, I just click the link and
then look at the page.body which gives me the content of the downloaded
file.

I know you should be able to do so in a controller spec/test also, should be
something like calling a get. I am not sure what your method is but if it
has multiple formats then you would have to specify the format in a
parameter I think, or do something like "get
''/controller/action/file.pdf"
or something like that. I would google for ''rails test file
download'', it
looks like you will have some results you can at least piece together.


>
> TIA,
>  Jeffrey
>
> --
> 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.
>
>