【发布时间】:2019-02-27 16:54:31
【问题描述】:
当我运行我的 rspec 测试时,我收到验证错误year is required,但在我的工厂中我设置了年份值。我不知道为什么会收到此错误。
FactoryBot.define do
factory :syllabus do
year { 2019 }
cycle_academic { "1" }
modality { "presencial" }
syllabus_content { "{}" }
association :doc_template
association :user
association :curriculum_course
association :cycle
credits { 4 }
weekly_hours { 5 }
trait :syllabus_estrategia do
course { :estrategia }
end
trait :syllabus_ingles1 do
course { :ingles1 }
end
trait :syllabus_ingles2 do
course { :ingles2 }
end
trait :syllabus_matematica do
course { :matematica }
end
end
end
在我的 rspec 文件中,我用这一行调用这个工厂
it "order to approver" do
syllabus_general = FactoryBot.create(:syllabus)
end
【问题讨论】:
-
db 中有
year列的类型是什么? -
其中一个相关型号是否也需要一年(其工厂不提供)?
-
@smathy 你是对的。在我的关联模型中,我没有设置 year 的值。现在它的作品。谢谢你。请问你能把你的答案给接受它并赚取你的积分吗?。
-
嘿,很酷,我试图以一种可能对碰巧遇到您的问题的其他人有所帮助的方式来制定我的答案。干杯。