diff --git a/app/models/profile.rb b/app/models/profile.rb index 8243268be..112e9d988 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -29,7 +29,7 @@ class Profile end def to_diaspora_xml - self.to_xml.to_s + ""+ self.to_xml.to_s + "" end end diff --git a/lib/diaspora/diaspora_parser.rb b/lib/diaspora/diaspora_parser.rb index 9220708e7..21b911e81 100644 --- a/lib/diaspora/diaspora_parser.rb +++ b/lib/diaspora/diaspora_parser.rb @@ -3,13 +3,18 @@ module Diaspora def parse_owner_from_xml(xml) doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } email = doc.xpath("//person/email").text.to_s - Person.where(:email => email).first + Person.first(:email => email) end def parse_body_contents_from_xml(xml) doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks } doc.xpath("/XML/posts/post") end + + def parse_owner_id_from_xml(doc) + id = doc.xpath("//person_id").text.to_s + Person.first(:id => id) + end def parse_objects_from_xml(xml) objects = [] @@ -17,8 +22,17 @@ module Diaspora body.children.each do |post| begin object = post.name.camelize.constantize.from_xml post.to_s - object.person = parse_owner_from_xml post.to_s if object.respond_to? :person - objects << object + if object.respond_to? :person + object.person = parse_owner_from_xml post.to_s + end + objects << object + #elsif object.is_a? Profile + # person = parse_owner_id_from_xml post + # profile_hash = Hash.from_xml(post.to_s) + # person.profile.update_attributes!(profile_hash) + #else + # object << object + #end rescue Rails.logger.info "Not a real type: #{object.to_s}" end @@ -31,6 +45,7 @@ module Diaspora objects.each do |p| Rails.logger.info("Receiving object:\n#{p.inspect}") if p.is_a? Retraction + puts "i am here" p.perform elsif p.is_a? Request User.owner.receive_friend_request(p) @@ -42,4 +57,4 @@ module Diaspora end end end -end \ No newline at end of file +end diff --git a/lib/diaspora/webhooks.rb b/lib/diaspora/webhooks.rb index c73530d11..084939e8a 100644 --- a/lib/diaspora/webhooks.rb +++ b/lib/diaspora/webhooks.rb @@ -1,4 +1,3 @@ - module Diaspora module Webhooks def self.included(klass) @@ -31,7 +30,7 @@ module Diaspora @@queue.add_hub_notification(APP_CONFIG[:pubsub_server], User.owner.url + self.class.to_s.pluralize.underscore + '.atom') unless recipients.empty? recipients.map!{|x| x = x.url + "receive/"} - xml = self.class.build_xml_for(self) + xml = Post.build_xml_for(self) Rails.logger.info("Adding xml for #{self} to message queue to #{recipients}") @@queue.add_post_request( recipients, xml ) end diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb index 337d5b862..a0906609b 100644 --- a/spec/lib/diaspora_parser_spec.rb +++ b/spec/lib/diaspora_parser_spec.rb @@ -151,8 +151,30 @@ describe Diaspora::DiasporaParser do Person.count.should == 2 store_objects_from_xml( request ) Person.count.should == 1 - end + + it 'should marshal a profile for a person' do + person = Factory.create(:person) + + person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com") + old_profile = person.profile + + puts person.profile.inspect + + xml = Post.build_xml_for(person.profile) + person.profile = nil + person.save + + puts person.profile.inspect + person.profile.should_be nil + store_objects_from_xml xml + + person = Person.first(:id => person.id) + + person.profile.should == old_profile + person.profile.should_not be nil + + end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b767db3b6..1c4f1cb74 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -65,15 +65,16 @@ describe User do @user = Factory.create(:user) p = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}} + n = Profile.send :class_variable_get, :@@queue + n.should_receive(:process) + @user.update_profile(p).should == true @user.profile.image_url.should == "http://clown.com" - Profile.should_receive(:build_xml_for) - - n = Profile.send :class_variable_get, :@@queue - n.should_receive(:process) + + end