uniqueness_of 升级应该匹配器后失败
uniqueness_of fails after upgrade shoulda matchers
我刚刚升级了我的 Rails 项目以使用 Shoulda Matchers 3.0
但是,验证标题唯一性的模型测试 属性 现在失败了:
app/models/product.rb
it { is_expected.to validate_uniqueness_of(:title) }
spec/models/product_spec.rb
it { is_expected.to validate_uniqueness_of(:title) }
失败测试的错误消息是:
Product should validate that :title is case-sensitively unique
Failure/Error: it { is_expected.to validate_uniqueness_of(:title) }
Product did not properly validate that :title is case-sensitively
unique.
The record you provided could not be created, as it failed with the
following validation errors:
* title: ["can't be blank"]
* description: ["can't be blank"]
# ./spec/models/product_spec.rb:6:in `block (2 levels) in <top (required)>'
有人遇到过这个问题吗?
感谢您的帮助,
安东尼
有一个已知问题 - https://github.com/thoughtbot/shoulda-matchers/issues/880 - 显然已在 master 中修复。
在等待该修复程序期间,您可以暂时锁定到版本 3.0.1,这应该可以工作。
唯一性匹配器确实在 3.0.x 中更改为默认区分大小写以匹配 rails 验证器的默认值,因此如果您将 rails 验证设置为不区分大小写,您必须将您的匹配器调用更新为
is_expected.to validate_uniqueness_of(:whatever_field).case_insensitive
我刚刚升级了我的 Rails 项目以使用 Shoulda Matchers 3.0
但是,验证标题唯一性的模型测试 属性 现在失败了:
app/models/product.rb
it { is_expected.to validate_uniqueness_of(:title) }
spec/models/product_spec.rb
it { is_expected.to validate_uniqueness_of(:title) }
失败测试的错误消息是:
Product should validate that :title is case-sensitively unique
Failure/Error: it { is_expected.to validate_uniqueness_of(:title) }
Product did not properly validate that :title is case-sensitively
unique.
The record you provided could not be created, as it failed with the
following validation errors:
* title: ["can't be blank"]
* description: ["can't be blank"]
# ./spec/models/product_spec.rb:6:in `block (2 levels) in <top (required)>'
有人遇到过这个问题吗?
感谢您的帮助,
安东尼
有一个已知问题 - https://github.com/thoughtbot/shoulda-matchers/issues/880 - 显然已在 master 中修复。
在等待该修复程序期间,您可以暂时锁定到版本 3.0.1,这应该可以工作。
唯一性匹配器确实在 3.0.x 中更改为默认区分大小写以匹配 rails 验证器的默认值,因此如果您将 rails 验证设置为不区分大小写,您必须将您的匹配器调用更新为
is_expected.to validate_uniqueness_of(:whatever_field).case_insensitive