build_xml_for is no longer static, we should probably change the name

This commit is contained in:
Raphael 2010-08-11 13:58:18 -07:00
parent 599d1da620
commit 9c9ebbf4c7
7 changed files with 27 additions and 43 deletions

View file

@ -37,7 +37,7 @@ class StatusMessagesController < ApplicationController
respond_to do |format|
format.html
format.xml { render :xml => Post.build_xml_for(@status_message) }
format.xml { render :xml => @status_message.build_xml_for }
format.json { render :json => @status_message }
end
end

View file

@ -57,9 +57,7 @@ class Person
options[:person] = self
model_class = class_name.to_s.camelize.constantize
post = model_class.instantiate(options)
if owns?(post)
post.notify_people
end
post
end

View file

@ -19,7 +19,7 @@ module Diaspora
def push_to(recipients)
unless recipients.empty?
recipients.map!{|x| x = x.receive_url }
xml = Post.build_xml_for(self)
xml = build_xml_for
Rails.logger.debug("Adding xml for #{self} to message queue to #{recipients}")
@@queue.add_post_request( recipients, xml )
end
@ -28,7 +28,7 @@ module Diaspora
def push_to_url(url)
hook_url = url
xml = self.class.build_xml_for(self)
xml = build_xml_for
Rails.logger.debug("Adding xml for #{self} to message queue to #{url}")
@@queue.add_post_request( hook_url, xml )
@@queue.process
@ -49,10 +49,10 @@ module Diaspora
end
end
def self.build_xml_for(posts)
def build_xml_for
xml = "<XML>"
xml += "\n <posts>"
[*posts].each {|x| xml << x.to_diaspora_xml}
xml << to_diaspora_xml
xml += "</posts>"
xml += "</XML>"

View file

@ -21,7 +21,7 @@ describe PublicsController do
person = Factory.create(:person)
message = StatusMessage.new(:message => 'foo', :person => person)
StatusMessage.all.count.should be 0
post :receive, :id => @user.person.id, :xml => Post.build_xml_for(message)
post :receive, :id => @user.person.id, :xml => message.build_xml_for(message)
StatusMessage.all.count.should be 1
end
end
@ -33,7 +33,7 @@ describe PublicsController do
@user2.person.save
req = Request.instantiate(:from => @user2.person, :to => @user.person.url)
@xml = Request.build_xml_for [req]
@xml = req.build_xml_for
req.delete
end

View file

@ -12,10 +12,11 @@ describe Diaspora::Parser do
end
it "should not store posts from me" do
status_messages = []
10.times { status_messages << Factory.build(:status_message, :person => @user)}
xml = Post.build_xml_for(status_messages)
10.times {
message = Factory.build(:status_message, :person => @user)
xml = message.build_xml_for
store_objects_from_xml(xml, @user)
}
StatusMessage.count.should == 0
end
@ -65,15 +66,11 @@ describe Diaspora::Parser do
describe "parsing compliant XML object" do
before do
@status_messages = []
10.times { @status_messages << Factory.build(:status_message)}
@xml = Post.build_xml_for(@status_messages)
@xml = Factory.build(:status_message).build_xml_for
end
it 'should be able to parse the body\'s contents' do
body = parse_body_contents_from_xml(@xml).to_s
body.should_not include "<head>"
body.should_not include "</head>"
body.should_not include "<posts>"
body.should_not include "</posts>"
body.should include "<post>"
@ -83,7 +80,7 @@ describe Diaspora::Parser do
it 'should be able to extract all posts to an array' do
posts = parse_objects_from_xml(@xml)
posts.is_a?(Array).should be true
posts.count.should == 10
posts.count.should == 1
end
it 'should be able to correctly handle comments' do
@ -106,7 +103,7 @@ describe Diaspora::Parser do
person = Factory.create(:person)
message = Factory.create(:status_message, :person => person)
retraction = Retraction.for(message)
request = Post.build_xml_for( [retraction] )
request = retraction.build_xml_for
StatusMessage.count.should == 1
store_objects_from_xml( request, @user )
@ -117,7 +114,7 @@ describe Diaspora::Parser do
request = Request.instantiate(:to =>"http://www.google.com/", :from => @person)
original_person_id = @person.id
xml = Request.build_xml_for [request]
xml = request.build_xml_for
@person.destroy
Person.all.count.should be 1
@ -134,7 +131,7 @@ describe Diaspora::Parser do
request = Request.instantiate(:to =>"http://www.google.com/", :from => @user2.person)
original_person_id = @user2.person.id
xml = Request.build_xml_for [request]
xml = request.build_xml_for
Person.all.count.should be 3
@ -163,7 +160,7 @@ describe Diaspora::Parser do
request_remote.person = @person
request_remote.exported_key = @person.export_key
xml = Request.build_xml_for [request_remote]
xml = request_remote.build_xml_for
@person.destroy
request_remote.destroy
@ -178,7 +175,7 @@ describe Diaspora::Parser do
it 'should process retraction for a person' do
retraction = Retraction.for(@user)
request = Retraction.build_xml_for( [retraction] )
request = retraction.build_xml_for
Person.count.should == 2
store_objects_from_xml( request , @user)
@ -197,7 +194,7 @@ describe Diaspora::Parser do
old_profile.first_name.should == 'bob'
#Build xml for profile, clear profile
xml = Post.build_xml_for(person.profile)
xml = person.profile.build_xml_for
reloaded_person = Person.first(:id => id)
reloaded_person.profile = nil
reloaded_person.save(:validate => false)

View file

@ -43,9 +43,7 @@ describe Diaspora do
end
it "should check that it does not send a person's post to an owners people" do
Post.stub(:build_xml_for).and_return(true)
Post.should_not_receive(:build_xml_for)
message_queue.should_not_receive(:add_post_request)
Factory.create(:status_message, :person => Factory.create(:person))
end
@ -58,15 +56,6 @@ describe Diaspora do
@post.people_with_permissions.size.should == 5
end
it "should build an xml object containing multiple Post types" do
Factory.create(:status_message)
Factory.create(:bookmark)
stream = Post.stream
xml = Post.build_xml_for(stream)
xml.should include "<status_message>"
xml.should include "<bookmark>"
end
end
end

View file

@ -39,7 +39,7 @@ describe 'user encryption' do
it 'should send over a public key' do
message_queue.stub!(:add_post_request)
request = @user.send_friend_request_to("http://example.com/")
Request.build_xml_for([request]).include?( @user.export_key).should be true
request.build_xml_for.include?( @user.export_key).should be true
end
it 'should receive and marshal a public key from a request' do
@ -51,10 +51,10 @@ describe 'user encryption' do
request = Request.instantiate(:to =>"http://www.google.com/", :from => person)
xml = Request.build_xml_for [request]
xml = request.build_xml_for
person.destroy
personcount = Person.all.count
store_objects_from_xml(xml)
store_objects_from_xml(xml, @user)
Person.all.count.should == personcount + 1
new_person = Person.first(:url => "http://test.url/")
new_person.id.should == id
@ -110,10 +110,10 @@ describe 'user encryption' do
message = Factory.build(:status_message, :person => @person)
message.creator_signature = "totally valid"
message.save
xml = Post.build_xml_for([message])
xml = message.build_xml_for
message.destroy
Post.count.should be 0
store_objects_from_xml(xml)
store_objects_from_xml(xml, @user)
Post.count.should be 0
end