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

Extend AM validate_length_of matcher to support array attributes #1560

Conversation

jarenas9539
Copy link
Contributor

@jarenas9539 jarenas9539 commented May 31, 2023

First step to close: #1559

Solution

Were added two mechanisms to treat validate_length_of_matcher related attribute as array. One was through array_column? helper(also used on validate_absence_of_matcher) based on column type if array? helper is defined on model's columns_hash and another one with an explicit chain method as_array that will force to validate column with arrays values.
Why this way? First one will cover pure array: true columns for postgresql, second one could be dynamically used to check, for example, json columns storing arrays and being treated like that. This second approach will leave more freedom when using the validator.

Main validate_length_of_matcher specs were duplicated for the two variants. After all review's iteration for this PR concluded and if it's finally approved and merged this approach, I'll continue extending the array support to other validators(as inclusion/exclusion).

Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

These changes make sense to me! Nice work. Just had a few comments.

@jarenas9539 jarenas9539 requested a review from mcmire June 9, 2023 20:25
@jarenas9539
Copy link
Contributor Author

@mcmire changes applied. This one is ready for another iteration. 👍

Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looking better! I just had two more suggestions related to documentation.

@jarenas9539 jarenas9539 requested a review from mcmire June 9, 2023 23:24
Copy link
Collaborator

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks so much for the PR!

@mcmire mcmire changed the title Extend ActiveModel validate_length_of_matcher to support array attributes Extend AM validate_length_of matcher to support array attributes Jun 12, 2023
@mcmire mcmire merged commit 3fee9ab into thoughtbot:main Jun 12, 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.

Extend ActiveModel matchers to support arrays attributes
2 participants