-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test::UploadedFile: unintended breakage of public API #207
Comments
Hi, This is occurring with me as well using FactoryBot (4.8.2), rspec-rails (3.7.2), ruby (2.4.2), rack-test (0.8.0)
Stacktrace:
When I roll back to rack-test 0.7.0, everything works fine. Is there a way to get this to work in rack-test 0.8.0 ? |
Getting this same error when converting a FactoryBot factory to JSON. |
Dynamic languages... Can't live with them, can't live without them. In #149, we added support for `UploadedFile` being an `StringIO `object, by means of the `if content.respond_to?(:read)` logic. _However_, that had the unintended consequence of breaking the use case when a `Pathname` is provided instead of a string as the `content` paramer, since a `Pathname` _also_ responds to the `read` message... This PR works around that, by adding some extra checking. As an added bonus, I also added some YARD comments to make it more clear what parameter types this method expects/accepts. Fixes #207.
I think I have a fix for this, thanks to you all for your input. See #210 - please try that branch in your project and see if it works: gem 'rack-test', github: 'rack-test/rack-test', branch: 'fix/uploaded-file-regression' (I haven't seen this error myself, so I am a bit "walking in the dark here" - your input is highly valued!) |
just tested your fix and it works. much appreciated for quick turnaround. |
Just tested, works for me 👍 🌮 🍺 |
Update Capybara to 2.16.1 also fix the issue to me, due to this change: |
Dynamic languages... Can't live with them, can't live without them. In #149, we added support for `UploadedFile` being an `StringIO `object, by means of the `if content.respond_to?(:read)` logic. _However_, that had the unintended consequence of breaking the use case when a `Pathname` is provided instead of a string as the `content` paramer, since a `Pathname` _also_ responds to the `read` message... This PR works around that, by adding some extra checking. As an added bonus, I also added some YARD comments to make it more clear what parameter types this method expects/accepts. Fixes #207.
* UploadedFile: Handle content being a Pathname Dynamic languages... Can't live with them, can't live without them. In #149, we added support for `UploadedFile` being an `StringIO `object, by means of the `if content.respond_to?(:read)` logic. _However_, that had the unintended consequence of breaking the use case when a `Pathname` is provided instead of a string as the `content` paramer, since a `Pathname` _also_ responds to the `read` message... This PR works around that, by adding some extra checking. As an added bonus, I also added some YARD comments to make it more clear what parameter types this method expects/accepts. Fixes #207. * Peer suggestion: Invert check to make the code safer.
Fix released in v0.8.2, published to Rubygems a minute ago. Enjoy! |
Sorry to be a pain guys but my error is reoccurring with rack-test 0.8.2. Have also opened it as a new issue: #211 |
Thanks! @aebirim are you also using capybara? |
@tagliala not using Capybara. Using FactoryBot_Rails (4.8.2), rspec-rails (3.7.2), ruby (2.4.2) |
* UploadedFile: Handle content being a Pathname Dynamic languages... Can't live with them, can't live without them. In rack#149, we added support for `UploadedFile` being an `StringIO `object, by means of the `if content.respond_to?(:read)` logic. _However_, that had the unintended consequence of breaking the use case when a `Pathname` is provided instead of a string as the `content` paramer, since a `Pathname` _also_ responds to the `read` message... This PR works around that, by adding some extra checking. As an added bonus, I also added some YARD comments to make it more clear what parameter types this method expects/accepts. Fixes rack#207. * Peer suggestion: Invert check to make the code safer.
This is a regression in #149, reported by @tagliala and @007lva. Copying from a comment there:
Hi,
This change is breaking an use case in specs with Paperclip + FactoryBot.
The suggested method documented here: https://github.com/thoughtbot/paperclip#testing
does not work anymore:
Is there any suggested way of doing this with rack-test 0.7.1? Should I report this to Paperclip?
I've tried several things but I'm unable to make it work.
TIA
The text was updated successfully, but these errors were encountered: