2
您将如何测试此代码(使用RSpec并最终Shoulda)?使用RSpec(和Shoulda Matchers)测试条件验证
validates_uniqueness_of :user_id, conditions: -> { where.not(status: "published").where.not(type: "Version") }
您将如何测试此代码(使用RSpec并最终Shoulda)?使用RSpec(和Shoulda Matchers)测试条件验证
validates_uniqueness_of :user_id, conditions: -> { where.not(status: "published").where.not(type: "Version") }
您只能使用shoulda-matchers测试预定义的验证。如果你想测试自定义验证,你应该编写你自己的规范实现。
请参阅https://stackoverflow.com/a/31642420/574621获取sol'n – MERM
创建记录。制作另一条记录,该记录将跳过该验证。验证第二条记录。确保错误存在。 – sevenseacat