6
在我的工厂中,我有一个布尔字段(求值),我试图设置为false。我想需要的领域,始终设置为真正或假FactoryGirl:为布尔值赋值为false
型号
validates_presence_of :evaluated
厂
FactoryGirl.define do
factory :submission do
evaluated true
score 1.5
ranking 1.5
submission_type "user"
.
.
end
end
在测试
it { should validate_presence_of(:evaluated) }
当我跑步它
Failure/Error: expect(@submission).to be_valid
expected #<Submission id: nil, competition_id: 163, user_id: 134, team_id: nil, evaluated: false, score: 1.5, ranking: 1.5, submission_type_cd: "user", withdrawn: true, withdrawn_date: "2016-02-08", created_at: nil, updated_at: nil> to be valid, but got errors: Evaluated can't be blank
如果我的值更改为true,测试通过
evaluated true
我怎样才能建立一个工厂与布尔假值?
它更是你无法验证布尔值的存在。 'false.present? => false' –
那么最好的选择是将它添加为db级别的非空值? – ardochhigh
是的,这就是我要做的 –