DG MS; end of day.
This commit is contained in:
parent
b2f3074eb0
commit
948c5d9b02
3 changed files with 151 additions and 20 deletions
|
|
@ -14,36 +14,45 @@ module Diaspora
|
||||||
module XML
|
module XML
|
||||||
def execute(user)
|
def execute(user)
|
||||||
builder = Nokogiri::XML::Builder.new do |xml|
|
builder = Nokogiri::XML::Builder.new do |xml|
|
||||||
xml.user {
|
xml.export {
|
||||||
xml.username user.username
|
xml.user {
|
||||||
xml.parent << user.person.to_xml
|
xml.username user.username
|
||||||
xml.serialized_private_key user.serialized_private_key
|
xml.serialized_private_key user.serialized_private_key
|
||||||
|
|
||||||
|
xml.parent << user.person.to_xml
|
||||||
|
}
|
||||||
xml.aspects {
|
xml.aspects {
|
||||||
user.aspects.each do |aspect|
|
user.aspects.each do |aspect|
|
||||||
|
puts aspect.people.inspect
|
||||||
xml.aspect {
|
xml.aspect {
|
||||||
xml.id_ aspect.id
|
xml._id aspect.id
|
||||||
xml.name aspect.name
|
xml.name aspect.name
|
||||||
|
|
||||||
xml.people {
|
xml.person_ids {
|
||||||
aspect.people.each do |person|
|
aspect.people.each do |person|
|
||||||
xml.person person.to_xml
|
xml.person_id person.id
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
xml.posts {
|
|
||||||
aspect.posts.find_all_by_person_id(user.person.id).each do |post|
|
|
||||||
post_doc = post.to_xml
|
|
||||||
|
|
||||||
post.comments.each do |comment|
|
|
||||||
post_doc << comment.to_xml
|
|
||||||
end
|
|
||||||
|
|
||||||
xml.post post_doc
|
xml.post_ids {
|
||||||
|
aspect.posts.each do |post|
|
||||||
|
xml.post_id post.id
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
xml.posts {
|
||||||
|
user.raw_visible_posts.find_all_by_person_id(user.person.id).each do |post|
|
||||||
|
#post_doc = post.to_xml
|
||||||
|
|
||||||
|
#post.comments.each do |comment|
|
||||||
|
# post_doc << comment.to_xml
|
||||||
|
#end
|
||||||
|
|
||||||
|
xml.post post.to_xml
|
||||||
|
end
|
||||||
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,54 @@ module Diaspora
|
||||||
|
|
||||||
module Importers
|
module Importers
|
||||||
module XML
|
module XML
|
||||||
def execute(user)
|
def execute(xml)
|
||||||
|
doc = Nokogiri::XML.parse(xml)
|
||||||
|
user, person = parse_user(doc)
|
||||||
|
user
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_user(doc)
|
||||||
|
user = User.new
|
||||||
|
user_doc = doc.xpath('/export/user')
|
||||||
|
user.username = user_doc.xpath('//user/username').text
|
||||||
|
user.serialized_private_key= user_doc.xpath('//user/serialized_private_key').text
|
||||||
|
person = Person.from_xml(user_doc.xpath('//user/person').to_s)
|
||||||
|
[user, person]
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_aspects(doc)
|
||||||
|
aspects = []
|
||||||
|
aspect_doc = doc.xpath('/export/aspects/aspect')
|
||||||
|
|
||||||
|
aspect_doc.each do |x|
|
||||||
|
|
||||||
|
puts x.to_s
|
||||||
|
puts; puts
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
aspects << aspect
|
||||||
|
end
|
||||||
|
|
||||||
|
aspects
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_people(doc)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def parse_posts(doc)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ describe Diaspora::Importer do
|
||||||
let!(:aspect6) { user3.aspect(:name => "Cats") }
|
let!(:aspect6) { user3.aspect(:name => "Cats") }
|
||||||
let!(:aspect7) { user4.aspect(:name => "Dogs") }
|
let!(:aspect7) { user4.aspect(:name => "Dogs") }
|
||||||
let!(:aspect8) { user5.aspect(:name => "Hamsters") }
|
let!(:aspect8) { user5.aspect(:name => "Hamsters") }
|
||||||
|
let!(:aspect9) { user5.aspect(:name => "Gophers") }
|
||||||
|
|
||||||
# User1 posts one status messages to aspects (1-4), two other users post message to one aspect
|
# User1 posts one status messages to aspects (1-4), two other users post message to one aspect
|
||||||
let(:status_message1) { user1.post(:status_message, :message => "One", :public => true, :to => aspect1.id) }
|
let(:status_message1) { user1.post(:status_message, :message => "One", :public => true, :to => aspect1.id) }
|
||||||
|
|
@ -36,21 +37,28 @@ describe Diaspora::Importer do
|
||||||
let(:status_message4) { user1.post(:status_message, :message => "Four", :public => false, :to => aspect4.id) }
|
let(:status_message4) { user1.post(:status_message, :message => "Four", :public => false, :to => aspect4.id) }
|
||||||
let(:status_message5) { user2.post(:status_message, :message => "Five", :public => false, :to => aspect5.id) }
|
let(:status_message5) { user2.post(:status_message, :message => "Five", :public => false, :to => aspect5.id) }
|
||||||
let(:status_message6) { user3.post(:status_message, :message => "Six", :public => false, :to => aspect6.id) }
|
let(:status_message6) { user3.post(:status_message, :message => "Six", :public => false, :to => aspect6.id) }
|
||||||
|
let(:status_message7) { user5.post(:status_message, :message => "Seven", :public => false, :to => aspect9.id) }
|
||||||
|
|
||||||
before(:all) do
|
before(:all) do
|
||||||
# Friend users
|
# Friend users with user1
|
||||||
friend_users( user1, aspect1, user2, aspect5 )
|
friend_users( user1, aspect1, user2, aspect5 )
|
||||||
friend_users( user1, aspect2, user3, aspect6 )
|
friend_users( user1, aspect2, user3, aspect6 )
|
||||||
friend_users( user1, aspect3, user4, aspect7 )
|
friend_users( user1, aspect3, user4, aspect7 )
|
||||||
friend_users( user1, aspect4, user5, aspect8 )
|
friend_users( user1, aspect4, user5, aspect8 )
|
||||||
|
|
||||||
# Generate status messages and receive
|
# Friend users 4 and 5
|
||||||
|
friend_users( user5, aspect9, user4, aspect7 )
|
||||||
|
|
||||||
|
# Generate status messages and receive for user1
|
||||||
user2.receive status_message1.to_diaspora_xml
|
user2.receive status_message1.to_diaspora_xml
|
||||||
user3.receive status_message2.to_diaspora_xml
|
user3.receive status_message2.to_diaspora_xml
|
||||||
user4.receive status_message3.to_diaspora_xml
|
user4.receive status_message3.to_diaspora_xml
|
||||||
user5.receive status_message4.to_diaspora_xml
|
user5.receive status_message4.to_diaspora_xml
|
||||||
user1.receive status_message5.to_diaspora_xml
|
user1.receive status_message5.to_diaspora_xml
|
||||||
user1.receive status_message6.to_diaspora_xml
|
user1.receive status_message6.to_diaspora_xml
|
||||||
|
|
||||||
|
# Generate status message and recieve between user4 and user5
|
||||||
|
user4.receive status_message7.to_diaspora_xml
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should gut check this test' do
|
it 'should gut check this test' do
|
||||||
|
|
@ -67,6 +75,75 @@ describe Diaspora::Importer do
|
||||||
|
|
||||||
user1.raw_visible_posts.count.should be 6
|
user1.raw_visible_posts.count.should be 6
|
||||||
user1.raw_visible_posts.find_all_by_person_id(user1.person.id).count.should be 4
|
user1.raw_visible_posts.find_all_by_person_id(user1.person.id).count.should be 4
|
||||||
|
user1.raw_visible_posts.find_all_by_person_id(user1.person.id).should_not include status_message7
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'importing a user' do
|
||||||
|
|
||||||
|
before(:all) 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
|
||||||
|
before do
|
||||||
|
@user, @person = @importer.parse_user(@doc)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should set username' do
|
||||||
|
@user.username.should == @old_user.username
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should set private key' do
|
||||||
|
@user.serialized_private_key.should == @old_user.serialized_private_key
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should ensure a match between persons public and private keys' do
|
||||||
|
pending
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#parse_aspects' do
|
||||||
|
before do
|
||||||
|
@aspects = @importer.parse_aspects(@doc)
|
||||||
|
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
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#parse_posts' do
|
||||||
|
it 'should have a users personal posts' do
|
||||||
|
pending
|
||||||
|
@user.raw_visible_posts.find_all_by_person_id(user1.person.id).count.should be 4
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue