我需要傳遞額外的參數給工廠女孩用於回調。像這樣的東西(但更復雜的真正):工廠女孩的額外參數
Factory.define :blog do |blog|
blog.name "Blah"
blog.after_create do |blog|
blog.posts += sample_posts
blog.save!
end
end
,然後用像這樣創建:
Factory.create(:blog, :sample_posts => [post1, post2])
任何想法怎麼辦呢?
這裏有用的一組文檔,包括如何訪問一個瞬態屬性一個after_create或其他塊:https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md – Hollownest 2012-05-01 18:13:46
'忽略'已棄用。改用'transient'。 – 2015-03-18 19:10:40
@JonathanTran非常感謝,我編輯了我的答案以反映變化! – wintersolutions 2015-03-19 10:34:55