FIX: suggest name when username/name is provided

This commit is contained in:
Arpit Jalan 2018-05-17 10:34:46 +05:30
parent 560a16d864
commit aee4045dd0
2 changed files with 15 additions and 1 deletions

View File

@ -288,7 +288,13 @@ class User < ActiveRecord::Base
def self.suggest_name(email)
return "" if email.blank?
email[/\A[^@]+/].tr(".", " ").titleize
if email[/\A[^@]+/].present?
# email provided
email[/\A[^@]+/].tr(".", " ").titleize
else
# username/name provided
email[/[^@]+\z/].tr(".", " ").titleize
end
end
def self.find_by_username_or_email(username_or_email)

View File

@ -449,6 +449,14 @@ describe User do
it 'is able to guess a decent name from an email' do
expect(User.suggest_name('sam.saffron@gmail.com')).to eq('Sam Saffron')
end
it 'is able to guess a decent name from username' do
expect(User.suggest_name('@sam.saffron')).to eq('Sam Saffron')
end
it 'is able to guess a decent name from name' do
expect(User.suggest_name('sam saffron')).to eq('Sam Saffron')
end
end
describe 'username format' do