Rails Functional Test Case and Uploading Files to ActionDispatch::Http::UploadFile

I use the s3 gem instead of the aws/s3 gem. The main reasons for this are no support for european buckets and development of aws/s3 seems to be stopped.

If you want to test file upload than using the fixtures_file_upload method is correct, it maps directly to Rack::Test::UploadedFile.new (you can use this if the test file isn't in the fixtures folder).

But I've also noticed that the behavior of the Rack::Test::Uploaded file objects isn't exactly the same as the ActionDispatch::Http::UploadedFile object (that's the class of uploaded files). The basic methods (original_filename, read, size, ...) all work but there are some differences when working with the file method. So limit your controller to these methods and all will be fine.

An other possible solution is by creating an ActionDispatch::Http::Uploaded file object and using that so:

upload = ActionDispatch::Http::UploadedFile.new({
  :filename => 'avatar.jpeg',
  :type => 'image/jpeg',
  :tempfile => File.new("#{Rails.root}/test/fixtures/avatar.jpeg")
})

post :create, :person => { :avatar => upload }