Updated email hash to Gravatar specifications

Gravatar email hashes have two requirements:
* Whitespace must be trimmed
* Email should be downcased
This commit is contained in:
Andy
2013-02-05 19:44:49 -07:00
parent d237e3bf3b
commit 66022f9faa
3 changed files with 2138 additions and 84 deletions

View File

@@ -176,7 +176,7 @@ class User < ActiveRecord::Base
end
def self.email_hash(email)
Digest::MD5.hexdigest(email)
Digest::MD5.hexdigest(email.strip.downcase)
end
def email_hash

File diff suppressed because it is too large Load Diff

View File

@@ -291,6 +291,22 @@ describe User do
it 'should have a sane email hash' do
@user.email_hash.should =~ /^[0-9a-f]{32}$/
end
it 'should use downcase email' do
@user.email = "example@example.com"
@user2 = Fabricate(:user)
@user2.email = "ExAmPlE@eXaMpLe.com"
@user.email_hash.should == @user2.email_hash
end
it 'should trim whitespace before hashing' do
@user.email = "example@example.com"
@user2 = Fabricate(:user)
@user2.email = " example@example.com "
@user.email_hash.should == @user2.email_hash
end
end
describe 'name heuristics' do