Password Reset Test failing in M.Hartl's Ruby on Rails Tutorial (3rd edition), Chapter 10 (10.54)

徘徊边缘 提交于 2019-12-06 04:15:27

I think this is a pretty simple mistake:

In your test, on line 53 you are submitting the password reset form to choose a new password for the user, but the new password you've chosen ("foobaz") is only 6 characters long:

patch password_reset_path(user.reset_token),
      email: user.email,
      user: { password:              "foobaz",
              password_confirmation: "foobaz" }

But then in user.rb you stipulate that passwords must be at least 8 characters:

validates :password, presence: true, length: { minimum: 8 }, allow_nil: true

So that's why password reset fails. Use a longer password and you should be OK!

To figure this out, you could have added this line just before the failing assertion:

puts html_document

Which would dump the rendered HTML to your terminal window, where you would find...

<div class="alert alert-danger">
  The form contains 1 error.
</div>
<ul>
  <li>Password is too short (minimum is 8 characters)</li>
</ul>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!