Skip to content

Instantly share code, notes, and snippets.

@mgates
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save mgates/eee93a87a8394d93bba7 to your computer and use it in GitHub Desktop.

Select an option

Save mgates/eee93a87a8394d93bba7 to your computer and use it in GitHub Desktop.
To add tempfile method to Rack::Test::UploadedFile to make it like ActionDispatch::Http::UploadedFile

The CSV.foreach method cexpects a string of a file to open. ActionDispatch::Http::UploadedFile has a #tempfile method which is good enough to pass into File.open like CSV.foreach does. Rack::Test::UploadedFile doesn't (and probably won't: rails/rails#799, rack/rack-test#30).

I added it like this:

# in spec/support/add_tempfile_to_test_uploaded_file.rb

class Rack::Test::UploadedFile
  def tempfile
    @tempfile
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment