mirror of
https://github.com/discourse/discourse.git
synced 2025-04-29 13:34:33 +08: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)
|
def self.suggest_name(email)
|
||||||
return "" if email.blank?
|
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
|
end
|
||||||
|
|
||||||
def self.find_by_username_or_email(username_or_email)
|
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
|
it 'is able to guess a decent name from an email' do
|
||||||
expect(User.suggest_name('sam.saffron@gmail.com')).to eq('Sam Saffron')
|
expect(User.suggest_name('sam.saffron@gmail.com')).to eq('Sam Saffron')
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe 'username format' do
|
describe 'username format' do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user