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)
|
def receive_friend_request(friend_request)
|
||||||
Rails.logger.debug("receiving friend request #{friend_request.to_json}")
|
Rails.logger.debug("receiving friend request #{friend_request.to_json}")
|
||||||
|
|
||||||
friend_request.person.serialized_key = friend_request.exported_key
|
#u am originator
|
||||||
if Request.where(:callback_url => friend_request.callback_url).first
|
if Request.where(:callback_url => person.url, :destination_url => person.url).first
|
||||||
|
puts "NOOO!!"
|
||||||
activate_friend friend_request.person
|
activate_friend friend_request.person
|
||||||
Rails.logger.debug("#{self.real_name}'s friend request has been accepted")
|
Rails.logger.debug("#{self.real_name}'s friend request has been accepted")
|
||||||
friend_request.destroy
|
friend_request.destroy
|
||||||
else
|
else
|
||||||
|
puts "423423"
|
||||||
friend_request.person.save
|
friend_request.person.save
|
||||||
pending_requests << friend_request
|
pending_requests << friend_request
|
||||||
save
|
save
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,13 @@ module Diaspora
|
||||||
Person.first(:id => id)
|
Person.first(:id => id)
|
||||||
end
|
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)
|
def parse_objects_from_xml(xml)
|
||||||
objects = []
|
objects = []
|
||||||
body = parse_body_contents_from_xml(xml)
|
body = parse_body_contents_from_xml(xml)
|
||||||
|
|
@ -28,15 +35,15 @@ module Diaspora
|
||||||
person.profile = object
|
person.profile = object
|
||||||
person.save
|
person.save
|
||||||
elsif object.is_a? Request
|
elsif object.is_a? Request
|
||||||
person_string = Nokogiri::XML(xml) { |cfg| cfg.noblanks }.xpath("/XML/posts/post/request/person").to_s
|
person = get_or_create_person_object_from_xml(post)
|
||||||
person = Person.from_xml person_string
|
|
||||||
person.serialized_key ||= object.exported_key
|
person.serialized_key ||= object.exported_key
|
||||||
object.person = person
|
object.person = person
|
||||||
object.person.save
|
object.person.save
|
||||||
|
object.save
|
||||||
elsif object.respond_to? :person
|
elsif object.respond_to? :person
|
||||||
object.person = parse_owner_from_xml post.to_s
|
object.person = parse_owner_from_xml post.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
objects << object
|
objects << object
|
||||||
rescue NameError => e
|
rescue NameError => e
|
||||||
if e.message.include? 'wrong constant name'
|
if e.message.include? 'wrong constant name'
|
||||||
|
|
@ -56,8 +63,12 @@ module Diaspora
|
||||||
if p.is_a? Retraction
|
if p.is_a? Retraction
|
||||||
Rails.logger.debug "Got a retraction for #{p.post_id}"
|
Rails.logger.debug "Got a retraction for #{p.post_id}"
|
||||||
p.perform
|
p.perform
|
||||||
|
|
||||||
elsif p.is_a? Request
|
elsif p.is_a? Request
|
||||||
|
puts user.pending_requests.count
|
||||||
user.receive_friend_request(p)
|
user.receive_friend_request(p)
|
||||||
|
puts user.pending_requests.count
|
||||||
|
|
||||||
elsif p.is_a? Profile
|
elsif p.is_a? Profile
|
||||||
p.save
|
p.save
|
||||||
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User)
|
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
require File.dirname(__FILE__) + '/../spec_helper'
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
|
|
||||||
describe PublicsController do
|
describe PublicsController do
|
||||||
render_views
|
render_views
|
||||||
|
|
@ -37,7 +38,7 @@ describe PublicsController do
|
||||||
req.delete
|
req.delete
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should save requests for the specified user (LOCAL)' do
|
it 'should save requests for the specified user (LOCAL)' do
|
||||||
post :receive, :id => @user.person.id, :xml => @xml
|
post :receive, :id => @user.person.id, :xml => @xml
|
||||||
|
|
||||||
@user.reload
|
@user.reload
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ describe Diaspora::Parser do
|
||||||
store_objects_from_xml(xml, @user)
|
store_objects_from_xml(xml, @user)
|
||||||
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.where(:url => request.callback_url).first.id.should == original_person_id
|
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -138,6 +139,9 @@ describe Diaspora::Parser do
|
||||||
Person.all.count.should be 3
|
Person.all.count.should be 3
|
||||||
|
|
||||||
@user2.reload
|
@user2.reload
|
||||||
|
@user2.person.reload
|
||||||
|
puts @user2.inspect
|
||||||
|
puts @user2.person.inspect
|
||||||
@user2.person.serialized_key.include?("PRIVATE").should be true
|
@user2.person.serialized_key.include?("PRIVATE").should be true
|
||||||
|
|
||||||
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
Person.where(:url => request.callback_url).first.id.should == original_person_id
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue