我正在关注rails教程在线书籍,我无法解决下面的问题
FAIL["test_valid_signup_information_with_account_activation", UsersSignupTest, 5.62457
6674999844]
test_valid_signup_information_with_account_activation#UsersSignupTest (5.63s)
Expected false to be truthy.
test/integration/users_signup_test.rb:38:in block in <class:UsersSignupTest>
require 'test_helper'
class UsersSignupTest < ActionDispatch::IntegrationTest
def setup
ActionMailer::Base.deliveries.clear
end
test "invalid signup information" do
get signup_path
assert_no_difference 'User.count' do
post users_path, params: { user: { name: "", email: "user@invalid", password: "foo", password_confirmation: "bar" } }
end
assert_template 'users/new'
assert_select 'div#error_explanation'
assert_select 'div.field_with_errors'
end
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: "foobar12", password_confirmation: "foobar12" } }
end
assert_equal 1, ActionMailer::Base.deliveries.size
user = assigns(:user)
assert_not user.activated?
# Try to log in before activation.
log_in_as(user)
assert_not is_logged_in?
# Invalid activation token
get edit_account_activation_path("invalid token")
assert_not is_logged_in?
# Valid token, wrong email
get edit_account_activation_path(user.activation_token, email: 'wrong')
assert_not is_logged_in?
# Valid activation token
get edit_account_activation_path(user.activation_token, email: user.email)
**assert user.reload.activated?**
# Problem is here, but unsure why??
follow_redirect!
assert_template 'users/show'
assert is_logged_in?
end
end
以下是帐户激活控制器的代码:
class AccountActivationsController < ApplicationController
def edit
user = User.find_by(email: params[:email])
if user && !user.activated? && user.authenticated?(:activation, params[:id])
# user.activate
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
end
end
答案 0 :(得分:0)
可能是之前的错误,而您没有注意到。这将是rails 4.2的语法(没有params :):
assert_difference 'User.count', 1 do
post users_path, user: { name: 'Example User',
email: 'user@example.com',
password: 'foo12',
password_confirmation: 'foo12' }
end