Quantcast
Channel: User Schwern - Stack Overflow
Viewing all articles
Browse latest Browse all 581

Comment by Schwern on How to prevent password from being updated if empty in Rails Model and test it with RSpec?

$
0
0
@ChiaraAni Did you try it?user.update!(password: nil) and user.update!(password: "") and user.update!(password: " ") will all fail the validation, but user.update(name: 'Joana') works fine because the password is not being updated. You do not need to allow nil. Maybe the misunderstanding here is that user.update(name: "Foo") and user.update(name: "Foo", password: nil) are different. There's a very important difference between passing in a key with a value of nil and not passing in a key at all.

Viewing all articles
Browse latest Browse all 581


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>