我在第10章中遇到了两个我不理解的错误。已经到处搜索,所以非常感谢任何帮助!
1) Error:
UsersSignupTest#test_valid_signup_information_with_account_activation:
NoMethodError: private method `authenticated?' called for #<User:0x00000009f0d058>
app/controllers/account_activations_controller.rb:5:in `edit'
test/integration/users_signup_test.rb:43:in `block in <class:UsersSignupTest>'
2) Error:
UserTest#test_authenticated?_should_return_false_for_a_user_with_nil_digest:
NoMethodError: private method `authenticated?' called for #<User:0x0000000aa1f360>
test/models/user_test.rb:62:in `block in <class:UserTest>'
帐户激活控制器:
class AccountActivationsController < ApplicationController
def edit
user = User.find_by(email: params[:email])
if user && !user.activated? && user.authenticated?(:activation, params[:id])
user.activate
log_in user
flash[:success] = "Account activated!"
redirect_to user
else
flash[:danger] = "Invalid activation link"
redirect_to root_url
end
end
end
Nil摘要测试:
test "authenticated? should return false for a user with nil digest" do
assert_not @user.authenticated?(:remember, '')
end
来自user.rb:
def authenticated?(attribute, token)
digest = send("#{attribute}_digest")
return false if digest.nil?
BCrypt::Password.new(digest).is_password?(token)
end
这是我的第一篇文章,如果它不应该是它,那就很抱歉。非常感谢任何帮助!
托托