I have a rails model with this validation:
validates_numericality_of(:insert_oz,
:allow_blank=>true,
:greater_than=>0,
:if=>(proc do |note|
!note.insert_pages.nil? &&
note.insert_pages > 0
end))
Using remarkable, how do I test a validation that uses the :if
option?
If I do the obvious, and add the validation to my spec, changing "validates" to "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))
Then the spec fails with this message:
'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