Improved real name detection from user creation via email.
This commit is contained in:
parent
46e56b821f
commit
abe8fff0e7
2 changed files with 119 additions and 1 deletions
|
@ -332,10 +332,32 @@ Your #{config.product_name} Team
|
|||
end
|
||||
|
||||
def check_name
|
||||
if self.firstname && (!self.lastname || self.lastname == '')
|
||||
|
||||
if !self.firstname.empty? && self.lastname.empty?
|
||||
|
||||
# Lastname, Firstname
|
||||
scan = self.firstname.scan(/, /)
|
||||
if scan[0]
|
||||
name = self.firstname.split(', ', 2)
|
||||
self.lastname = name[0]
|
||||
self.firstname = name[1]
|
||||
return
|
||||
end
|
||||
|
||||
# Firstname Lastname
|
||||
name = self.firstname.split(' ', 2)
|
||||
self.firstname = name[0]
|
||||
self.lastname = name[1]
|
||||
return
|
||||
|
||||
# -no name- firstname.lastname@example.com
|
||||
elsif self.firstname.empty? && self.lastname.empty? && !self.email.empty?
|
||||
scan = self.email.scan(/^(.+?)\.(.+?)\@.+?$/)
|
||||
if scan[0]
|
||||
self.firstname = scan[0][0].capitalize
|
||||
self.lastname = scan[0][1].capitalize
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
96
test/unit/user_test.rb
Normal file
96
test/unit/user_test.rb
Normal file
|
@ -0,0 +1,96 @@
|
|||
# encoding: utf-8
|
||||
require 'test_helper'
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
test 'user' do
|
||||
tests = [
|
||||
{
|
||||
:create => {
|
||||
:firstname => 'Firstname',
|
||||
:lastname => 'Lastname',
|
||||
:email => 'some@example.com',
|
||||
:login => 'some@example.com',
|
||||
:created_by_id => 1,
|
||||
},
|
||||
:create_verify => {
|
||||
:firstname => 'Firstname',
|
||||
:lastname => 'Lastname',
|
||||
:email => 'some@example.com',
|
||||
:login => 'some@example.com',
|
||||
},
|
||||
},
|
||||
{
|
||||
:create => {
|
||||
:firstname => 'Firstname Lastname',
|
||||
:lastname => '',
|
||||
:email => 'some@example.com',
|
||||
:login => 'some@example.com',
|
||||
:created_by_id => 1,
|
||||
},
|
||||
:create_verify => {
|
||||
:firstname => 'Firstname',
|
||||
:lastname => 'Lastname',
|
||||
:email => 'some@example.com',
|
||||
:login => 'some@example.com',
|
||||
},
|
||||
},
|
||||
{
|
||||
:create => {
|
||||
:firstname => 'Lastname, Firstname',
|
||||
:lastname => '',
|
||||
:email => 'some@example.com',
|
||||
:login => 'some@example.com',
|
||||
:created_by_id => 1,
|
||||
},
|
||||
:create_verify => {
|
||||
:firstname => 'Firstname',
|
||||
:lastname => 'Lastname',
|
||||
:email => 'some@example.com',
|
||||
:login => 'some@example.com',
|
||||
},
|
||||
},
|
||||
{
|
||||
:create => {
|
||||
:firstname => '',
|
||||
:lastname => '',
|
||||
:email => 'firstname.lastname@example.com',
|
||||
:login => 'login',
|
||||
:created_by_id => 1,
|
||||
},
|
||||
:create_verify => {
|
||||
:firstname => 'Firstname',
|
||||
:lastname => 'Lastname',
|
||||
:email => 'firstname.lastname@example.com',
|
||||
:login => 'login',
|
||||
},
|
||||
},
|
||||
{
|
||||
:create => {
|
||||
:firstname => '',
|
||||
:lastname => '',
|
||||
:email => 'FIRSTNAME.lastname@example.com',
|
||||
:login => 'login',
|
||||
:created_by_id => 1,
|
||||
},
|
||||
:create_verify => {
|
||||
:firstname => 'Firstname',
|
||||
:lastname => 'Lastname',
|
||||
:email => 'firstname.lastname@example.com',
|
||||
:login => 'login',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
tests.each { |test|
|
||||
|
||||
user = User.create( test[:create] )
|
||||
|
||||
test[:create_verify].each { |key, value|
|
||||
assert_equal( user[key], value )
|
||||
}
|
||||
|
||||
user.destroy
|
||||
}
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in a new issue