Skip to content
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

Fix: Fix size matcher for has_many_attached attachments #210

Conversation

jozzi05
Copy link

@jozzi05 jozzi05 commented Nov 2, 2023

This PR fixes the size validator matcher for has_many_attached attachments.

Details:

Currently, the matcher checks all edge cases for size validation in chain:

responds_to_methods && not_lower_than_min? && higher_than_min? && lower_than_max? && not_higher_than_max?

this works for has_one_attached attachments since whenever attach method is called, previous attachment is being replaced with a new one.
@subject.public_send(@attribute_name).attach(io: io, filename: 'test.png', content_type: 'image/pg')

Unfortunately, this is not the case for has_many_attached attachments since the attach method adds new attachments to the list, which leads to having error validations for attachments from previous checks. To solve this issue, I added cleanup of attachments after each step.

.tap { @subject.attachment_changes["#{@attribute_name}"] = nil }

It works, but if there's a better way of fixing it, please let me know, and I will try to provide a better solution.

@jozzi05
Copy link
Author

jozzi05 commented Nov 3, 2023

@igorkasyanchuk @Mth0158 I would love to hear your feedback also in regards to this fix 🙏

@jozzi05
Copy link
Author

jozzi05 commented Nov 10, 2023

Same as mentioned in other PR (#209 (comment))

@jozzi05 jozzi05 closed this Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant