0
我有一個Note
對象附加到Course
,我想在FactoryGirl中隨機設置@note.number
到rand(@note.course.sections)
。我試過:FactoryGirl設置屬性與關聯
factory :note do
association :course
number { ranb(course.sections) }
content { Faker::Lorem.paragraphs(paragraph_count = 1).join(" ") }
end
它不工作,並說課程爲零。什麼是正確的方法來做到這一點?謝謝!
謝謝,我應該在控制檯也測試過它。錯誤實際上是由'FactoryGirl.attributes_for(:note)'發出的,因爲我沒有通過'course:'。 – randomor 2013-03-09 21:19:06