我有一个锻炼模型,它有很多 PerformedExercises,它有很多 PeformedSet。我无法让它在我的测试中构建一个对象,我不确定它是 SQLite3 还是其他东西(它在测试环境之外工作正常)。
我有以下工厂:
FactoryGirl.define do
factory :workout do
title 'workout one'
performed_exercise
end
factory :performed_exercise do
exercise_id '2'
performed_set
end
factory :performed_set do
set_number '1'
end
end
我的 RSpec 测试看起来像这样(我让它变得非常简单,以排除测试中的任何其他问题):
it "is causing me to lose hair" do
wrkt = FactoryGirl.build(:workout)
end
当我运行测试时,我收到以下错误消息:
Failure/Error: wrkt = FactoryGirl.build(:workout)
ActiveRecord::StatementInvalid:
SQLite3::ConstraintException: constraint failed:
INSERT INTO "performed_sets" ("created_at", "notes", "performed_exercise_id", "reps", "set_number", "updated_at", "weight")
VALUES (?, ?, ?, ?, ?, ?, ?)
任何帮助将不胜感激!