Skip to content
Extraits de code Groupes Projets
Valider 417fed38 rédigé par danielvincent's avatar danielvincent
Parcourir les fichiers

DG IZ; fixed person requesting (friend requests).

parent 3d105e7c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class PersonRequest
include MongoMapper::Document
include Diaspora::Webhooks
include ROXML
key :url, String
xml_name :person_request
xml_accessor :_id
xml_accessor :person, :as => Person
attr_accessor :sender
key :url, String
key :person, Person
validates_presence_of :url
before_save :check_for_person_requests
def to_person_xml
person = Person.new
person.email = sender.email
person.url = sender.url
person.profile = sender.profile.clone
person.to_xml
end
def self.for(url)
person_request = PersonRequest.new(:url => url)
person_request.sender = User.first
person_request.save
request = PersonRequest.new(:url => url)
request.person = User.first
request.save
person_request.push_person_request_to_url(person_request.url)
request.push_to([request])
end
def check_for_person_requests
......
......@@ -33,11 +33,12 @@ module Diaspora
objects.each do |p|
if p.is_a? Retraction
p.perform
elsif p.is_a? Person
elsif p.is_a? PersonRequest
if PersonRequest.where(:url => p.url).first
p.active = true
end
p.save
p.person.save
#This line checks if the sender was in the database, among other things?
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User) #WTF
p.save
......@@ -68,19 +69,6 @@ module Diaspora
end
end
def push_person_request_to_url(url)
if url
url = url + "receive/"
xml = "<XML>
<posts><post>
#{self.to_person_xml.to_s}
</post></posts>
</XML>"
@@queue.add_post_request( [url], xml )
@@queue.process
end
end
def prep_webhook
"<post>#{self.to_xml.to_s}</post>"
end
......
......@@ -111,13 +111,10 @@ describe "parser in application helper" do
end
it "should create a new person upon getting a person request" do
person_request = PersonRequest.new(:url => "http://www.googles.com/")
person_request.sender = @person
xml = "<XML>
<posts><post>
#{person_request.to_person_xml.to_s}
</post></posts>
</XML>"
request = PersonRequest.new(:url => "http://www.googles.com/")
request.person = @person
xml = Post.build_xml_for [request]
@person.destroy
@user.destroy
......@@ -127,22 +124,13 @@ describe "parser in application helper" do
end
it "should activate the Person if I initiated a request to that url" do
person_request = PersonRequest.create(:url => @person.url, :sender => @user)
person_request_remote = PersonRequest.new(:url => "http://www.yahoo.com/")
person_request_remote.sender = @person.clone
xml = "<XML>
<posts><post>
#{person_request_remote.to_person_xml.to_s}
</post></posts>
</XML>"
request = PersonRequest.create(:url => @person.url, :person => @user)
request_remote = PersonRequest.new(:url => "http://www.yahoo.com/")
request_remote.person = @person.clone
@person.destroy
@user.destroy
Person.count.should be 0
store_objects_from_xml(xml)
Person.count.should be 1
Person.first.active.should be true
xml = Post.build_xml_for [request_remote]
Person.where(:url => @person.url).first.active.should be true
end
end
......
......@@ -10,14 +10,14 @@ describe PersonRequest do
end
it 'should generate xml for the User as a Person' do
person_request = PersonRequest.new(:url => "http://www.google.com")
user = Factory.create(:user)
person_request.sender = user
person_xml = person_request.to_person_xml.to_s
person_xml.include?(user.email).should be true
person_xml.include?(user.url).should be true
person_xml.include?(user.profile.first_name).should be true
person_xml.include?(user.profile.last_name).should be true
request = PersonRequest.new(:url => "http://www.google.com/", :person => user)
xml = request.to_xml.to_s
xml.include?(user.email).should be true
xml.include?(user.url).should be true
xml.include?(user.profile.first_name).should be true
xml.include?(user.profile.last_name).should be true
end
it 'should be sent to the url upon for action' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter