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| respond_to do |format|
format.html 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 } format.json { render :json => @status_message }
end end
end end

View file

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

View file

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

View file

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

View file

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

View file

@ -43,9 +43,7 @@ describe Diaspora do
end end
it "should check that it does not send a person's post to an owners people" do 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) message_queue.should_not_receive(:add_post_request)
Post.should_not_receive(:build_xml_for)
Factory.create(:status_message, :person => Factory.create(:person)) Factory.create(:status_message, :person => Factory.create(:person))
end end
@ -58,15 +56,6 @@ describe Diaspora do
@post.people_with_permissions.size.should == 5 @post.people_with_permissions.size.should == 5
end 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
end end

View file

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