http://robots.thoughtbot.com/post/254496652/aint-no-calla-back-girl arasındaki has_many
ilişkileri için FactoryGirl örneğini kullanıyorum. Özellikle, örnektir:FactoryGirl has_many şirketi
Modeller:
class Article < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :article
end
Fabrikalar:
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
Aynı örneği (uygun şema ile, elbette), bir hata atılır olduğunu çalıştırmak
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)
FactoryGirl ile has_many
dernekleri oluşturmak için yeni bir yol var mı?