Having difficulties in ending Michael Hartl's tutorial. Help?
Following Michael Hartl's (amazing) Ruby on Rails Tutorial, on the final section, I get the following errors:
1) User micropost associations status feed should include the microposts of followed users
Failure/Error: @user.feed.should include(mp3)
expected [#<Micropost id: 2, content: "Foo bar", user_id: 1, created_at: "2011-01-12 21:22:41", updated_at: "2011-01-12 22:22:41">, #<Micropost id: 1, content: "Foo bar", user_id: 1, created_at: "2011-01-11 22:22:41", updated_at: "2011-01-12 22:22:41">] to include #<Micropost id: 3, content: "Foo bar", user_id: 2, created_at: "2011-01-12 22:22:41", updated_at: "2011-01-12 22:22:41">
Diff:
@@ -1,2 +1,2 @@
-#<Micropost id: 3, content: "Foo bar", user_id: 2, created_at: "2011-01-12 22:22:41", updated_at: "2011-01-12 22:22:41">
+[#<Micropost id: 2, content: "Foo bar", user_id: 1, created_at: "2011-01-12 21:22:41", updated_at: "2011-01-12 22:22:41">, #<Micropost id: 1, content: "Foo bar", user_id: 1, created_at: "2011-01-11 22:22:41", updated_at: "2011-01-12 22:22:41">]
# ./spec/models/user_spec.rb:214
2) Micropost from_users_followed_by should include the followed user's microposts
Failure/Error: Micropost.from_users_followed_by(@user).should include(@other_post)
expected [#<Micropost id: 1, content: "foo", user_id: 1, created_at: "2011-01-12 22:22:46", updated_at: "2011-01-12 22:22:46">] to include #<Micropost id: 2, content: "bar", user_id: 2, created_at: "2011-01-12 22:22:46", updated_at: "2011-01-12 22:22:46">
Diff:
@@ -1,2 +1,2 @@
-#<Micropost id: 2, content: "bar", user_id: 2, created_at: "2011-01-12 22:22:46", updated_at: "2011-01-12 22:22:46">
+[#<Micropost id: 1, content: "foo", user_id: 1, 开发者_JS百科created_at: "2011-01-12 22:22:46", updated_at: "2011-01-12 22:22:46">]
# ./spec/models/micropost_spec.rb:75
Finished in 9.18 seconds
153 examples, 2 failures
Seems like mp3
is not included in the feed. Any ideas on how to fix it? Or where to look for possible errors in the code? I compared the files with Hartl's original code; seems exact.
Thanks.
Yes, it looks like you have a problem setting relationships. Make sure your follow!
method in your User
model looks exactly like this
def follow!(followed)
relationships.create!(:followed_id => followed.id)
end
精彩评论