diff --git a/app/models/profile.rb b/app/models/profile.rb index 709cb77448334727258e3586600bac5252b4c748..551d16acf5795d60ad589586e3c64ab154c09eeb 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -36,9 +36,10 @@ class Profile < ActiveRecord::Base end def receive(user, person) - person.profile = self - person.save - self + Rails.logger.info("event=receive payload_type=profile sender=#{person} to=#{user}") + person.profile.update_attributes self.attributes + + person.profile end def diaspora_handle diff --git a/spec/intergration/receiving_spec.rb b/spec/intergration/receiving_spec.rb index d4fa78a7e34ac8a7a2753d279321365ee7a2b88d..ba2fec44aeb0fd0e3c259fea7fdd8c7476bc5eac 100644 --- a/spec/intergration/receiving_spec.rb +++ b/spec/intergration/receiving_spec.rb @@ -272,4 +272,80 @@ describe 'a user receives a post' do @user2.raw_visible_posts.include?(post).should be_true end end + + + context 'retractions' do + it 'should accept retractions' do + message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id) + retraction = Retraction.for(message) + xml = retraction.to_diaspora_xml + + lambda { + zord = Postzord::Receiver.new(@user1, :person => @user2.person) + zord.parse_and_receive(xml) + }.should change(StatusMessage, :count).by(-1) + end + + it "should activate the Person if I initiated a request to that url" do + begin + @user1.send_contact_request_to(@user3.person, @aspect) + rescue Exception => e + raise e.original_exception + end + request = @user3.request_from(@user1.person) + fantasy_resque do + @user3.accept_and_respond(request.id, @aspect3.id) + end + @user1.reload + @aspect.reload + new_contact = @user1.contact_for(@user3.person) + @aspect.contacts.include?(new_contact).should be true + @user1.contacts.include?(new_contact).should be true + end + + it 'should process retraction for a person' do + retraction = Retraction.for(@user2) + retraction_xml = retraction.to_diaspora_xml + + lambda { + zord = Postzord::Receiver.new(@user1, :person => @user2.person) + zord.parse_and_receive(retraction_xml) + }.should change { + @aspect.contacts(true).size }.by(-1) + end + + end + + it 'should marshal a profile for a person' do + #Create person + person = @user2.person + id = person.id + person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com") + person.save + + #Cache profile for checking against marshaled profile + old_profile = person.profile.dup + old_profile.first_name.should == 'bob' + + #Build xml for profile, clear profile + xml = person.profile.to_diaspora_xml + reloaded_person = Person.find(id) + reloaded_person.profile.delete + reloaded_person.save(:validate => false) + + #Make sure profile is cleared + Person.find(id).profile.should be nil + old_profile.first_name.should == 'bob' + + #Marshal profile + zord = Postzord::Receiver.new(@user1, :person => person) + zord.parse_and_receive(xml) + + #Check that marshaled profile is the same as old profile + person = Person.find(person.id) + person.profile.should_not be nil + person.profile.first_name.should == old_profile.first_name + person.profile.last_name.should == old_profile.last_name + person.profile.image_url.should == old_profile.image_url + end end diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index 74390c5a3d08d94d8623cc19b50468305b372eb2..5645726dc68b9bceeabcd0a7591a354e2cc73c15 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -29,78 +29,6 @@ describe Diaspora::Parser do comment_from_xml.text.should == "Freedom!" comment_from_xml.should_not be comment end - - it 'should accept retractions' do - message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id) - retraction = Retraction.for(message) - xml = retraction.to_diaspora_xml - - lambda { - zord = Postzord::Receiver.new(@user1, :person => @user2.person) - zord.parse_and_receive(xml) - }.should change(StatusMessage, :count).by(-1) - end - - it "should activate the Person if I initiated a request to that url" do - begin - @user1.send_contact_request_to(@user3.person, @aspect1) - rescue Exception => e - raise e.original_exception - end - request = @user3.request_from(@user1.person) - fantasy_resque do - @user3.accept_and_respond(request.id, @aspect3.id) - end - @user1.reload - @aspect1.reload - new_contact = @user1.contact_for(@user3.person) - @aspect1.contacts.include?(new_contact).should be true - @user1.contacts.include?(new_contact).should be true - end - - it 'should process retraction for a person' do - retraction = Retraction.for(@user2) - retraction_xml = retraction.to_diaspora_xml - - lambda { - zord = Postzord::Receiver.new(@user1, :person => @user2.person) - zord.parse_and_receive(retraction_xml) - }.should change { - @aspect1.contacts(true).size }.by(-1) - end - - it 'should marshal a profile for a person' do - #Create person - person = @user2.person - id = person.id - person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com") - person.save - - #Cache profile for checking against marshaled profile - old_profile = person.profile.dup - old_profile.first_name.should == 'bob' - - #Build xml for profile, clear profile - xml = person.profile.to_diaspora_xml - reloaded_person = Person.find(id) - reloaded_person.profile.delete - reloaded_person.save(:validate => false) - - #Make sure profile is cleared - Person.find(id).profile.should be nil - old_profile.first_name.should == 'bob' - - #Marshal profile - zord = Postzord::Receiver.new(@user1, :person => person) - zord.parse_and_receive(xml) - - #Check that marshaled profile is the same as old profile - person = Person.find(person.id) - person.profile.should_not be nil - person.profile.first_name.should == old_profile.first_name - person.profile.last_name.should == old_profile.last_name - person.profile.image_url.should == old_profile.image_url - end end end diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index d094b476df828aa46a2d46ccd40cff6092f506f9..c7ebb1eab44a73aba10cd772f392889ab7269661 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -146,4 +146,16 @@ describe Profile do end end + describe '#receive' do + + it 'updates the profile in place' do + local_luke, local_leia, remote_raphael = set_up_friends + new_profile = Factory.build :profile + lambda{ + new_profile.receive(local_leia, remote_raphael) + }.should_not change(Profile, :count) + remote_raphael.last_name.should == new_profile.last_name + end + + end end