我正在使用 FactoryGirl 示例来处理has_many
来自http://robots.thoughtbot.com/post/254496652/aint-no-calla-back-girl的关系。具体来说,例子是:
楷模:
class Article < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :article
end
工厂:
factory :article do
body 'password'
factory :article_with_comment do
after_create do |article|
create(:comment, article: article)
end
end
end
factory :comment do
body 'Great article!'
end
当我运行相同的示例(当然,使用正确的模式)时,会引发错误
2.0.0p195 :001 > require "factory_girl_rails"
=> true
2.0.0p195 :002 > article = FactoryGirl.create(:article_with_comment)
ArgumentError: wrong number of arguments (3 for 1..2)
有没有一种新方法可以创建has_many
与 FactoryGirl 关联的模型?