我在第8章的最后一部分,在推送到Heroku之前需要我的最后一个测试套件是绿色的。出于某种原因,我发现错误,我认为在我创建用户时可以追溯到第6章(当时有一些问题)。
出现以下错误:
1) Failure:
SessionsHelperTest#test_current_user_returns_right_user_when_session_is_nil
[/Users/carlosgrijalva/workspace/sample_app/test/helpers/sessions_helper_test.rb:11]:
--- expected
+++ actual
@@ -1 +1 @@
-#<User id: 762146111, name: "Michael Hartl", email: "mhartl@example.com",
created_at: "2016-07-20 14:56:07", updated_at: "2016-07-20 14:56:12",
password_digest: "$2a$04$ll9WRPhi4/y65RgRqiMwiO4evjbp8mR1FwCTIkdZsMA...",
remember_digest: "$2a$04$IOc/zghNtUBNFi45l96DwOc7YYUT2f2BJsob5wLg/c0...">
+nil
users_login_test.rb
require 'test_helper'
class SessionsHelperTest < ActionView::TestCase
def setup
@user = users(:michael)
remember(@user)
end
test "current_user returns right user when session is nil" do
assert_equal @user, current_user
assert is_logged_in?
end
test "current_user returns nil when remember digest is wrong" do
@user.update_attribute(:remember_digest, User.digest(User.new_token))
assert_nil current_user
end
end
users.yml里
michael:
name: Michael Hartl
email: mhartl@example.com
password_digest: <%= User.digest('password') %>
现在,我认为这可以追溯到第6章,当时我正在玩弄用户。我最终删除了我创建的第一个,最终使2个用户拥有不同的名字/电子邮件:
第一位用户
2.3.1 :001 > User.first
User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
=> #<User id: 1, name: "Rails Tutorial", email: "example@railstutorial.com",
created_at: "2016-07-05 21:54:47",
updated_at: "2016-07-05 21:54:47",
password_digest: "$2a$10$KH0GTDtLldSCWy6xAUebZuFH11U7DPmkT6uZAZQ0xf2...",
remember_digest: nil>
第二位用户
2.3.1 :002 > User.second
User Load (1.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 OFFSET 1
=> #<User id: 2, name: "Example User2", email: "example2@railstutorial.com",
created_at: "2016-07-07 18:17:20", updated_at: "2016-07-19 21:40:31",
password_digest: "$2a$10$GzAoNK2GDp5ne1hTb70jDuO8m1ydthy879Xto/gJpWx...",
remember_digest: "$2a$10$I/yQhO/HLNkGF9aUk9ldMeZvuBHYK2akM1b0at1n1bk...">
我不确定这是否与错误有关,但似乎相关。任何建议都将不胜感激,谢谢。