Restore ActionDispatch::Http::UploadedFile compatibility with IO.copy_stream #35382
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Shrine relies on
ActionDispatch::Http::UploadedFile
working withIO.copy_stream
. In #28676,#to_path
method was added toActionDispatch::Http::UploadedFile
, which broke usage withIO.copy_stream
(shrinerb/shrine#353):Normally
IO.copy_stream
just calls#read
on the source object to read the content. However, when#to_path
is defined,IO.copy_stream
calls#to_io
in order to retrieve the rawFile
object. In this case it trips up, becauseActionDispatch::Http::UploadedFile#to_io
returned aTempfile
object, which is not anIO
subclass.We fix this by modifying
#to_io
to return an actualFile
object (which is aIO
subclass). I think this is also more correct behaviour in general.I had to test this with an actual
Tempfile
object, so then I also updated the rest of the tests to use an actualTempfile
objects (which simplified them).