RS, DG; build_xml_for has been eliminated.

This commit is contained in:
Raphael 2010-08-11 14:21:53 -07:00
parent e94faf89bb
commit 5abd604dad
8 changed files with 26 additions and 35 deletions

View file

@ -23,9 +23,4 @@ class Profile
def person
Person.first(:id => self.person_id)
end
def to_diaspora_xml
"<post>"+ self.to_xml.to_s + "</post>"
end
end

View file

@ -48,6 +48,7 @@ module Diaspora
rescue NameError => e
if e.message.include? 'wrong constant name'
Rails.logger.info "Not a real type: #{object.to_s}"
raise e
else
raise e
end

View file

@ -19,7 +19,7 @@ module Diaspora
def push_to(recipients)
unless recipients.empty?
recipients.map!{|x| x = x.receive_url }
xml = build_xml_for
xml = to_diaspora_xml
Rails.logger.debug("Adding xml for #{self} to message queue to #{recipients}")
@@queue.add_post_request( recipients, xml )
end
@ -28,14 +28,18 @@ module Diaspora
def push_to_url(url)
hook_url = url
xml = build_xml_for
xml = to_diaspora_xml
Rails.logger.debug("Adding xml for #{self} to message queue to #{url}")
@@queue.add_post_request( hook_url, xml )
@@queue.process
end
def to_diaspora_xml
"<post>#{self.to_xml.to_s}</post>"
xml = "<XML>"
xml += "<posts>"
xml += "<post>#{self.to_xml.to_s}</post>"
xml += "</posts>"
xml += "</XML>"
end
def people_with_permissions
@ -48,15 +52,6 @@ module Diaspora
[]
end
end
def build_xml_for
xml = "<XML>"
xml += "\n <posts>"
xml << to_diaspora_xml
xml += "</posts>"
xml += "</XML>"
end
end
end
end

View file

@ -20,7 +20,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 => message.build_xml_for(message)
post :receive, :id => @user.person.id, :xml => message.to_diaspora_xml(message)
StatusMessage.all.count.should be 1
end
end
@ -37,7 +37,7 @@ describe PublicsController do
req = @user2.send_friend_request_to(@user.person.url)
#req = Request.instantiate(:from => @user2.person, :to => @user.person.url)
@xml = req.build_xml_for
@xml = req.to_diaspora_xml
req.delete
@user2.reload

View file

@ -14,7 +14,7 @@ describe Diaspora::Parser do
it "should not store posts from me" do
10.times {
message = Factory.build(:status_message, :person => @user)
xml = message.build_xml_for
xml = message.to_diaspora_xml
store_objects_from_xml(xml, @user)
}
StatusMessage.count.should == 0
@ -66,7 +66,7 @@ describe Diaspora::Parser do
describe "parsing compliant XML object" do
before do
@xml = Factory.build(:status_message).build_xml_for
@xml = Factory.build(:status_message).to_diaspora_xml
end
it 'should be able to parse the body\'s contents' do
@ -103,7 +103,7 @@ describe Diaspora::Parser do
person = Factory.create(:person)
message = Factory.create(:status_message, :person => person)
retraction = Retraction.for(message)
request = retraction.build_xml_for
request = retraction.to_diaspora_xml
StatusMessage.count.should == 1
store_objects_from_xml( request, @user )
@ -114,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
xml = request.to_diaspora_xml
@person.destroy
Person.all.count.should be 1
@ -131,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
xml = request.to_diaspora_xml
Person.all.count.should be 3
@ -160,7 +160,7 @@ describe Diaspora::Parser do
request_remote.person = @person
request_remote.exported_key = @person.export_key
xml = request_remote.build_xml_for
xml = request_remote.to_diaspora_xml
@person.destroy
request_remote.destroy
@ -175,7 +175,7 @@ describe Diaspora::Parser do
it 'should process retraction for a person' do
retraction = Retraction.for(@user)
request = retraction.build_xml_for
request = retraction.to_diaspora_xml
Person.count.should == 2
store_objects_from_xml( request , @user)
@ -194,7 +194,7 @@ describe Diaspora::Parser do
old_profile.first_name.should == 'bob'
#Build xml for profile, clear profile
xml = person.profile.build_xml_for
xml = person.profile.to_diaspora_xml
reloaded_person = Person.first(:id => id)
reloaded_person.profile = nil
reloaded_person.save(:validate => false)
@ -209,7 +209,7 @@ describe Diaspora::Parser do
#Check that marshaled profile is the same as old profile
person = Person.first(:id => person.id)
person.profile.should_not be nil
person.profile.first_name.should == old_profile.first_name
person.profile.first_name.should == old_profile.first_name
person.profile.last_name.should == old_profile.last_name
person.profile.image_url.should == old_profile.image_url
end

View file

@ -23,7 +23,7 @@ describe Diaspora do
end
it "should convert an object to a proper diaspora entry" do
@post.to_diaspora_xml.should == "<post>#{@post.to_xml.to_s}</post>"
@post.to_diaspora_xml.should == "<XML><posts><post>#{@post.to_xml.to_s}</post></posts></XML>"
end
it "should retrieve all valid person endpoints" do

View file

@ -78,9 +78,9 @@ describe User do
@request_three = Request.instantiate(:to => @user2.receive_url, :from => @user.person)
@req_xml = @request.build_xml_for
@req_two_xml = @request_two.build_xml_for
@req_three_xml = @request_three.build_xml_for
@req_xml = @request.to_diaspora_xml
@req_two_xml = @request_two.to_diaspora_xml
@req_three_xml = @request_three.to_diaspora_xml
@request.destroy

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.include?( @user.export_key).should be true
request.to_diaspora_xml.include?( @user.export_key).should be true
end
it 'should receive and marshal a public key from a request' do
@ -51,7 +51,7 @@ describe 'user encryption' do
request = Request.instantiate(:to =>"http://www.google.com/", :from => person)
xml = request.build_xml_for
xml = request.to_diaspora_xml
person.destroy
personcount = Person.all.count
store_objects_from_xml(xml, @user)
@ -110,7 +110,7 @@ describe 'user encryption' do
message = Factory.build(:status_message, :person => @person)
message.creator_signature = "totally valid"
message.save
xml = message.build_xml_for
xml = message.to_diaspora_xml
message.destroy
Post.count.should be 0
store_objects_from_xml(xml, @user)