FIX: strip whitespaces from user email

This commit is contained in:
Arpit Jalan 2015-01-30 01:11:41 +05:30
parent 22adb682d8
commit 6c410ed093
2 changed files with 14 additions and 5 deletions

View File

@ -62,7 +62,7 @@ class User < ActiveRecord::Base
delegate :last_sent_email_address, :to => :email_logs
before_validation :downcase_email
before_validation :strip_downcase_email
validates_presence_of :username
validate :username_validator
@ -764,8 +764,11 @@ class User < ActiveRecord::Base
self.username_lower = username.downcase
end
def downcase_email
self.email = self.email.downcase if self.email
def strip_downcase_email
if self.email
self.email = self.email.strip
self.email = self.email.downcase
end
end
def username_validator

View File

@ -261,8 +261,14 @@ describe User do
it "downcases email addresses" do
user = Fabricate.build(:user, email: 'Fancy.Caps.4.U@gmail.com')
user.save
expect(user.reload.email).to eq('fancy.caps.4.u@gmail.com')
user.valid?
expect(user.email).to eq('fancy.caps.4.u@gmail.com')
end
it "strips whitespace from email addresses" do
user = Fabricate.build(:user, email: ' example@gmail.com ')
user.valid?
expect(user.email).to eq('example@gmail.com')
end
end