-
-
Notifications
You must be signed in to change notification settings - Fork 910
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
Matcher validate_comparison_of is not working with ActiveRecord objects #1655
Comments
Hey @cesarjr, unfortunately, this is a limitation of the current implementation, I'm planning to make it more robust in the future, just need to find some time 😢 But you should probably be able to to that if you slightly change your validation. If you compare using the IDs, instead of the whole object it should work the way you want. validates :transfer_account_id, comparison: { other_than: :itself_id }
# In the spec
it { is_expected to validate_comparison_of(:transfer_account_id).is_other_than(:itself_id) } Please let me know if that works for you |
Hey @matsales28, I would be glad to help on this but I just want to confirm the idea first should we add a case in this switch for Update: |
Hey @mohammednasser-32, I think limiting to objects that don't respond to the |
Hi @matsales28 ! First of all, I'd like to thank you to have used your time to answer my issue 😀. Well, unfortunately your solution is not viable for me because I also have others validations running for I ended up solving my problem writing a group of tests without Thanks again for your help. |
@matsales28 It turned out this needs more refactoring than I expected, The basic scenario can be handled using the approach mentioned before (changes here), however to handle every possible scenario it seems more refactoring needs to be done and I don't want to be causing a a lot of big changes...sorry for the noise 😓 |
Description
The matcher
validate_comparison_of
does not work when the attribute of the subject is also an ActiveRecord.Reproduction Steps
Save the script above and run:
Expected behavior
The test should pass.
Actual behavior
Complement
I'm not sure if the problem is around of here.
System configuration
shoulda_matchers version: 6.4.0
rails version: 7.2.2
ruby version: 3.3.5p100
The text was updated successfully, but these errors were encountered: