diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb
index 8cc73bac1..f941389a5 100644
--- a/app/controllers/status_messages_controller.rb
+++ b/app/controllers/status_messages_controller.rb
@@ -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
diff --git a/app/models/person.rb b/app/models/person.rb
index ad3991959..75e261496 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -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.notify_people
post
end
diff --git a/lib/diaspora/webhooks.rb b/lib/diaspora/webhooks.rb
index 959010e61..6d88ad8c2 100644
--- a/lib/diaspora/webhooks.rb
+++ b/lib/diaspora/webhooks.rb
@@ -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 += "\n "
- [*posts].each {|x| xml << x.to_diaspora_xml}
+ xml << to_diaspora_xml
xml += ""
xml += ""
diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb
index 976d8900c..fedc031ae 100644
--- a/spec/controllers/publics_controller_spec.rb
+++ b/spec/controllers/publics_controller_spec.rb
@@ -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
diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb
index 4ec4815c7..17bc556f4 100644
--- a/spec/lib/diaspora_parser_spec.rb
+++ b/spec/lib/diaspora_parser_spec.rb
@@ -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)
- store_objects_from_xml(xml, @user)
+ 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 "
"
- body.should_not include ""
body.should_not include ""
body.should_not include ""
body.should include ""
@@ -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)
diff --git a/spec/lib/web_hooks_spec.rb b/spec/lib/web_hooks_spec.rb
index 32a8d4cb0..ba62d5ebe 100644
--- a/spec/lib/web_hooks_spec.rb
+++ b/spec/lib/web_hooks_spec.rb
@@ -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 ""
- xml.should include ""
- end
end
end
diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb
index 2c7b8963b..b4a63fc98 100644
--- a/spec/user_encryption_spec.rb
+++ b/spec/user_encryption_spec.rb
@@ -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