On 18 Jul 2013, at 12:23, Ian Moss <[email protected]> wrote:

> Given that the ActiveAdmin 'controller' method 'export' exports a csv
> and it has been called in a http request,
> And I'm using TestUnit
> As A Developer, I want to assert that the file 'export.txt' is created
> and sent as a http response

You'll probably use `send_data` inside your controller action. It'll set a 
Content-Type header, so check for that.

No need to couple yourself to the implementation, check files on disk, etc. Try 
and check what the action is supposed to do, not that it's done half the job.

    test 'should export a CSV file' do
      # appropriate setup to create a collection_of_stuff
      get :export, appropriate: params, go: here
      assert 'text/csv', response.header['Content-Type']
      rows = CSV.parse(response.body)
      assert_equal collection_of_stuff.size, rows.size
      assert_equal 'Contents of column 1', rows.first[0]
    end

Don't get too rigid with what your asserts check for; I'd just check that it 
looked like the right kind of data was in it (i.e. number of rows, and probably 
just that the right stuff was in the first column; detailed testing of what's 
in the CSV is something I'd only unit test at the model level, and only then if 
it was complicated [i.e. only if I was likely to get it wrong without testing 
it]).

-- 
You received this message because you are subscribed to the Google Groups 
"NWRUG" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nwrug-members.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to