While trying to write rSpec tests, im a bit confused on how to generate FactoryGirl records with associations.
Basically, I have a Quiz
model and a Question
model. They are related through a HABTM association.
Here is my Quiz
factory:
FactoryGirl.define do
factory :quiz do
description 'Test'
# after(:create) { |quiz| quiz.create_sample_questions }
# trait :with_questions do
# after :create do |quiz|
# 5.times do |q|
# quiz.questions << FactoryGirl.create(:question, :with_answers)
# end
# end
# end
end
end
Is it best to create a trait here, and then create sample questions for a quiz? or should I use the after create method to do this?
Neither seem to work, and my trait doesn't seem to generate questions.
Thanks!
question
factory along with how you are calling aquiz
withwith_questions
trait? – Boldfaced