Re: Testing download in controller

Jeffrey L. Taylor
2011-04-30T16:59:39Z

Quoting David Kahn
<dk-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org>:
> 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.
>

Oops, I have the directions backwards.  I need to simulate/test upload of a
file.  The user is uploading their RSS feeds in an OPML file (typically
exported from Google Reader).  I expected this to be an obscure question, so I
didn''t Google it.  It isn''t.  There are several answers on
Stack Overflow and
elsewhere.  I sucessfully used the answer at the URL below.  Note, this has
changed in Rails 3.  There is a link to the Rails 3 answer in the footnote to
the first answer.

Jeffrey