diff --git a/app/models/user.rb b/app/models/user.rb index 1b2bb91d5..4040ba226 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 9e1b13ae5..1b8b32d40 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -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|