mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:40:53 -06:00
FIX: suggest name when username/name is provided
This commit is contained in:
parent
560a16d864
commit
aee4045dd0
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user