2

I have a simple test to execute. Below is the following code:

  it 'should validate that email is lowercase' do
    account = build(:account, email: 'IRONMAN@gmail.com')
    lowercase_account = build(:account, email: 'warmachine@gmail.com')
    account.wont_be :valid?
    lowercase_account.must_be :valid?
  end

According to my test, IRONMAN@gmail.com should fail and warmachine@gmail.com 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?

Community
  • 1
  • 1
Dan Rubio
  • 4,709
  • 10
  • 49
  • 106

1 Answers1

3

Case sensitive doesn't mean everything must be lowercase to be valid, it means that you CAN have two emails like hello@example.com and HELLO@example.com.

If case sensitivity is set to false, you CANNOT have hello@example.com and HELLO@example.com

Eyeslandic
  • 14,553
  • 13
  • 41
  • 54