Rails上的Rails测试教程,ArgumentError

时间:2019-02-18 02:52:40

标签: ruby-on-rails

我目前正在学习Ruby on Rails on Rails教程。当我进行Rails测试时,遇到了此错误。

日志

ArgumentError: wrong number of arguments (given 2, expected 1)
    app/models/user.rb:35:in `authenticated?'
    app/controllers/account_activations_controller.rb:4:in `edit'
    test/integration/users_signup_test.rb:35:in `block in <class:UsersSignupTest>'

app / models / user.rb

def authenticated?(remember_token)
    return false if remember_digest.nil?
    BCrypt::Password.new(self.remember_digest).is_password?(remember_token)
end

app / controllers / account_activations_controller.rb

def edit
    user = User.find_by(email: params[:email])
    if user && !user.activated? && user.authenticated?(:activation, params[:id])
      user.update_attribute(:activated,    true)
      user.update_attribute(:activated_at, Time.zone.now)
      log_in user
      flash[:success] = "Account activated!"
      redirect_to user
    else
      flash[:danger] = "Invalid activation link"
      redirect_to root_url
    end

test / integration / users_signup_test.rb


test "valid signup information with account activation" do
    get signup_path
    assert_difference 'User.count', 1 do
      post users_path, params: { user: { name:  "Example User",
                                         email: "user@example.com",
                                         password:              "password",
                                         password_confirmation: "password" } }
    end

    assert_equal 1, ActionMailer::Base.deliveries.size
    user = assigns(:user)
    assert_not user.activated?
    log_in_as(user)
    assert_not is_logged_in?
    get edit_account_activation_path("invalid token", email: user.email)
    assert_not is_logged_in?
    get edit_account_activation_path(user.activation_token, email: 'wrong')
    assert_not is_logged_in?
    get edit_account_activation_path(user.activation_token, email: user.email)
    assert user.reload.activated?
    follow_redirect!
    assert_template 'users/show'
    assert is_logged_in?
  end
end

您能给我建议解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

好像您在第二行authenticated?中为app/controllers/account_activations_controller.rb#edit方法赋予了附加参数。

删除它,它应该可以工作。