-
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
Add the ability to create Test::UploadedFile instances without the file system #149
Conversation
Thanks for the contribution. I really like the idea, but I am not to sure about all details of the implementation. Especially the conditional switch on respond_to to then handle IO object and paths differently. |
@scepticulous I like the idea too, though I have not checked the actual source code yet. |
@amilligan This has now conflicts with the current |
Okay, I fixed the conflicts; nothing too concerning. Regarding an earlier concern: I don't like using I can think of any number of ways to work around this, but |
@amilligan this now has conflicts again. 😄 If you rebase one more time, I promise we'll try to give it a look. |
The initializer now accepts an IO object, which allows callers to instantiate fake upload objects with in-memory content.
Resolved again; ready for a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question that I think should be resolved before merge, but in general - thanks! A valuable contribution. @scepticulous and @junaruga, feel free to chime in as well.
def respond_to?(method_name, include_private = false) #:nodoc: | ||
@tempfile.respond_to?(method_name, include_private) || super | ||
def respond_to_missing?(method_name, include_private = false) #:nodoc: | ||
tempfile.respond_to?(method_name, include_private) || super |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://ruby-doc.org/core-2.4.1/Object.html#method-i-respond_to_missing-3F says:
DO NOT USE THIS DIRECTLY.
Is there a way to implement this in another way?
Yeah, sure. |
@perlun I'm slightly confused. You're asking about the choice to implement As of ruby 1.9 implementing the former is the invariably preferred mechanism. The 'DO NOT USE THIS DIRECTLY' directive refers to calling the method, which I don't believe is done anywhere in the project. |
I stand corrected. 🙈 Sorry for that @amilligan! This blog post explains some more of the details. I am fine with this now. Will approve and merge. Thanks for the effort, and sorry about the delay! |
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 |
Hi, I have the same problem with 0.7.1: rspec/rspec-rails#1915 |
@tagliala @007lva Sorry for this; this is an unintended regression because of this change. For now, downgrade your project to 0.7.0 to work around the issue. If either one of you could provide a PR with a failing test case to the I will lock this conversation now, since it's too hard to find discussions going on in "merged pull requests"; we need it in a new issue or PR for it to be visible to the audience at large. |
Uploaded files behave as IO streams, so it should be reasonable to instantiate a fake one from an IO stream. These changes don't change the existing interface to the
#initialize
method, but add the ability to do something like this:A lot of tests for content uploads don't need a lot of complex content; this should allow for test suites without a bunch of tiny test files cluttering the project or spec directories.