【问题标题】:Testing a conditional validation with remarkable以非凡的方式测试条件验证
【发布时间】: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


    【解决方案1】:

    try and catch 语句?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-27
      • 2012-12-22
      • 1970-01-01
      • 2019-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多