Fixed check_name().

This commit is contained in:
Martin Edenhofer 2012-11-02 08:14:59 +01:00
parent 3c7943dc27
commit f723ea3cdb
2 changed files with 32 additions and 2 deletions

View file

@ -333,7 +333,7 @@ Your #{config.product_name} Team
def check_name
if !self.firstname.empty? && self.lastname.empty?
if ( self.firstname && !self.firstname.empty? ) && ( !self.lastname || self.lastname.empty? )
# Lastname, Firstname
scan = self.firstname.scan(/, /)
@ -351,7 +351,7 @@ Your #{config.product_name} Team
return
# -no name- firstname.lastname@example.com
elsif self.firstname.empty? && self.lastname.empty? && !self.email.empty?
elsif ( !self.firstname || self.firstname.empty? ) && ( !self.lastname || self.lastname.empty? ) && ( self.email && !self.email.empty? )
scan = self.email.scan(/^(.+?)\.(.+?)\@.+?$/)
if scan[0]
self.firstname = scan[0][0].capitalize

View file

@ -34,6 +34,21 @@ class UserTest < ActiveSupport::TestCase
:login => 'some@example.com',
},
},
{
:create => {
:firstname => 'Firstname Lastname',
:lastname => nil,
: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',
@ -79,6 +94,21 @@ class UserTest < ActiveSupport::TestCase
:login => 'login',
},
},
{
:create => {
:firstname => nil,
:lastname => nil,
: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|