I'm trying to use rspec and FactoryGirl for my acceptance tests in Rails app.
I have Program, ProgramLesson, Course, Lesson objects.
Here are factories for those things:
FactoryGirl.define do
factory :program do
after(:create) do |object|
create_list(:program_lesson, 10, program: object)
create(:course, program: object)
end
end
FactoryGirl.define do
factory :course do
program
after(:create) { |object| object.program.program_lessons.each { |pl| create(:lesson, course: object, program_lesson:
end
end
So, factories are creating program, then program_lessons for that program, then course that belongs_to program, and then course.lessons which belong to course and to program_lesson.
The problem is that course.lessons will only be created when I use byebug and program.reload before creating them. Why is this happening?
Aucun commentaire:
Enregistrer un commentaire