我正在尝试制作与投票相关的帖子。这样 Post.votes 将生成与之关联的投票。
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>
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
导轨 3.0.0