我正在嘗試Factory與投票相關的帖子。因此,Post.votes會生成與之關聯的投票。未定義的方法`每個'在一個factory_girl/rspec2場景
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 PATCHLEVEL 174) universal-darwin10.0]
Rails 3.0.0
只要執行'p.association:vote'(非複數) – 2010-09-21 03:47:19
單個投票怎麼會不能用作數組? – Trip 2010-09-21 14:29:10
@Trip請參閱編輯。 – 2010-09-21 14:37:00