我正在编写测试帐户激活的测试,但我遇到了一些问题:
test "valid signup information with account activation" do
log_in_as(@user)
get new_company_path
assert_difference 'Company.count', 1 do
assert_difference 'User.count', 1 do
post companies_path, company: { name: "company",
users_attributes: [{
first_name: 'John',
last_name: 'Doe',
email: 'user@example.com',
password: 'foobar' }]
}
end
end
assert_equal 1, ActionMailer::Base.deliveries.size
user = User.last
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?
follow_redirect!
assert_template '/'
assert is_logged_in?
end
问题是我无法检索我在POST中创建的用户。我尝试使用User.last,但似乎不起作用。有没有人知道如何使这项工作?
测试返回
Expected true to be nil or false
在assert_not is_logged_in?