From 340a57ea6dc933e214b8662c4358282dd631836f Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Wed, 30 Jun 2010 08:06:30 -0700 Subject: [PATCH] RS; figured out recursive serialization with ROXML, posts and comments now serialize with their persons --- app/models/comment.rb | 2 +- app/models/person.rb | 3 ++- app/models/post.rb | 1 + app/models/profile.rb | 6 +++++- spec/models/person_spec.rb | 10 ++++++++++ spec/models/post_spec.rb | 7 ++++++- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 1029e4bc36..af10726bdc 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -2,7 +2,7 @@ class Comment include MongoMapper::Document include ROXML xml_accessor :text - + xml_accessor :person, :as => Person key :text, String key :target, String diff --git a/app/models/person.rb b/app/models/person.rb index 73161780ba..1e7dd0f2b2 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -4,7 +4,8 @@ class Person xml_accessor :email xml_accessor :url - + xml_accessor :profile, :as => Profile + key :email, String key :url, String diff --git a/app/models/post.rb b/app/models/post.rb index e5974f4c6d..5cd6795031 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -6,6 +6,7 @@ class Post include Diaspora::Webhooks xml_accessor :_id + xml_accessor :person, :as => Person key :person_id, ObjectId diff --git a/app/models/profile.rb b/app/models/profile.rb index 0e4e6c9138..13febaaf30 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1,6 +1,10 @@ class Profile include MongoMapper::Document - + include ROXML + + xml_accessor :first_name + xml_accessor :last_name + key :first_name, String key :last_name, String diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 97ed93418e..59ef0c21c5 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -13,4 +13,14 @@ describe Person do friend.valid?.should == false end + it 'should serialize to xml' do + friend_one = Factory.create(:friend) + xml = friend_one.to_xml.to_s + (xml.include? "friend").should == true + end + it 'should have a profile in its xml' do + user = Factory.create(:user) + xml = user.to_xml.to_s + (xml.include? "first_name").should == true + end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index b3df7552ff..93deadc990 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -77,6 +77,11 @@ describe Post do friend_posts.count.should == 2 end end - + describe 'xml' do + it 'should serialize to xml with its person' do + message = Factory.create(:status_message, :person => @user) + (message.to_xml.to_s.include? @user.email).should == true + end + end end -- GitLab