RS, DG; store_from_xml is gone, use user.receive

This commit is contained in:
Raphael 2010-08-11 15:05:05 -07:00
parent 5228e51262
commit c6a620c7dd
6 changed files with 66 additions and 51 deletions

View file

@ -25,7 +25,7 @@ class PublicsController < ApplicationController
def receive def receive
@user = Person.first(:id => params[:id]).owner @user = Person.first(:id => params[:id]).owner
Rails.logger.debug "PublicsController has received: #{params[:xml]}" Rails.logger.debug "PublicsController has received: #{params[:xml]}"
store_from_xml params[:xml], @user @user.receive params[:xml]
render :nothing => true render :nothing => true
end end

View file

@ -118,6 +118,25 @@ class User
save save
end end
###### Receiving #######
def receive xml
object = Diaspora::Parser.parse_from_xml(xml)
Rails.logger.debug("Receiving object:\n#{object.inspect}")
if object.is_a? Retraction
Rails.logger.debug "Got a retraction for #{object.post_id}"
object.perform
elsif object.is_a? Request
receive_friend_request(object)
elsif object.is_a? Profile
object.save
elsif object.respond_to?(:person) && !(object.person.nil?) && !(object.person.is_a? User)
Rails.logger.debug("Saving object with success: #{object.save}")
end
end
###Helpers############ ###Helpers############
def self.instantiate( opts = {} ) def self.instantiate( opts = {} )

View file

@ -29,6 +29,7 @@ module Diaspora
begin begin
object = body.name.camelize.constantize.from_xml body.to_s object = body.name.camelize.constantize.from_xml body.to_s
if object.is_a? Retraction if object.is_a? Retraction
elsif object.is_a? Profile elsif object.is_a? Profile
person = parse_owner_id_from_xml body person = parse_owner_id_from_xml body
@ -52,23 +53,5 @@ module Diaspora
end end
end end
def store_from_xml(xml, user)
object = parse_from_xml(xml)
Rails.logger.debug("Receiving object:\n#{object.inspect}")
if object.is_a? Retraction
Rails.logger.debug "Got a retraction for #{object.post_id}"
object.perform
elsif object.is_a? Request
user.receive_friend_request(object)
elsif object.is_a? Profile
object.save
elsif object.respond_to?(:person) && !(object.person.nil?) && !(object.person.is_a? User)
Rails.logger.debug("Saving object with success: #{object.save}")
end
end
end end
end end

View file

@ -15,7 +15,7 @@ describe Diaspora::Parser do
10.times { 10.times {
message = Factory.build(:status_message, :person => @user) message = Factory.build(:status_message, :person => @user)
xml = message.to_diaspora_xml xml = message.to_diaspora_xml
store_from_xml(xml, @user) @user.receive xml
} }
StatusMessage.count.should == 0 StatusMessage.count.should == 0
end end
@ -28,7 +28,7 @@ describe Diaspora::Parser do
<post><person></person></post> <post><person></person></post>
<post><status_message>\n <message>HEY DUDE</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post> <post><status_message>\n <message>HEY DUDE</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
</XML>" </XML>"
store_from_xml(xml, @user) @user.receive xml
Post.count.should == 0 Post.count.should == 0
end end
@ -38,7 +38,7 @@ describe Diaspora::Parser do
<post><person></person></post> <post><person></person></post>
</XML>" </XML>"
store_from_xml(xml, @user) @user.receive xml
Post.count.should == 0 Post.count.should == 0
end end
@ -73,7 +73,7 @@ describe Diaspora::Parser do
request = retraction.to_diaspora_xml request = retraction.to_diaspora_xml
StatusMessage.count.should == 1 StatusMessage.count.should == 1
store_from_xml( request, @user ) @user.receive request
StatusMessage.count.should == 0 StatusMessage.count.should == 0
end end
@ -85,7 +85,7 @@ describe Diaspora::Parser do
@person.destroy @person.destroy
Person.all.count.should be 1 Person.all.count.should be 1
store_from_xml(xml, @user) @user.receive xml
Person.all.count.should be 2 Person.all.count.should be 2
Person.first(:_id => original_person_id).serialized_key.include?("PUBLIC").should be true Person.first(:_id => original_person_id).serialized_key.include?("PUBLIC").should be true
@ -102,7 +102,7 @@ describe Diaspora::Parser do
Person.all.count.should be 3 Person.all.count.should be 3
store_from_xml(xml, @user) @user.receive xml
Person.all.count.should be 3 Person.all.count.should be 3
@user2.reload @user2.reload
@ -131,7 +131,7 @@ describe Diaspora::Parser do
@person.destroy @person.destroy
request_remote.destroy request_remote.destroy
store_from_xml(xml, @user) @user.receive xml
new_person = Person.first(:url => @person.url) new_person = Person.first(:url => @person.url)
new_person.nil?.should be false new_person.nil?.should be false
@ -145,7 +145,7 @@ describe Diaspora::Parser do
request = retraction.to_diaspora_xml request = retraction.to_diaspora_xml
Person.count.should == 2 Person.count.should == 2
store_from_xml( request , @user) @user.receive request
Person.count.should == 1 Person.count.should == 1
end end
@ -171,7 +171,7 @@ describe Diaspora::Parser do
old_profile.first_name.should == 'bob' old_profile.first_name.should == 'bob'
#Marshal profile #Marshal profile
store_from_xml xml, @user @user.receive xml
#Check that marshaled profile is the same as old profile #Check that marshaled profile is the same as old profile
person = Person.first(:id => person.id) person = Person.first(:id => person.id)

