RS, IZ; removed lots of putses, fixed up request, parser, retractions

This commit is contained in:
Raphael 2010-08-06 16:01:39 -07:00
parent f2e327d908
commit 4350e17656
14 changed files with 71 additions and 43 deletions

View file

@ -18,7 +18,7 @@ class PublicsController < ApplicationController
end
def receive
puts "SOMEONE JUST SENT ME: #{params[:xml]}"
Rails.logger.info "PublicsController has received: #{params[:xml]}"
store_objects_from_xml params[:xml]
render :nothing => true
end

View file

@ -13,9 +13,8 @@ module SocketsHelper
begin
v = render_to_string(:partial => type_partial(object), :locals => {:post => object}) unless object.is_a? Retraction
rescue Exception => e
puts "web socket view rendering failed for some reason." + v.inspect
puts object.inspect
puts e.message
Rails.logger.error ("web socket view rendering failed for some reason." + v.inspect)
Rails.logger.error("Socketed object was #{object.inspect}")
raise e
end
action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}

View file

@ -26,12 +26,10 @@ class Comment
end
def push_upstream
puts "Comment going upstream"
push_to([post.person])
end
def push_downstream
puts "Comment going downstream"
push_to(post.people_with_permissions)
end
@ -63,7 +61,6 @@ class Comment
def verify_post_creator_signature
unless person == User.owner
puts "verifying post creator sig from #{post.person.real_name}"
verify_signature(post_creator_signature, post.person)
else
true

View file

@ -93,7 +93,6 @@ class Person
##profile
def update_profile(params)
if self.update_attributes(params)
puts self.profile.class
self.profile.notify_people!
true
else

View file

@ -32,17 +32,20 @@ class Request
person = options[:from]
self.new(:destination_url => options[:to], :callback_url => person.url, :person => person, :exported_key => person.export_key)
end
def activate_friend
from_user = Person.first(:url => self.callback_url).owner
puts from_user.inspect
from_user.friends << from_user.pending_friends.delete(person)
from_user.pending_friends.delete(person)
from_user.friends << person
from_user.save
end
def set_pending_friend
p = Person.first(:id => self.person.id)
puts p.inspect
self.person.save #save pending friend
end

View file

@ -5,11 +5,15 @@ class Retraction
def self.for(object)
retraction = self.new
retraction.post_id= object.id
if object.is_a? User
retraction.post_id = object.person.id
retraction.type = object.person.class.to_s
else
retraction.post_id= object.id
retraction.type = object.class.to_s
end
retraction.person_id = person_id_from(object)
retraction.type = object.class.to_s
retraction
end
xml_accessor :post_id
@ -23,6 +27,7 @@ class Retraction
def perform
begin
return unless signature_valid?
Rails.logger.info("Retracting #{self.type} id: #{self.post_id}")
self.type.constantize.destroy(self.post_id)
rescue NameError
Rails.logger.info("Retraction for unknown type recieved.")

View file

@ -8,7 +8,9 @@ class User
key :pending_friend_ids, Array
one :person, :class_name => 'Person', :foreign_key => :owner_id
many :friends, :in => :friend_ids, :class_name => 'Person'
many :pending_friends, :in => :pending_friend_ids, :class_name => 'Person'
before_validation_on_create :assign_key
before_validation :do_bad_things
@ -20,10 +22,6 @@ class User
self.person.send(method, *args)
end
def pending_friends
Person.all(:id => self.pending_friend_ids)
end
def real_name
"#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}"
@ -38,13 +36,15 @@ class User
if p.save
p.push_to_url friend_url
end
p
p
end
end
def accept_friend_request(friend_request_id)
request = Request.where(:id => friend_request_id).first
request.activate_friend
pending_friends.delete(request.person)
friends << request.person
request.person = self
request.exported_key = self.export_key
request.destination_url = request.callback_url
@ -55,7 +55,8 @@ class User
def ignore_friend_request(friend_request_id)
request = Request.first(:id => friend_request_id)
person = request.person
person.destroy unless self.friends.include? person
pending_friends.delete(request.person)
person.destroy unless person.user_refs > 0
request.destroy
end
@ -65,12 +66,12 @@ class User
friend_request.person.serialized_key = friend_request.exported_key
if Request.where(:callback_url => friend_request.callback_url).first
friend_request.activate_friend
Rails.logger.info("#{self.real_name}'s friend request has been accepted")
friend_request.destroy
else
friend_request.person.save
friend_request.create_pending_friend
pending_friends << friend_request.person
Rails.logger.info("#{self.real_name} has received a friend request")
friend_request.save
end
end

View file

@ -23,13 +23,12 @@ module Diaspora
begin
object = post.name.camelize.constantize.from_xml post.to_s
if object.is_a? Retraction
elsif object.respond_to? :person
object.person = parse_owner_from_xml post.to_s
elsif object.is_a? Profile
puts "got into parse objects from xml PROFILE"
person = parse_owner_id_from_xml post
person.profile = object
person.save
elsif object.respond_to? :person
object.person = parse_owner_from_xml post.to_s
end
objects << object
rescue NameError => e
@ -48,7 +47,7 @@ module Diaspora
objects.each do |p|
Rails.logger.info("Receiving object:\n#{p.inspect}")
if p.is_a? Retraction
puts "Got a retraction for #{p.post_id}"
Rails.logger.info "Got a retraction for #{p.post_id}"
p.perform
elsif p.is_a? Request
User.owner.receive_friend_request(p)

View file

@ -13,7 +13,6 @@ class MessageHandler
end
def add_post_request(destinations, body)
puts "sending to: #{destinations.inspect}"
b = CGI::escape( body )
[*destinations].each{|dest| @queue.push(Message.new(:post, dest, :body => b))}
end

View file

@ -105,7 +105,6 @@ describe Diaspora::Parser do
message = Factory.create(:status_message, :person => person)
retraction = Retraction.for(message)
request = Post.build_xml_for( [retraction] )
puts request
StatusMessage.count.should == 1
store_objects_from_xml( request )
@ -141,11 +140,14 @@ describe Diaspora::Parser do
@person.destroy
request_remote.destroy
store_objects_from_xml(xml)
Person.first(:url => @person.url).active.should be true
new_person = Person.first(:url => @person.url)
new_person.nil?.should be false
@user.reload
@user.friends.include?(new_person).should be true
end
it 'should marshal a retraction for a person' do
it 'should process retraction for a person' do
retraction = Retraction.for(@user)
request = Retraction.build_xml_for( [retraction] )
@ -169,7 +171,7 @@ describe Diaspora::Parser do
xml = Post.build_xml_for(person.profile)
reloaded_person = Person.first(:id => id)
reloaded_person.profile = nil
reloaded_person.profile.save
reloaded_person.save(:validate => false)
#Make sure profile is cleared
Person.first(:id => id).profile.should be nil

View file

@ -138,7 +138,6 @@ class FakeHttpRequest
@callback = callback_wanted
end
def response
"NOTE YOU ARE IN FAKE HTTP"
end
def post; end

View file

@ -46,7 +46,6 @@ describe Comment do
it 'should send a user comment on his own post to lots of people' do
allowed_urls = @user_status.people_with_permissions.map!{|x| x = x.url + "receive/"}
puts allowed_urls
message_queue.should_receive(:add_post_request).with(allowed_urls, anything)
@user.comment "yo", :on => @user_status
end

View file

@ -59,7 +59,6 @@ describe Photo do
it 'should not use the imported filename as the url' do
@photo.image.store! File.open(@fixture_name)
puts @photo.image.url(:thumb_medium)
@photo.image.url.include?(@fixture_filename).should be false
@photo.image.url(:thumb_medium).include?("/" + @fixture_filename).should be false
end

View file

@ -1,19 +1,18 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe User do
before do
@user = Factory.create(:user)
end
it "should be a person" do
n = Person.count
Factory.create(:user)
Person.count.should == n+1
end
describe 'friend requesting' do
before do
@user = Factory.create(:user)
end
it "should be able to accept a pending friend request" do
it "should be able to accept a pending friend request" do
friend = Factory.create(:person)
r = Request.instantiate(:to => @user.url, :from => friend)
r.save
@ -50,6 +49,35 @@ describe User do
@user.terse_url.should == 'example.com'
end
it 'should get the pending friends' do
person_one = Factory.create :person
person_two = Factory.create :person
@user.pending_friends.empty?.should be true
@user.friends.empty?.should be true
request = Request.instantiate(:to => @user.url, :from => person_one)
person_one.destroy
@user.receive_friend_request request
@user.pending_friends.size.should be 1
@user.friends.size.should be 0
request_two = Request.instantiate(:to => @user.url, :from => person_two)
person_two.destroy
@user.receive_friend_request request_two
@user.pending_friends.size.should be 2
@user.friends.size.should be 0
@user.accept_friend_request request.id
@user.pending_friends.size.should be 1
@user.friends.size.should be 1
@user.ignore_friend_request request_two.id
@user.pending_friends.size.should be 0
@user.friends.size.should be 1
end
end
describe 'profiles' do
it 'should be able to update their profile and send it to their friends' do
Factory.create(:person)
@ -61,5 +89,4 @@ describe User do
@user.profile.image_url.should == "http://clown.com"
end
end
end