diff --git a/app/models/person.rb b/app/models/person.rb index 92d29b8d7..23d748c92 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -148,7 +148,7 @@ class Person < ActiveRecord::Base end def self.name_from_attrs(first_name, last_name, diaspora_handle) - first_name.blank? ? diaspora_handle : "#{first_name.to_s.strip} #{last_name.to_s.strip}" + first_name.blank? && last_name.blank? ? diaspora_handle : "#{first_name.to_s.strip} #{last_name.to_s.strip}".strip end def first_name diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index b8b9a9d0b..c1bd235a4 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -270,7 +270,7 @@ describe AspectsController do describe '#edit' do before do - eve.profile.first_name = nil + eve.profile.first_name = eve.profile.last_name = nil eve.profile.save eve.save diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index e77413de4..66432f6c8 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -151,13 +151,25 @@ describe Person do @profile = @person.profile end - context 'with first name' do - it 'should return their name for name' do - Person.name_from_attrs(@profile.first_name, @profile.last_name, @profile.diaspora_handle).should match /#{@profile.first_name}|#{@profile.last_name}/ + context 'with only first name' do + it 'should return their first name for name' do + Person.name_from_attrs(@profile.first_name, nil, @profile.diaspora_handle).should == @profile.first_name.strip end end - context 'without first name' do + context 'with only last name' do + it 'should return their last name for name' do + Person.name_from_attrs(nil, @profile.last_name, @profile.diaspora_handle).should == @profile.last_name.strip + end + end + + context 'with both first and last name' do + it 'should return their composed name for name' do + Person.name_from_attrs(@profile.first_name, @profile.last_name, @profile.diaspora_handle).should == "#{@profile.first_name.strip} #{@profile.last_name.strip}" + end + end + + context 'without first nor last name' do it 'should display their diaspora handle' do Person.name_from_attrs(nil, nil, @profile.diaspora_handle).should == @profile.diaspora_handle end