From 19897df1ecd13456f1270c6c4af50016acc39c04 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 24 Oct 2011 21:34:56 -0700 Subject: [PATCH] more first_name fixing --- app/models/person.rb | 4 +++- spec/models/person_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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