投票に関連付けられた投稿をファクトリしようとしています。Post.votesがそれに関連付けられたVoteを生成するようにします。
Factory.define :voted_post, :parent => :post, :class => Post do |p|
p.association :votes, :factory => :vote
end
そして私のrspec2は比較的簡単です:
describe "vote scores" do
it "should show me the total vote score" do
@post = Factory(:voted_post)
@post.vote_score.should == 1
end
end
では、なぜこのエラーが返されるのでしょうか。
Failures:
1) Post vote scores should show me the total vote score
Failure/Error: @post = Factory(:voted_post)
undefined method `each' for #<Vote:0x105819948>
ルビー1.8.7(2009-06-12パッチレベル174)[universal-darwin10.0]
Rails 3.0.0