MS IZ fixed all of the request specs zomg
This commit is contained in:
parent
cd875d06db
commit
95c4de5d6c
4 changed files with 24 additions and 6 deletions
|
|
@ -77,12 +77,14 @@ class User
|
|||
def receive_friend_request(friend_request)
|
||||
Rails.logger.debug("receiving friend request #{friend_request.to_json}")
|
||||
|
||||
friend_request.person.serialized_key = friend_request.exported_key
|
||||
if Request.where(:callback_url => friend_request.callback_url).first
|
||||
#u am originator
|
||||
if Request.where(:callback_url => person.url, :destination_url => person.url).first
|
||||
puts "NOOO!!"
|
||||
activate_friend friend_request.person
|
||||
Rails.logger.debug("#{self.real_name}'s friend request has been accepted")
|
||||
friend_request.destroy
|
||||
else
|
||||
puts "423423"
|
||||
friend_request.person.save
|
||||
pending_requests << friend_request
|
||||
save
|
||||
|
|
|
|||
|
|
@ -16,6 +16,13 @@ module Diaspora
|
|||
Person.first(:id => id)
|
||||
end
|
||||
|
||||
def get_or_create_person_object_from_xml(doc)
|
||||
person_xml = doc.xpath("//request/person").to_s
|
||||
person_id = doc.xpath("//request/person/_id").text.to_s
|
||||
person = Person.first(:_id => person_id)
|
||||
person ? person : Person.from_xml( person_xml)
|
||||
end
|
||||
|
||||
def parse_objects_from_xml(xml)
|
||||
objects = []
|
||||
body = parse_body_contents_from_xml(xml)
|
||||
|
|
@ -28,15 +35,15 @@ module Diaspora
|
|||
person.profile = object
|
||||
person.save
|
||||
elsif object.is_a? Request
|
||||
person_string = Nokogiri::XML(xml) { |cfg| cfg.noblanks }.xpath("/XML/posts/post/request/person").to_s
|
||||
person = Person.from_xml person_string
|
||||
person = get_or_create_person_object_from_xml(post)
|
||||
person.serialized_key ||= object.exported_key
|
||||
object.person = person
|
||||
object.person.save
|
||||
|
||||
object.save
|
||||
elsif object.respond_to? :person
|
||||
object.person = parse_owner_from_xml post.to_s
|
||||
end
|
||||
|
||||
objects << object
|
||||
rescue NameError => e
|
||||
if e.message.include? 'wrong constant name'
|
||||
|
|
@ -56,8 +63,12 @@ module Diaspora
|
|||
if p.is_a? Retraction
|
||||
Rails.logger.debug "Got a retraction for #{p.post_id}"
|
||||
p.perform
|
||||
|
||||
elsif p.is_a? Request
|
||||
puts user.pending_requests.count
|
||||
user.receive_friend_request(p)
|
||||
puts user.pending_requests.count
|
||||
|
||||
elsif p.is_a? Profile
|
||||
p.save
|
||||
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
|
||||
describe PublicsController do
|
||||
render_views
|
||||
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ describe Diaspora::Parser do
|
|||
store_objects_from_xml(xml, @user)
|
||||
Person.all.count.should be 2
|
||||
|
||||
Person.first(:_id => original_person_id).serialized_key.include?("PUBLIC").should be true
|
||||
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
||||
end
|
||||
|
||||
|
|
@ -138,6 +139,9 @@ describe Diaspora::Parser do
|
|||
Person.all.count.should be 3
|
||||
|
||||
@user2.reload
|
||||
@user2.person.reload
|
||||
puts @user2.inspect
|
||||
puts @user2.person.inspect
|
||||
@user2.person.serialized_key.include?("PRIVATE").should be true
|
||||
|
||||
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
||||
|
|
|
|||
Loading…
Reference in a new issue