【发布时间】:2010-08-25 15:37:02
【问题描述】:
我有一个带有此验证的 rails 模型:
validates_numericality_of(:insert_oz,
:allow_blank=>true,
:greater_than=>0,
:if=>(proc do |note|
!note.insert_pages.nil? &&
note.insert_pages > 0
end))
使用显着,我如何测试使用:if 选项的验证?
如果我做了显而易见的事情,并将验证添加到我的规范中,将“validates”更改为“should_validate”:
should_validate_numericality_of(:insert_oz,
:allow_blank=>true,
:greater_than=>0,
:if=>(proc do |note|
!note.insert_pages.nil? &&
note.insert_pages > 0
end))
然后规范失败并显示此消息:
'Processingnote should ensure numericality of insert oz is greater than 0 and allowing blank values' FAILED
Expected Processingnote to be invalid when insert oz is less than 1
【问题讨论】:
标签: ruby-on-rails