diff --git a/app/models/person.rb b/app/models/person.rb index daa07cde5..0d6d40829 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -154,7 +154,9 @@ class Person < ActiveRecord::Base self.diaspora_handle.split('@').first else names = profile.first_name.to_s.split(/\s/) - names[0...-1].join(' ') + str = names[0...-1].join(' ') + str = names[0] if str.blank? + str end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 4d03ee7c7..6257ffd69 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -281,6 +281,16 @@ describe Person do alice.person.profile.update_attributes(:first_name => "First Mid Last") alice.person.first_name.should == "First Mid" end + + it 'returns first word in first_name if first_name is present' do + alice.person.profile.update_attributes(:first_name => "Alice Smith") + alice.person.first_name.should == "Alice" + end + + it 'returns first word in first_name if first_name is present' do + alice.person.profile.update_attributes(:first_name => "Alice") + alice.person.first_name.should == "Alice" + end end describe '.search' do