没有ID哈特尔找不到用户轨教程

我有问题,我在轨 我从railstutorial.org学习项目,我在上市的有问题〜6.18 所以这是回购 https://github.com/Mroczeks/first_project 这是错误:没有ID哈特尔找不到用户轨教程

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)

"[email protected]" 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_test.rb文件保存@user对象时要失败验证。试着用下面的代码替换这个测试并运行这个测试时,你会看到验证失败:

test "email addresses should be saved as lower-case" do 

mixed_case_email = "[email protected]"

@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方法相应地满足所有验证,再尝试。

回答:

User模式,你必须defined password length validation为6作为最小的,但在测试设置,created the user与password: 'pies'。因此,你让所有的错误和失败:

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>'


要解决所有的错误,你需要在UserTest#setup初始化有效数据的用户。在这种情况下,您只需提供一个最小长度为6的密码。

以上是 没有ID哈特尔找不到用户轨教程 的全部内容, 来源链接: utcz.com/qa/262454.html

回到顶部