Testing File Uploads in Rails Without Fixtures
While working on some functional tests for a controller, I needed to be able
to test uploading a file. Fairly standard, but in this case I didn’t want to
fixture_file_upload as the related objects were being created by
Machinist from a blueprint. That’s where Rack::Test comes in.
allows you to post a Tempfile given its path and content type. Perfect! No
So all I had to do was create a Tempfile, write my CSV contents to it, and post using the instance of UploadFile. Here’s a small snippet showing an example:
1 2 3 4 5 6 7 8 9