2010-08-25 52 views
0

我有這個驗證一個軌道模型:測試條件驗證具有顯着

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選項驗證?

如果我做明顯的,和驗證添加到我的規格,改變「驗證」到「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 

回答

0

試並捕獲聲明?