Merge branch 'master' of github.com:diaspora/diaspora_rails

This commit is contained in:
maxwell 2010-07-08 10:42:55 -07:00
commit 0c00e6a512
7 changed files with 21 additions and 10 deletions

View file

@ -32,7 +32,6 @@ group :test do
gem 'autotest'
gem 'factory_girl_rails'
gem 'database_cleaner'
gem 'em-spec', :git => 'http://github.com/danielsdeleo/em-spec.git'
end
group :development do

View file

@ -24,10 +24,9 @@ class PersonRequestsController < ApplicationController
end
def create
@person_request = PersonRequest.new(params[:person_request])
@person_request.sender = current_user
@person_request = PersonRequest.for(params[:person_request][:url])
if @person_request.save
if true
flash[:notice] = "Successfully created person request."
redirect_to @person_request
else

View file

@ -4,4 +4,5 @@ class UsersController < ApplicationController
def index
@users = User.sort(:created_at.desc).all
end
end

View file

@ -56,7 +56,7 @@ module Diaspora
module Webhooks
def self.included(klass)
klass.class_eval do
@@queue = MessageHandler.new
@@queue = MessageHandler.instance
def notify_people
if self.person_id == User.first.id
@ -76,9 +76,7 @@ module Diaspora
def push_to_url(url)
if url
puts "AHHHHHH, sending"
xml = self.class.build_xml_for([self])
puts xml
@@queue.add_post_request( [url], xml )
@@queue.process
end

View file

@ -1,4 +1,5 @@
class MessageHandler
include Singleton
NUM_TRIES = 3
TIMEOUT = 5 #seconds
@ -7,6 +8,10 @@ class MessageHandler
@queue = EM::Queue.new
end
def clear
@queue = EM::Queue.new
end
def add_get_request(destinations)
destinations.each{ |dest| @queue.push(Message.new(:get, dest))}
end
@ -22,7 +27,7 @@ class MessageHandler
case query.type
when :post
http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body}
http.callback {process}
http.callback {puts "processing"; process}
when :get
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
http.callback {send_to_seed(query, http.response); process}

View file

@ -2,12 +2,16 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe MessageHandler do
before do
@handler = MessageHandler.new
@handler = MessageHandler.instance
@message_body = "I want to pump you up"
@message_urls = ["http://www.google.com/", "http://yahoo.com/", "http://foo.com/"]
end
after do
@handler.clear
end
describe 'GET messages' do
describe 'creating a GET query' do
it 'should be able to add a GET query to the queue with required destinations' do

View file

@ -33,4 +33,9 @@ describe PersonRequest do
Person.where(:url => person.url).first.active.should be true
end
it "should send a person request to specified url" do
PersonRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
PersonRequest.for("http://google.com/")
end
end