I use Bcrypt gem for password encryption.
User model:
class User < ApplicationRecord has_secure_password validates :password, presence: true, length: { minimum: 6 }, confirmation: true # ...end
How to allow password to be blank when user is updated?:
expect(user.update(name: 'Joana', password: '')).to be(true)
But not update password?
expect { user.update(name: 'Joana', password: '') }.not_to(change { user.reload.password_digest })
If you want to test it, mind to find user before updating it not to get false positives:
user = User.find(user.id)