Fix: Fix size matcher for has_many_attached
attachments
#210
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
active_storage_validations/lib/active_storage_validations/matchers/size_validator_matcher.rb
Line 54 in dc76544
this works for
has_one_attached
attachments since wheneverattach
method is called, previous attachment is being replaced with a new one.active_storage_validations/lib/active_storage_validations/matchers/size_validator_matcher.rb
Line 92 in dc76544
Unfortunately, this is not the case for
has_many_attached
attachments since theattach
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.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.