我目前正在学习Ruby on Rails on Rails教程。
我做了rails测试,然后得到了这个错误。
UsersSignupTest#test_valid_signup_information_with_account_activation:
NameError: uninitialized constant User::FILL_IN
app/models/user.rb:42:in `activate'
app/controllers/account_activations_controller.rb:6:in `edit'
test/integration/users_signup_test.rb:39:in `block in <class:UsersSignupTest>'
我不明白此错误的含义。我可能必须初始化constant User::FILL_IN
。
class User < ApplicationRecord
attr_accessor :remember_token, :activation_token
before_save :downcase_email
before_create :create_activation_digest
....
def activate
update_columns(activated:FILL_IN, activated_at:FILL_IN)
end
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
require 'test_helper'
class UsersSignupTest < ActionDispatch::IntegrationTest
...
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
您能帮我解决这个问题吗?
答案 0 :(得分:0)
您不应实际使用单词FILL_IN
。您应该更改FILL_IN
才能通过测试。您可能需要类似的东西:
update_columns(activated: true, activated_at: Time.now)