diff --git a/lib/diaspora/exporter.rb b/lib/diaspora/exporter.rb index c6971348f..c5bf48665 100644 --- a/lib/diaspora/exporter.rb +++ b/lib/diaspora/exporter.rb @@ -23,25 +23,31 @@ module Diaspora } xml.aspects { user.aspects.each do |aspect| - puts aspect.people.inspect xml.aspect { xml._id aspect.id xml.name aspect.name xml.person_ids { - aspect.people.each do |person| - xml.person_id person.id + aspect.person_ids.each do |id| + xml.person_id id end } xml.post_ids { - aspect.posts.each do |post| - xml.post_id post.id + aspect.post_ids.each do |id| + xml.post_id id end } } end } + + xml.people { + user.friends.each do |friend| + xml.parent << friend.to_xml + end + } + xml.posts { user.raw_visible_posts.find_all_by_person_id(user.person.id).each do |post| #post_doc = post.to_xml @@ -50,7 +56,7 @@ module Diaspora # post_doc << comment.to_xml #end - xml.post post.to_xml + xml.parent << post.to_xml end } } diff --git a/lib/diaspora/importer.rb b/lib/diaspora/importer.rb index b214d8007..65d95fdc4 100644 --- a/lib/diaspora/importer.rb +++ b/lib/diaspora/importer.rb @@ -16,8 +16,6 @@ module Diaspora doc = Nokogiri::XML.parse(xml) user, person = parse_user(doc) user - - end @@ -31,29 +29,27 @@ module Diaspora end def parse_aspects(doc) - aspects = [] + aspects = [] aspect_doc = doc.xpath('/export/aspects/aspect') aspect_doc.each do |x| - - puts x.to_s - puts; puts - - + a = Nokogiri::XML.parse(x.to_s) + aspect = Aspect.new - - aspect.id = x.xpath('//aspect/_id').text - aspect.name = x.xpath('//aspect/name').text - - aspect.post_ids = x.xpath('//aspect/post_ids/post_id').collect(&:text) + aspect.id = a.xpath('/aspect/_id').text + aspect.name = a.xpath('/aspect/name').text + aspect.post_ids = a.xpath('/aspect/post_ids/post_id').collect(&:text) + aspect.person_ids = a.xpath('/aspect/person_ids/person_id').collect(&:text) aspects << aspect end - aspects - end def parse_people(doc) + people_doc = doc.xpath('/export/people/person') + people_doc.inject([]) do |people,curr| + people << Person.from_xml(curr.to_s) + end end diff --git a/spec/lib/exporter_spec.rb b/spec/lib/exporter_spec.rb index fb3e6d29f..0d882bab7 100644 --- a/spec/lib/exporter_spec.rb +++ b/spec/lib/exporter_spec.rb @@ -20,14 +20,24 @@ describe Diaspora::Exporter do let!(:exported) { Diaspora::Exporter.new(Diaspora::Exporters::XML).execute(user1) } it 'should include a users posts' do - exported.should include status_message1.to_xml.to_s - exported.should include status_message2.to_xml.to_s - exported.should_not include status_message3.to_xml.to_s + exported.should include status_message1.message + exported.should include status_message2.message + exported.should_not include status_message3.message end it 'should include a users private key' do exported.should include user1.serialized_private_key end -end + it 'should include post_ids' do + doc = Nokogiri::XML::parse(exported) + doc.xpath('//aspects').to_s.should include status_message1.id.to_s + doc.xpath('//posts').to_s.should include status_message1.id.to_s + end + it 'should include a list of users posts' do + doc = Nokogiri::XML::parse(exported) + posts = doc.xpath('//posts').to_s + posts.should include(status_message1.message) + end +end diff --git a/spec/lib/importer_spec.rb b/spec/lib/importer_spec.rb index d6d067243..df8474813 100644 --- a/spec/lib/importer_spec.rb +++ b/spec/lib/importer_spec.rb @@ -84,22 +84,21 @@ describe Diaspora::Importer do # Generate exported XML for user1 exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML) @xml = exporter.execute(user1) + @old_user = user1 @old_aspects = user1.aspects # Remove user1 from the server user1.aspects.each( &:delete ) user1.raw_visible_posts.find_all_by_person_id(user1.person.id).each( &:delete ) user1.delete - + @importer = Diaspora::Importer.new(Diaspora::Importers::XML) @doc = Nokogiri::XML::parse(@xml) end it 'should import a user' do user = @importer.execute(@xml) - user.class.should == User - end describe '#parse_user' do @@ -112,6 +111,7 @@ describe Diaspora::Importer do end it 'should set private key' do + @user.serialized_private_key.should_not be nil @user.serialized_private_key.should == @old_user.serialized_private_key end @@ -125,17 +125,39 @@ describe Diaspora::Importer do @aspects = @importer.parse_aspects(@doc) end + it 'should return valid aspects' do + @aspects.all?(&:valid?).should be true + end + it 'should return an array' do @aspects.count.should == 6 end it 'should should have post ids' do - puts @aspects.inspect @aspects.any?{|x| x.post_ids.count > 0}.should be true end + it 'should have person ids' do + @aspects.any?{|x| x.person_ids.count > 0}.should be true + end end + describe '#parse_people' do + before do + @people = @importer.parse_people(@doc) + end + + it 'should return valid people' do + @people.all?(&:valid?).should be true + end + + it 'should return an array' do + @people.count.should == 4 + end + end + + + describe '#parse_posts' do it 'should have a users personal posts' do pending