Arp*_*nav 3 unit-testing ruby-on-rails ruby-on-rails-3
我正在研究Rails 3测试用例.在撰写案例的同时,我得到了贬值错误
DEPRECATION WARNING: Errors#on have been deprecated, use Errors#[] instead.
Also note that the behaviour of Errors#[] has changed. Errors#[] now always returns an Array. An empty Array is returned when there are no errors on the specified attribute. (called from on at /usr/local/lib/ruby/gems/1.9.1/gems/activemodel-3.0.0.rc/lib/active_model/deprecated_error_methods.rb:7)
Run Code Online (Sandbox Code Playgroud)
为此,我使用了错误[:field]而不是errors.on(:field)现在,弃用错误消失了,但是案例在早期工作时没有起作用.它没有测试模型的任何验证
索尔
更换:
errors.on(:field)
Run Code Online (Sandbox Code Playgroud)
有:
errors.include?(:field)
Run Code Online (Sandbox Code Playgroud)
在搜索了如何执行此操作但没有找到任何内容的示例后,我最终做了:
errors[:field].present? / errors[:field].blank?
Run Code Online (Sandbox Code Playgroud)
不知道这是否是首选方式,但它似乎可以完成这项工作.
| 归档时间: |
|
| 查看次数: |
5005 次 |
| 最近记录: |