Strip full name considering cases where first or last name omitted
This commit is contained in:
parent
8187fb9ddb
commit
24be48d660
2 changed files with 21 additions and 1 deletions
|
|
@ -129,7 +129,7 @@ class Profile < ActiveRecord::Base
|
|||
# Constructs a full name by joining #first_name and #last_name
|
||||
# @return [String] A full name
|
||||
def construct_full_name
|
||||
self.full_name = [self.first_name, self.last_name].join(' ').downcase
|
||||
self.full_name = [self.first_name, self.last_name].join(' ').downcase.strip
|
||||
self.full_name
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,26 @@ describe Profile do
|
|||
end
|
||||
|
||||
describe '#contruct_full_name' do
|
||||
it 'generates a full name given only first name' do
|
||||
profile = Factory(:person).profile
|
||||
profile.first_name = "casimiro"
|
||||
profile.last_name = nil
|
||||
|
||||
profile.full_name.should_not == "casimiro"
|
||||
profile.save
|
||||
profile.full_name.should == "casimiro"
|
||||
end
|
||||
|
||||
it 'generates a full name given only last name' do
|
||||
profile = Factory(:person).profile
|
||||
profile.first_name = nil
|
||||
profile.last_name = "grippi"
|
||||
|
||||
profile.full_name.should_not == "grippi"
|
||||
profile.save
|
||||
profile.full_name.should == "grippi"
|
||||
end
|
||||
|
||||
it 'generates a full name given first and last names' do
|
||||
profile = Factory(:person).profile
|
||||
profile.first_name = "casimiro"
|
||||
|
|
|
|||
Loading…
Reference in a new issue