我的 Rails 项目有问题 我正在从 railstutorial.org 学习,但我在列出 ~6.18 时遇到问题 所以这是 repo https://github.com/Mroczeks/first_project 这是错误:
rails test
Running via Spring preloader in process 10776
Started with run options --seed 33787
FAIL["test_schould_be_valid", UserTest, 0.6801217989996076]
test_schould_be_valid#UserTest (0.68s)
Expected false to be truthy.
test/models/user_test.rb:9:in `block in <class:UserTest>'
ERROR["test_email_addresses_should_be_saved_as_lower-case", UserTest, 0.6879979369996363]
test_email_addresses_should_be_saved_as_lower-case#UserTest (0.69s)
ActiveRecord::RecordNotFound: ActiveRecord::RecordNotFound: Couldn't find User without an ID
test/models/user_test.rb:45:in `block in <class:UserTest>'
FAIL["test_email_validation_should_accept_valid_addresses", UserTest, 0.7056386839994957]
test_email_validation_should_accept_valid_addresses#UserTest (0.71s)
"user@example.com" should be valid
test/models/user_test.rb:32:in `block (2 levels) in <class:UserTest>'
test/models/user_test.rb:30:in `each'
test/models/user_test.rb:30:in `block in <class:UserTest>'
18/18: [=================================] 100% Time: 00:00:00, Time: 00:00:00
Finished in 0.78367s
18 tests, 29 assertions, 2 failures, 1 errors, 0 skips
最佳答案
此错误的原因似乎是在将 @user
对象保存在 user_test.rb 文件中时验证失败。尝试用以下代码替换此测试,您将在运行此测试时看到验证失败:
test "email addresses should be saved as lower-case" do
mixed_case_email = "Foo@ExAMPle.CoM"
@user.email = mixed_case_email
# Calling `save!` here will raise an exception if failed to save @user.
@user.save!
assert_equal mixed_case_email.downcase, @user.reload.email
end
修复您的 setup
方法以相应地满足所有验证并重试。
关于ruby-on-rails - 找不到没有 ID 的用户 Hartl rails 教程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47866308/