FactoryGirl不会在不重新加载父项的情况下创建嵌套对象

时间:2017-10-03 12:42:25

标签: ruby-on-rails testing rspec factory-bot

我正在尝试使用class menudemo(QMainWindow): def __init__(self, parent = None): super(menudemo, self).__init__(parent) layout = QHBoxLayout() bar = self.menuBar() file = bar.addMenu("ملف") file.addAction("الجديد") save = QAction("حفظ",self) file.addAction(save) edit = file.addMenu("تصحيح") edit.addAction("نسخ") edit.addAction("معجون") quit = QAction("استقال",self) file.addAction(quit) file.triggered[QAction].connect(self.processtrigger) self.setLayout(layout) self.setWindowTitle("RTL") def processtrigger(self,q): print(q.text()+" is triggered") if __name__ == '__main__': app = QApplication(sys.argv) app.setLayoutDirection(Qt.RightToLeft) ex = menudemo() ex.show() sys.exit(app.exec_()) rspec进行Rails应用程序中的验收测试。

我有FactoryGirlProgramProgramLessonCourse个对象。

以下是模型:

Lesson

以下是这些东西的工厂:

class Program < ApplicationRecord
  has_many :program_lessons
  has_many :courses
end

class ProgramLesson < ApplicationRecord
  has_many :lessons
end

class Course < ApplicationRecord
  belongs_to :program
  has_many :lessons
end

class Lesson < ApplicationRecord
  belongs_to :program_lesson
  belongs_to :course
end

因此,工厂正在为 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 创建program,然后program_lessons,然后为program创建course,然后program属于course.lessonscourse

问题是program_lesson只会在创建course.lessonsbyebug之前创建。为什么会这样?

0 个答案:

没有答案