I'm using Rails 7 and I try to validate the uniqueness of multiple columns using scope
regardless of the case, as follow:
validates :attr1, uniqueness: { scope: %i[attr2 attr3], case_sensitive: false }
The following spec passes
it "is not valid without a unique attr1, attr2, and attr3" do
model = create(:model)
expect(build(:model, attr1: model.attr1, attr2: model.attr2, attr3: model.attr3)).to_not be_valid
end
But this fails
it "is not valid without a unique attr1, attr2, and attr3 (case sensitive)" do
model = create(:model)
expect(build(:model, attr1: model.attr1.upcase, attr2: model.attr2.upcase, attr3: model.attr3.upcase)).to_not be_valid
end
What am I doing wrong?