diff --git a/app/models/profile.rb b/app/models/profile.rb index 661d42920..579dd2208 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -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 diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index 00996fef5..81a816674 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -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"