shoulda-matchers icon indicating copy to clipboard operation
shoulda-matchers copied to clipboard

Allow validates_length_of to work on association - Fix #1007

Open prashantjois opened this issue 7 years ago • 6 comments

if the length check is on an association then create an array to assign to the association instead of a string

prashantjois avatar Sep 03 '18 22:09 prashantjois

This enhancement works but I'm struggling to test it. Would love some guidance on creating a test model with a has_many and has_many through: ... association.

prashantjois avatar Sep 03 '18 22:09 prashantjois

It would be great to have this feature in the main gem!

StragaSevera avatar Nov 20 '19 23:11 StragaSevera

@mcmire is there anything pending for this PR?

KapilSachdev avatar Sep 07 '20 15:09 KapilSachdev

@KapilSachdev Yes. In order to merge this addition, there need to be tests. Essentially, most of the scenarios represented within validate_length_of_spec, including most of the qualifier tests, need to be updated to also account for associations. This includes:

  • Validation option minimum + qualifier is_at_least
  • Validation option maximum + qualifier is_at_most
  • Validation option is + qualifier is_equal_to
  • allow_nil
  • allow_blank

mcmire avatar Sep 08 '20 04:09 mcmire

My bad, i missed the PR: Needs Tests label. As the OP hasn't responded and in case anyone else does not wants to work, I will move this PR forward asap, .

KapilSachdev avatar Sep 08 '20 05:09 KapilSachdev

@KapilSachdev No worries, I should have said something initially when adding that tag. Thank you, that would be much appreciated!

mcmire avatar Sep 08 '20 16:09 mcmire

Closing this PR as this was implemented on #1569.

matsales28 avatar Aug 18 '23 12:08 matsales28