View file

@ -90,7 +90,7 @@ describe User do
it 'should befriend the user other user on the same pod' do it 'should befriend the user other user on the same pod' do
store_from_xml @req_three_xml, @user2 @user2.receive @req_three_xml
@user2.pending_requests.size.should be 1 @user2.pending_requests.size.should be 1
@user2.accept_friend_request @request_three.id @user2.accept_friend_request @request_three.id
@user2.friends.include?(@user.person).should be true @user2.friends.include?(@user.person).should be true
@ -99,7 +99,7 @@ describe User do
it 'should not delete the ignored user on the same pod' do it 'should not delete the ignored user on the same pod' do
store_from_xml @req_three_xml, @user2 @user2.receive @req_three_xml
@user2.pending_requests.size.should be 1 @user2.pending_requests.size.should be 1
@user2.ignore_friend_request @request_three.id @user2.ignore_friend_request @request_three.id
@user2.friends.include?(@user.person).should be false @user2.friends.include?(@user.person).should be false
@ -108,12 +108,12 @@ describe User do
it 'should both users should befriend the same person' do it 'should both users should befriend the same person' do
store_from_xml @req_xml, @user @user.receive @req_xml
@user.pending_requests.size.should be 1 @user.pending_requests.size.should be 1
@user.accept_friend_request @request.id @user.accept_friend_request @request.id
@user.friends.include?(@person_one).should be true @user.friends.include?(@person_one).should be true
store_from_xml @req_two_xml, @user2 @user2.receive @req_two_xml
@user2.pending_requests.size.should be 1 @user2.pending_requests.size.should be 1
@user2.accept_friend_request @request_two.id @user2.accept_friend_request @request_two.id
@user2.friends.include?(@person_one).should be true @user2.friends.include?(@person_one).should be true
@ -122,12 +122,12 @@ describe User do
it 'should keep the person around if one of the users rejects him' do it 'should keep the person around if one of the users rejects him' do
store_from_xml @req_xml, @user @user.receive @req_xml
@user.pending_requests.size.should be 1 @user.pending_requests.size.should be 1
@user.accept_friend_request @request.id @user.accept_friend_request @request.id
@user.friends.include?(@person_one).should be true @user.friends.include?(@person_one).should be true
store_from_xml @req_two_xml, @user2 @user2.receive @req_two_xml
@user2.pending_requests.size.should be 1 @user2.pending_requests.size.should be 1
@user2.ignore_friend_request @request_two.id @user2.ignore_friend_request @request_two.id
@user2.friends.include?(@person_one).should be false @user2.friends.include?(@person_one).should be false
@ -135,12 +135,12 @@ describe User do
end end
it 'should not keep the person around if the users ignores them' do it 'should not keep the person around if the users ignores them' do
store_from_xml @req_xml, @user @user.receive @req_xml
@user.pending_requests.size.should be 1 @user.pending_requests.size.should be 1
@user.ignore_friend_request @user.pending_requests.first.id @user.ignore_friend_request @user.pending_requests.first.id
@user.friends.include?(@person_one).should be false @user.friends.include?(@person_one).should be false
store_from_xml @req_two_xml, @user2 @user2.receive @req_two_xml
@user2.pending_requests.size.should be 1 @user2.pending_requests.size.should be 1
@user2.ignore_friend_request @user2.pending_requests.first.id#@request_two.id @user2.ignore_friend_request @user2.pending_requests.first.id#@request_two.id
@user2.friends.include?(@person_one).should be false @user2.friends.include?(@person_one).should be false
@ -184,23 +184,14 @@ describe User do
@user.friends.include?(@person_two).should be false @user.friends.include?(@person_two).should be false
end end
=begin
it 'should do accept reject for people not on the pod' do it 'should do accept reject for people not on the pod' do
@person_one.destroy
@person_two.destroy
end end
it 'should do accept reject for people on the pod' do it 'should do accept reject for people on the pod' do
end end
it 'should do accept reject for mixed people on the pod' do it 'should do accept reject for mixed people on the pod' do
@person_two.destroy
end end
=end
end end
end end
@ -217,4 +208,26 @@ describe User do
@user.profile.image_url.should == "http://clown.com" @user.profile.image_url.should == "http://clown.com"
end end
end end
describe 'receiving' do
before do
@user2 = Factory.create(:user)
@user.friends << @user2.person
@user2.friends << @user.person
@user.person.user_refs += 1
@user2.person.user_refs += 1
@user.save
@user2.save
end
it 'should be able to parse and store a status message from xml' do
status_message = @user2.post :status_message, :message => 'store this!'
xml = status_message.to_diaspora_xml
@user2.destroy
status_message.destroy
StatusMessage.all.size.should == 0
@user.receive( xml )
StatusMessage.all.size.should == 1
end
end
end end

View file

@ -54,7 +54,7 @@ describe 'user encryption' do
xml = request.to_diaspora_xml xml = request.to_diaspora_xml
person.destroy person.destroy
personcount = Person.all.count personcount = Person.all.count
store_from_xml(xml, @user) @user.receive xml
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
@ -113,7 +113,7 @@ describe 'user encryption' do
xml = message.to_diaspora_xml xml = message.to_diaspora_xml
message.destroy message.destroy
Post.count.should be 0 Post.count.should be 0
store_from_xml(xml, @user) @user.receive xml
Post.count.should be 0 Post.count.should be 0
end end