RS; figured out recursive serialization with ROXML, posts and comments now serialize with their persons

This commit is contained in:
Raphael 2010-06-30 08:06:30 -07:00
parent 6bc68fb42e
commit 340a57ea6d
6 changed files with 25 additions and 4 deletions

View file

@ -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

View file

@ -4,7 +4,8 @@ class Person
xml_accessor :email
xml_accessor :url
xml_accessor :profile, :as => Profile
key :email, String
key :url, String

View file

@ -6,6 +6,7 @@ class Post
include Diaspora::Webhooks
xml_accessor :_id
xml_accessor :person, :as => Person
key :person_id, ObjectId

View file

@ -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

View file

@ -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

View file

@ -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