diff --git a/app/models/user.rb b/app/models/user.rb index 765050e92f9..27156250ac1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 35983247a2c..e2b0cf3e72c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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