storing the entriety of the service profile name in first name

This commit is contained in:
Ilya Zhitomirskiy 2011-10-24 12:41:35 -07:00
parent 083f788359
commit 51778cb22d
2 changed files with 9 additions and 9 deletions

View file

@ -81,16 +81,9 @@ class Profile < ActiveRecord::Base
def from_omniauth_hash(omniauth_user_hash) def from_omniauth_hash(omniauth_user_hash)
mappings = {"description" => "bio", mappings = {"description" => "bio",
'image' => 'image_url', 'image' => 'image_url',
'first_name' => 'first_name', 'name' => 'first_name',
'last_name' => 'last_name',
'location' => 'location', 'location' => 'location',
'name' => 'full_name'
} }
if(omniauth_user_hash['first_name'].blank? || omniauth_user_hash['last_name'].blank?) && omniauth_user_hash['name'].present?
first, last = omniauth_user_hash['name'].split
omniauth_user_hash['first_name'] ||= first
omniauth_user_hash['last_name'] ||= last
end
update_hash = Hash[omniauth_user_hash.map {|k, v| [mappings[k], v] }] update_hash = Hash[omniauth_user_hash.map {|k, v| [mappings[k], v] }]

View file

@ -36,13 +36,20 @@ describe Profile do
it 'outputs a hash that can update a diaspora profile' do it 'outputs a hash that can update a diaspora profile' do
profile = Profile.new profile = Profile.new
profile.from_omniauth_hash(@from_omniauth)['first_name'].should == 'bob' profile.from_omniauth_hash(@from_omniauth)['bio'].should == 'this is my bio'
end end
it 'does not overwrite any exsisting profile fields' do it 'does not overwrite any exsisting profile fields' do
profile = Profile.new(:first_name => 'maxwell') profile = Profile.new(:first_name => 'maxwell')
profile.from_omniauth_hash(@from_omniauth)['first_name'].should == 'maxwell' profile.from_omniauth_hash(@from_omniauth)['first_name'].should == 'maxwell'
end end
it 'sets full name to first name' do
@from_omniauth = {'name' => 'bob jones', 'description' => 'this is my bio', 'location' => 'sf', 'image' => 'http://cats.com/gif.gif'}
profile = Profile.new
profile.from_omniauth_hash(@from_omniauth)['first_name'].should == 'bob jones'
end
end end
describe '#contruct_full_name' do describe '#contruct_full_name' do