Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Current validation check in AttachmentContentTypeValidator is wrong #792

Merged
merged 1 commit into from
Mar 27, 2012

Conversation

tony-brewerio
Copy link
Contributor

Current validation check in AttachmentContentTypeValidator is simply wrong, it will add an error if any of the allowed_types fails comparison with value, so it will pass only if value is either empty or equals to each and every one of allowed_types.

Test suite on this validator uses only a single element as :allowed_types everywhere, so this error wasn't detected.
I've added a test to check this specific behavior.

))
end
end
unless value.blank? || allowed_types.any? { |type| type === value }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you convert the conditional to an if, so it will not look awkward when chaining? My head is almost exploding when trying to parse the unless ... || ... condition.

@sikachu
Copy link
Contributor

sikachu commented Mar 27, 2012

I have one comment in the code. After you're done, can you squash commit together and force push to your branch?

Thank you.

…wrong, it will add an error if any of the allowed_types fails comparison with value, so it will pass only if value is either empty or equals to each and every one of allowed_types.

Add test to check that validation passes if even one of content types match.
@tony-brewerio
Copy link
Contributor Author

Okay, I've squashed commits together and made condition more clear.
I'm not sure how to properly convert nested unless to if. Inner === condition for items cannot be replaced with != since === also handles regular expressions.

@sikachu
Copy link
Contributor

sikachu commented Mar 27, 2012

That looks better, thanks a bunch! :D

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants