-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
validate_attachment_type_content_matcher: Short-curcuiting && means side effects do not happen; confusion around where errors are added #1476
Comments
Repro in progress using paperclip_demo app. The second issue - confusion around where errors are added - causes |
using paperclip-4.1.1 |
failing test for short-circuiting && problem: https://github.com/cofiem/paperclip_demo/compare/thoughtbot:master...master |
This is interesting. After I apply the suggested fix, I still get a few errors in the demo app. Is that intended to highlight things that should be failing? |
Yes, there are still some errors. I don't think they're all part of what I'm talking about here. I'll check, then comment more here. |
Ok, that was a little confusing, sorry about that. I've added comments to the tests I added, and commented out irrelevant tests. Have a look at this commit: https://github.com/cofiem/paperclip_demo/commit/767bff943c544835000df7b436b3f2c7c85e584c Unfortunately I haven't been able to reproduce the second problem I mentioned in the issue description: 'Confusion around where errors are added'. I have found something else, however: two of the tests have errors I do not expect (see comments above tests in commit). I believe the problem is on line 43 or 45 of All in, all, it seems to me there are quite a few assumptions of non-empty arrays and assumptions of ordering of method calls. |
Hi @cofiem ! Is this still an issue for you in Paperclip; I know this issue is from approximately 1 year ago. If it is still an issue, can you please provide the code that's causing you the error? Thanks! |
@maclover7 I haven't looked at this in quite some time. The code this issue refers to has most likely changed in the year since. Please refer to the tests in the fork I linked to in earlier comments. |
I don't think the error message is a problem, as they are always present at that location or the suggested addition one, too. |
Similar, but not exactly the same, as #792 #1158 #1334 #161
Short-curcuiting && means side-effects of methods are not in effect
The return in
matches?
cannot be done as it is on line 38. This is because&&
short-curcuits when a return value is false.A failure will call
failure_message
. Due tofailure_message
callingaccepted_types_and_failures
andrejected_types_and_failures
,@missing_rejected_types
and@missing_allowed_types
must have values (any?
is called on them). These two instance variables are set in theallowed_types_allowed?
andrejected_types_rejected?
methods.The short-curcuit will mean that one or both of
allowed_types_allowed?
andrejected_types_rejected?
are not called. The end result of all of this is the error discussed in #1334:undefined method
any?' for nil:NilClass`One possible fix is to replace line 37 and 38 with:
Confusion around where errors are added
Due to #1253, there is confusion about where to look for errors on
@subject
in thetype_allowed?
method.Currently line 85 only checks
@subject.errors[:"#{@attachment_name}_content_type"]
. It should also check@subject.errors[:"#{@attachment_name}"]
.A possible fix is to replace line 85 with:
The text was updated successfully, but these errors were encountered: