aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/uploaded_file_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add implicit to path conversion to uploaded file (#28676)Aaron Kromer2018-07-221-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add implicit to path conversion to uploaded file Ruby has a few implicit conversion protocols (e.g. `to_hash`, `to_str`, `to_path`, etc.). These are considered implicit conversion protocols because in certain instances Ruby (MRI core objects) will check if an argument responds to the appropriate protocol and automatically convert it when it does; this is why you can provide a `Pathname` instance into `File.read` without having to explicitly call `to_s`. ```ruby a_file_path = 'some/path/file.ext' File.write a_file_path, 'String Path Content' File.read a_file_path a_pathname = Pathname(a_file_path) File.write core_file, 'Pathname Content' File.read a_file_path core_file = File.new(a_pathname) File.write core_file, 'File Content' File.read core_file tmp_file = Tempfile.new('example') File.write tmp_file, 'Tempfile Content' File.read tmp_file ``` So how does an uploaded file work in such cases? ```ruby tmp_file = Tempfile.new('example') File.write tmp_file, 'Uploaded Content' uploaded_file = ActionDispatch::Http::UploadedFile.new(tempfile: tmp_file) File.read uploaded_file ``` It fails with a `TypeError`: no implicit conversion of ActionDispatch::Http::UploadedFile into String In order to make an uploaded file work it must be explicitly converted to a file path using `path`. ```ruby File.read uploaded_file.path ``` This requires any code that expects path/file like objects to either special case an uploaded file, re-implement the path conversion protocol to use `path`, or forces the developer to explicitly cast uploaded files to paths. This last option can sometimes be difficult to do when such calls are deep within the inner workings of libraries. Since an uploaded file already has a path it makes sense to implement the implicit "path" conversion protocol (just like `File` and `Tempfile`). This change allows uploaded file content to be treated more closely to regular file content, without requiring any special case handling or explicit conversion for common file utilities. * Note uploaded file path delegation in CHANGELOG
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-1/+1
|
* Use respond_to test helpersDaniel Colson2018-01-251-2/+2
|
* Enable `Layout/SpaceBeforeComma` rubocop rule, and fixed moreRyuta Kamizono2017-12-121-1/+1
| | | | Follow up of #31390.
* Use frozen string literal in actionpack/Kir Shatrov2017-07-291-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Fixed string being modified in place causing frozen string errors in Ruby 2.3sepehr5002017-05-151-0/+6
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-4/+4
|
* modernizes hash syntax in actionpackXavier Noria2016-08-061-17/+17
|
* applies new string literal convention in actionpack/testXavier Noria2016-08-061-22/+22
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* always transcode the file to utf-8Aaron Patterson2014-07-161-0/+6
| | | | | | people may be passing filenames to the constructor that are not utf-8, but they will assome that calling `original_filename` returns utf-8 (because that's what it used to do).
* Change the method descriptionRafael Mendonça França2014-04-171-1/+1
|
* Provide interface for accessing underlying IO objectTim Linquist2014-04-151-0/+6
| | | | | | In some cases users may need to work with/manipulate more of the Tempfile api than provided by Upload. Allow users to get at the underlying io via the common to_io method of IO/IO-like objects
* fixes the suite for uploaded filesXavier Noria2012-09-231-6/+6
|
* Accept parameters in methods delegated to tempfileSergio Gil Pérez de la Manga2012-09-221-0/+6
|
* Delegate ActionDispatch::Http::UploadedFile#close to tempfileSergio Gil Pérez de la Manga2012-09-201-0/+6
|
* adds delegetion for eof? to AD::Http::UploadedFileJens Fahnenbruck2012-03-271-0/+6
| | | | | if you want to read the file you may need to ask if there is something to read from
* Refactor AD::UploadedFile, and raise sooner if tempfile is not presentCarlos Antonio da Silva2012-03-061-1/+1
|
* deprecate String#encoding_aware? and remove its usageSergey Nartimov2011-12-241-5/+3
|
* Use assert_equal instead of assert in uploaded file test.Lukáš Konarovský2011-06-151-1/+1
|
* all requests are utf-8. Don't use the external encoding.Damien Mathieu2011-06-141-6/+1
|
* encode the uploaded file's name in the default external encoding - Closes #869Damien Mathieu2011-06-141-0/+12
|
* delegating path and open to internal tempfileAaron Patterson2010-11-181-0/+12
|
* only forwarding enough methods to work. People should grab the delegate ↵Aaron Patterson2010-10-041-14/+8
| | | | tempfile if they really need to do hard work
* making sure respond_to? works properlyAaron Patterson2010-10-041-0/+15
|
* raising an argument error if tempfile is not providedAaron Patterson2010-10-041-3/+9
|
* delegate to the @tempfile instance variableAaron Patterson2010-10-041-0/+18
|
* adding tests for uploaded fileAaron Patterson2010-10-041-0/+25