我要幹在我廠創建/建立後鉤:DRY FactoryGirl後創建/建立掛鉤
FactoryGirl.define do
factory :poll do
sequence :title do |n|
"MyPollTitle#{n}"
end
sequence :description do |n|
"MyPollDescription#{n}"
end
user
factory :poll_with_answers do
ignore do
answers_count 2
end
after(:build) do |poll, evaluator|
evaluator.answers_count.times do
poll.answers << build(:answer, poll: poll)
end
end
after(:create) do |poll, evaluator|
evaluator.answers_count.times do
poll.answers << create(:answer, poll: poll)
end
end
end
end
end
我面臨的問題是,它似乎我不能定義在FG的方法呢?想法如何幹這件事?
它應該做的伎倆。它與你的代碼非常相似,所以如果評估器在lambda版本中爲零,那麼它也應該在你的版本中爲零。你能不能把我的原始工作代碼和得到nils的代碼(也就是棧跟蹤)都歸爲一類。我目前沒有足夠的信息進行調試。 – 2012-07-18 22:16:11
你不需要在這方面投入更多的工作,這並不重要,我基本上只是想檢查是否有一個快捷方式。無論如何,我在https://gist.github.com/3140033上看到了模型,剩下的是1:1。 – wintersolutions 2012-07-19 00:51:40
好吧,不用擔心,但檢查完代碼後,我不知道「評估者」是什麼:) – 2012-07-19 07:45:48