Thursday, November 20, 2008

Testing file uploads in Rails.

zomg, there are like no Google hits for this. This or 'test file upload in rails.' Whatever. Same deal.

I was doing it "the hard way" earlier, until I stumbled across this while looking for something else entirely...

# fixture_file_upload uses /fixtures as its base directory
post :foo_bar, :file => fixture_file_upload('/files/test_file.txt', 'text/plain', :binary)
Automatically does the multipart stuff, so you can add in extra normal parameters (:user_id => 1, etc).

No comments: