| Class | ActionController::TestUploadedFile |
| In: |
vendor/rails/actionpack/lib/action_controller/test_process.rb
|
| Parent: | Object |
Essentially generates a modified Tempfile object similar to the object you‘d get from the standard library CGI module in a multipart request. This means you can use an ActionController::TestUploadedFile object in the params of a test request in order to simulate a file upload.
Usage example, within a functional test:
post :change_avatar, :avatar => ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/spongebob.png', 'image/png')
| path | -> | local_path |
| content_type | [R] | The content type of the "uploaded" file |
| original_filename | [R] | The filename, not including the path, of the "uploaded" file |
# File vendor/rails/actionpack/lib/action_controller/test_process.rb, line 311
311: def initialize(path, content_type = 'text/plain')
312: raise "file does not exist" unless File.exist?(path)
313: @content_type = content_type
314: @original_filename = path.sub(/^.*#{File::SEPARATOR}([^#{File::SEPARATOR}]+)$/) { $1 }
315: @tempfile = Tempfile.new(@original_filename)
316: FileUtils.copy_file(path, @tempfile.path)
317: end