2011-01-12 4 views
0

Michael Hartlのチュートリアルを終了するのが難しい。助けて?マイケル・ハートルの(素晴らしい)<a href="http://railstutorial.org/" rel="nofollow">Ruby on Rails Tutorial</a>、<a href="http://railstutorial.org/chapters/following-users#code%3afollowing_followers_actions" rel="nofollow">final section</a>に、私が手に、次のエラー後

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

mp3のように思えるがフィードに含まれていません。どのようにそれを修正するための任意のアイデア?または、コード内で起こりうるエラーを探す場所はどこですか?私はファイルをHartl's original codeと比較した。正確であるようです。

ありがとうございました。

答えて

2

はい、関係の設定に問題があるようです。 Userモデルのfollow!メソッドがこのようになっていることを確認してください。

def follow!(followed) 
    relationships.create!(:followed_id => followed.id) 
end 
+0

ありがとうございます。問題は{}のMySQLスニペットにありませんでした。チュートリアルを完了してください!ご協力いただきありがとうございます。 –

関連する問題