-
Notifications
You must be signed in to change notification settings - Fork 177
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
Length validator spec with minimum value doesn't work. #135
Comments
@joejeet Could you paste here the snippet of your class with |
Getting same issue with slightly different circumstances.
user_spec:
Gems:
|
I had the same problem and what should i do to solve it? thx! |
Having a similar issue, I fixed it by adding I was also able to reproduce this error outside of rspec when I ran the server, so there's a good chance that a) this isn't an rspec issue or b) I'm having an unrelated bug However, this causes an issue with password resets (which I'm assuming are a common feature in most of the apps using has_secure_password). A very shitty, temporary fix I implemented was overriding def password=(other_password)
if {validation logic fails}
error.add(:password, {some error})
end
super other_password
end |
As in rails has_secure_password the maximum length validation (should be less than or equal to 72 characters) is been added automatically for password field.
So, when you add something like this:
it { should validate_length_of(:password).with_minimum(6) }
it add length validation to the array and in array It just takes the first condition which comes true. So, length validation which is of maximum is accepted and ignores any other validation.
looks like this:
and it gives this error:
Failure/Error: it { should validate_length_of(:password).with_minimum(6) }
Expected User to have "length" validator on "password" with minimum of 6; instead got "length" validator on "password" with no minimum
The text was updated successfully, but these errors were encountered: