I just upgraded my Rails project to use Shoulda Matchers 3.0
However the model test that validates the uniqueness of the title property is now failing:
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) }
the error message for the failing test is:
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)>'
Does anyone have experience with this issue?
thanks for your help,
Anthony
There's a known issue - https://github.com/thoughtbot/shoulda-matchers/issues/880 - apparently fixed in master.
While waiting for that fix you can lock to version 3.0.1 for now which should work.
The uniqueness matcher did change in 3.0.x to default to case sensitive to match the default of rails validator, so if you have rails validations set to case insensitive you will have to update your matcher calls to
is_expected.to validate_uniqueness_of(:whatever_field).case_insensitive