diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb
index eac2540ac..d6182a6eb 100644
--- a/app/controllers/publics_controller.rb
+++ b/app/controllers/publics_controller.rb
@@ -25,7 +25,7 @@ class PublicsController < ApplicationController
def receive
@user = Person.first(:id => params[:id]).owner
Rails.logger.debug "PublicsController has received: #{params[:xml]}"
- store_from_xml params[:xml], @user
+ @user.receive params[:xml]
render :nothing => true
end
diff --git a/app/models/user.rb b/app/models/user.rb
index d40ab77a0..2e82b0904 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -113,12 +113,31 @@ class User
end
end
- def activate_friend (person)
+ def activate_friend(person)
friends << person
save
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############
def self.instantiate( opts = {} )
opts[:person][:email] = opts[:email]
diff --git a/lib/diaspora/parser.rb b/lib/diaspora/parser.rb
index 471a4fbed..883859151 100644
--- a/lib/diaspora/parser.rb
+++ b/lib/diaspora/parser.rb
@@ -29,6 +29,7 @@ module Diaspora
begin
object = body.name.camelize.constantize.from_xml body.to_s
+
if object.is_a? Retraction
elsif object.is_a? Profile
person = parse_owner_id_from_xml body
@@ -52,23 +53,5 @@ module Diaspora
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
diff --git a/spec/lib/diaspora_parser_spec.rb b/spec/lib/diaspora_parser_spec.rb
index c4d56fc11..1afd93ead 100644
--- a/spec/lib/diaspora_parser_spec.rb
+++ b/spec/lib/diaspora_parser_spec.rb
@@ -15,7 +15,7 @@ describe Diaspora::Parser do
10.times {
message = Factory.build(:status_message, :person => @user)
xml = message.to_diaspora_xml
- store_from_xml(xml, @user)
+ @user.receive xml
}
StatusMessage.count.should == 0
end
@@ -28,7 +28,7 @@ describe Diaspora::Parser do
\n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n
"
- store_from_xml(xml, @user)
+ @user.receive xml
Post.count.should == 0
end
@@ -38,7 +38,7 @@ describe Diaspora::Parser do
"
- store_from_xml(xml, @user)
+ @user.receive xml
Post.count.should == 0
end
@@ -73,7 +73,7 @@ describe Diaspora::Parser do
request = retraction.to_diaspora_xml
StatusMessage.count.should == 1
- store_from_xml( request, @user )
+ @user.receive request
StatusMessage.count.should == 0
end
@@ -85,7 +85,7 @@ describe Diaspora::Parser do
@person.destroy
Person.all.count.should be 1
- store_from_xml(xml, @user)
+ @user.receive xml
Person.all.count.should be 2
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
- store_from_xml(xml, @user)
+ @user.receive xml
Person.all.count.should be 3
@user2.reload
@@ -131,7 +131,7 @@ describe Diaspora::Parser do
@person.destroy
request_remote.destroy
- store_from_xml(xml, @user)
+ @user.receive xml
new_person = Person.first(:url => @person.url)
new_person.nil?.should be false
@@ -145,7 +145,7 @@ describe Diaspora::Parser do
request = retraction.to_diaspora_xml
Person.count.should == 2
- store_from_xml( request , @user)
+ @user.receive request
Person.count.should == 1
end
@@ -171,7 +171,7 @@ describe Diaspora::Parser do
old_profile.first_name.should == 'bob'
#Marshal profile
- store_from_xml xml, @user
+ @user.receive xml
#Check that marshaled profile is the same as old profile
person = Person.first(:id => person.id)
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index b1ae2df6a..ae9be2083 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -90,7 +90,7 @@ describe User 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.accept_friend_request @request_three.id
@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
- store_from_xml @req_three_xml, @user2
+ @user2.receive @req_three_xml
@user2.pending_requests.size.should be 1
@user2.ignore_friend_request @request_three.id
@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
- store_from_xml @req_xml, @user
+ @user.receive @req_xml
@user.pending_requests.size.should be 1
@user.accept_friend_request @request.id
@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.accept_friend_request @request_two.id
@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
- store_from_xml @req_xml, @user
+ @user.receive @req_xml
@user.pending_requests.size.should be 1
@user.accept_friend_request @request.id
@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.ignore_friend_request @request_two.id
@user2.friends.include?(@person_one).should be false
@@ -135,12 +135,12 @@ describe User do
end
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.ignore_friend_request @user.pending_requests.first.id
@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.ignore_friend_request @user2.pending_requests.first.id#@request_two.id
@user2.friends.include?(@person_one).should be false
@@ -184,23 +184,14 @@ describe User do
@user.friends.include?(@person_two).should be false
end
+=begin
it 'should do accept reject for people not on the pod' do
-
- @person_one.destroy
- @person_two.destroy
-
end
-
it 'should do accept reject for people on the pod' do
-
end
-
it 'should do accept reject for mixed people on the pod' do
-
- @person_two.destroy
-
end
-
+=end
end
end
@@ -217,4 +208,26 @@ describe User do
@user.profile.image_url.should == "http://clown.com"
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
diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb
index 39bfbd2cd..437c9124e 100644
--- a/spec/user_encryption_spec.rb
+++ b/spec/user_encryption_spec.rb
@@ -54,7 +54,7 @@ describe 'user encryption' do
xml = request.to_diaspora_xml
person.destroy
personcount = Person.all.count
- store_from_xml(xml, @user)
+ @user.receive xml
Person.all.count.should == personcount + 1
new_person = Person.first(:url => "http://test.url/")
new_person.id.should == id
@@ -113,7 +113,7 @@ describe 'user encryption' do
xml = message.to_diaspora_xml
message.destroy
Post.count.should be 0
- store_from_xml(xml, @user)
+ @user.receive xml
Post.count.should be 0
end