From a99e69edd64218431296f448505ec69d9cb90235 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 17 Aug 2011 16:51:34 -0700 Subject: [PATCH] down to 2 failures in postgres --- app/models/services/facebook.rb | 15 +++++++++++++-- spec/controllers/contacts_controller_spec.rb | 4 ++-- spec/integration/receiving_spec.rb | 1 + spec/models/services/facebook_spec.rb | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index 2252dd01f..8cac6b75f 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -47,15 +47,26 @@ class Services::Facebook < Service if postgres? # Take the naive approach to inserting our new visibilities for now. data.each do |su| - su.save + if existing = ServiceUser.find_by_uid(su.uid) + update_hash = OVERRIDE_FIELDS_ON_FB_UPDATE.inject({}) do |acc, element| + acc[element] = su.send(element) + acc + end + + existing.update_attributes(update_hash) + else + su.save + end end else - ServiceUser.import(data, :on_duplicate_key_update => [:updated_at, :contact_id, :person_id, :request_id, :invitation_id, :photo_url, :name, :username]) + ServiceUser.import(data, :on_duplicate_key_update => OVERRIDE_FIELDS_ON_FB_UPDATE + [:updated_at]) end end private + OVERRIDE_FIELDS_ON_FB_UPDATE = [:contact_id, :person_id, :request_id, :invitation_id, :photo_url, :name, :username] + def prevent_service_users_from_being_empty if self.service_users.blank? self.save_friends diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb index a0b00d5ca..92374536a 100644 --- a/spec/controllers/contacts_controller_spec.rb +++ b/spec/controllers/contacts_controller_spec.rb @@ -59,7 +59,7 @@ describe ContactsController do it 'will return the contacts for multiple aspects' do get :index, :aspect_ids => bob.aspect_ids, :format => 'json' - assigns[:people].should == bob.contacts.map(&:person) + assigns[:people].map(&:id).should =~ bob.contacts.map{|c| c.person.id} response.should be_success end @@ -73,7 +73,7 @@ describe ContactsController do aspect.contacts << bob.contact_for(eve.person) get :index, :format => 'json', :aspect_ids => bob.aspect_ids assigns[:people].map{|p| p.id}.uniq.should == assigns[:people].map{|p| p.id} - assigns[:people].should == bob.contacts.map(&:person) + assigns[:people].map(&:id).should =~ bob.contacts.map{|c| c.person.id} end end diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index a4ea66f3e..4e6d9315d 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -272,6 +272,7 @@ describe 'a user receives a post' do post_in_db.comments.should == [] receive_with_zord(bob, alice.person, @xml) + post_in_db.comments(true).first.author.should == remote_person end end diff --git a/spec/models/services/facebook_spec.rb b/spec/models/services/facebook_spec.rb index fcb1be916..fc6d59e73 100644 --- a/spec/models/services/facebook_spec.rb +++ b/spec/models/services/facebook_spec.rb @@ -69,12 +69,12 @@ JSON it 'attaches local models' do @service.save_friends - @service.service_users.first.person.should == @user2.person + @service.service_users.where(:uid => @user2_fb_id).first.person.should == @user2.person end it 'overwrites local model information' do @service.save_friends - su = @service.service_users.first + su = @service.service_users.where(:uid => @user2_fb_id).first su.person.should == @user2.person su.contact.should == nil