Emails are case insensitive

This commit is contained in:
Neil Lalonde
2014-07-14 10:16:24 -04:00
parent 0c8025d513
commit 01a68f8cc7
18 changed files with 105 additions and 13 deletions

View File

@ -423,4 +423,16 @@ describe Category do
end
describe "find_by_email" do
it "is case insensitive" do
c1 = Fabricate(:category, email_in: 'lower@example.com')
c2 = Fabricate(:category, email_in: 'UPPER@EXAMPLE.COM')
c3 = Fabricate(:category, email_in: 'Mixed.Case@Example.COM')
Category.find_by_email('LOWER@EXAMPLE.COM').should == c1
Category.find_by_email('upper@example.com').should == c2
Category.find_by_email('mixed.case@example.com').should == c3
Category.find_by_email('MIXED.CASE@EXAMPLE.COM').should == c3
end
end
end

View File

@ -16,6 +16,11 @@ describe EmailToken do
email_token.should be_present
end
it 'should downcase the email' do
token = user.email_tokens.create(email: "UpperCaseSoWoW@GMail.com")
token.email.should == "uppercasesowow@gmail.com"
end
it 'is valid' do
email_token.should be_valid
end

View File

@ -79,7 +79,7 @@ describe Invite do
it 'returns the original invite' do
topic.invite_by_email(inviter, 'iceking@adventuretime.ooo').should == @invite
topic.invite_by_email(inviter, 'iceking@ADVENTURETIME.ooo').should == @invite
topic.invite_by_email(inviter, 'ICEKING@adventuretime.ooo').should_not == @invite
topic.invite_by_email(inviter, 'ICEKING@adventuretime.ooo').should == @invite
end
it 'returns a new invite if the other has expired' do

View File

@ -15,6 +15,11 @@ describe ScreenedEmail do
# have ever been blocked by looking at last_match_at.
ScreenedEmail.create(email: email).last_match_at.should be_nil
end
it "downcases the email" do
s = ScreenedEmail.create(email: 'SPAMZ@EXAMPLE.COM')
s.email.should == 'spamz@example.com'
end
end
describe '#block' do
@ -66,6 +71,11 @@ describe ScreenedEmail do
ScreenedEmail.should_block?(email).should be_true
end
it "returns true when it's same email, but all caps" do
ScreenedEmail.create(email: email).save
ScreenedEmail.should_block?(email.upcase).should be_true
end
shared_examples "when a ScreenedEmail record matches" do
it "updates statistics" do
Timecop.freeze(Time.zone.now) do

View File

@ -242,6 +242,12 @@ describe User do
its(:email_tokens) { should be_present }
end
it "downcases email addresses" do
user = Fabricate.build(:user, email: 'Fancy.Caps.4.U@gmail.com')
user.save
user.reload.email.should == 'fancy.caps.4.u@gmail.com'
end
end
describe 'ip address validation' do
@ -755,7 +761,7 @@ describe User do
expect(found_user).to eq bob
found_user = User.find_by_username_or_email('Bob@Example.com')
expect(found_user).to be_nil
expect(found_user).to eq bob
found_user = User.find_by_username_or_email('bob1')
expect(found_user).to be_nil
@ -763,6 +769,9 @@ describe User do
found_user = User.find_by_email('bob@Example.com')
expect(found_user).to eq bob
found_user = User.find_by_email('BOB@Example.com')
expect(found_user).to eq bob
found_user = User.find_by_email('bob')
expect(found_user).to be_nil