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
Fix NoMethodError in random_password #850
Conversation
The method `random_password` uses `self` to retrieve the `password_length` configuration, but `self` is the `User` class, which has no `password_length` by default. The length of the password should be fetch from Devise's own config
Getting password_length from devise is not right, because it can be changed in the model, as it's done in the test you changed. If you change only lib, test fails, so it's not right way to fix it. I'm not sure why it raises NoMethodError, but it doesn't happen in devise invitable tests, do you have validatable in your model? |
Hi @scambra, thanks for the info! No, we're not using In the default # Ensure that invited record is valid.
# The invitation won't be sent if this check fails.
# Default: false
# config.validate_on_invite = true which leads me to believe that Let me know if I misunderstood. |
No validatable shouldn't be mandatory, but when is added, model's password_length must be used. So right way to fix would be: respond_to?(:password_length) ? password_length : Devise.password_length Or other way to check if :validatable is used by model instead of using respond_to? |
Cool, I'll change the code and test for both cases. Thank you! |
Thanks for working on this |
@scambra those failures look unrelated, at least those related to nokogiri |
Thank you! 🙌 |
Will you cut a new release with this fix? @scambra |
@davidwessman 2.0.5 released |
The method
random_password
usesself
to retrieve thepassword_length
configuration, butself
is theUser
class, which has nopassword_length
by default.This will result in:
when
User.invite!()
is called without apassword
. See also Forem's dependabot's integration build: forem/forem#13383The length of the password should be fetch from Devise's own config I think
Refs #848