Shoulda-matchers: validate_uniqueness_of and enum

Created on 31 Jan 2017  路  3Comments  路  Source: thoughtbot/shoulda-matchers

My environment

ruby 2.3.1
rails (4.2.7.1)
shoulda-matchers (3.1.1)
rspec-rails (~> 3.5)

My Class

Class A
  enum name: ['a', 'b']

  validates :name, uniqueness: true
end

My Spec

subject { build(:a, name: 'a') }
it { is_expected.to validate_uniqueness_of(:name) }

Failed Results

ArgumentError:
  'A' is not a valid name

The problem here is that shoulda-matcher check for case_sensitive too.

Most helpful comment

Right, that's the default behavior of the uniqueness validation, that it is case-sensitive-aware.

You can tell the matcher not to test for this by adding .ignore_case_sensitivity to the end of the matcher.

Cheers!

The qualifier is .ignoring_case_sensitivity :)

All 3 comments

Right, that's the default behavior of the uniqueness validation, that it is case-sensitive-aware.

You can tell the matcher not to test for this by adding .ignore_case_sensitivity to the end of the matcher.

Cheers!

@mcmire Thanks.

Right, that's the default behavior of the uniqueness validation, that it is case-sensitive-aware.

You can tell the matcher not to test for this by adding .ignore_case_sensitivity to the end of the matcher.

Cheers!

The qualifier is .ignoring_case_sensitivity :)

Was this page helpful?
0 / 5 - 0 ratings