Reputation: 4907
I have a simple test to execute. Below is the following code:
it 'should validate that email is lowercase' do
account = build(:account, email: '[email protected]')
lowercase_account = build(:account, email: '[email protected]')
account.wont_be :valid?
lowercase_account.must_be :valid?
end
According to my test, [email protected]
should fail and [email protected]
should pass. However when I run the test, both emails pass.
Here is my validation code for my Account
model.
validates :email, presence: :true, length: { in: 3..100 }, uniqueness: true,
confirmation: true, email_format: true, allow_blank: false
validates :email_confirmation, email_format: true, presence: true, allow_blank: false, on: :create
What could be the error here? I've referenced this link on SO as a starting point Rails 4 validation case insensitivity test. It had some good information but I am using Postgresql and not MySQL to perform the account insertion. To my knowledge, Postgresql does not do a case insensitive search so I should be good. Has anyone experienced this problem?
Upvotes: 2
Views: 537
Reputation: 14900
Case sensitive doesn't mean everything must be lowercase to be valid, it means that you CAN have two emails like [email protected]
and [email protected]
.
If case sensitivity is set to false, you CANNOT have [email protected]
and [email protected]
Upvotes: 3