Merge branch 'master' of github.com:diaspora/diaspora_rails
This commit is contained in:
commit
0c00e6a512
7 changed files with 21 additions and 10 deletions
1
Gemfile
1
Gemfile
|
|
@ -32,7 +32,6 @@ group :test do
|
||||||
gem 'autotest'
|
gem 'autotest'
|
||||||
gem 'factory_girl_rails'
|
gem 'factory_girl_rails'
|
||||||
gem 'database_cleaner'
|
gem 'database_cleaner'
|
||||||
gem 'em-spec', :git => 'http://github.com/danielsdeleo/em-spec.git'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,9 @@ class PersonRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@person_request = PersonRequest.new(params[:person_request])
|
@person_request = PersonRequest.for(params[:person_request][:url])
|
||||||
@person_request.sender = current_user
|
|
||||||
|
|
||||||
if @person_request.save
|
if true
|
||||||
flash[:notice] = "Successfully created person request."
|
flash[:notice] = "Successfully created person request."
|
||||||
redirect_to @person_request
|
redirect_to @person_request
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,5 @@ class UsersController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@users = User.sort(:created_at.desc).all
|
@users = User.sort(:created_at.desc).all
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,8 @@ module Diaspora
|
||||||
module Webhooks
|
module Webhooks
|
||||||
def self.included(klass)
|
def self.included(klass)
|
||||||
klass.class_eval do
|
klass.class_eval do
|
||||||
@@queue = MessageHandler.new
|
@@queue = MessageHandler.instance
|
||||||
|
|
||||||
def notify_people
|
def notify_people
|
||||||
if self.person_id == User.first.id
|
if self.person_id == User.first.id
|
||||||
push_to(people_with_permissions)
|
push_to(people_with_permissions)
|
||||||
|
|
@ -76,9 +76,7 @@ module Diaspora
|
||||||
|
|
||||||
def push_to_url(url)
|
def push_to_url(url)
|
||||||
if url
|
if url
|
||||||
puts "AHHHHHH, sending"
|
|
||||||
xml = self.class.build_xml_for([self])
|
xml = self.class.build_xml_for([self])
|
||||||
puts xml
|
|
||||||
@@queue.add_post_request( [url], xml )
|
@@queue.add_post_request( [url], xml )
|
||||||
@@queue.process
|
@@queue.process
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
class MessageHandler
|
class MessageHandler
|
||||||
|
include Singleton
|
||||||
|
|
||||||
NUM_TRIES = 3
|
NUM_TRIES = 3
|
||||||
TIMEOUT = 5 #seconds
|
TIMEOUT = 5 #seconds
|
||||||
|
|
@ -7,6 +8,10 @@ class MessageHandler
|
||||||
@queue = EM::Queue.new
|
@queue = EM::Queue.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clear
|
||||||
|
@queue = EM::Queue.new
|
||||||
|
end
|
||||||
|
|
||||||
def add_get_request(destinations)
|
def add_get_request(destinations)
|
||||||
destinations.each{ |dest| @queue.push(Message.new(:get, dest))}
|
destinations.each{ |dest| @queue.push(Message.new(:get, dest))}
|
||||||
end
|
end
|
||||||
|
|
@ -22,7 +27,7 @@ class MessageHandler
|
||||||
case query.type
|
case query.type
|
||||||
when :post
|
when :post
|
||||||
http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body}
|
http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body}
|
||||||
http.callback {process}
|
http.callback {puts "processing"; process}
|
||||||
when :get
|
when :get
|
||||||
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
|
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
|
||||||
http.callback {send_to_seed(query, http.response); process}
|
http.callback {send_to_seed(query, http.response); process}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,16 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
describe MessageHandler do
|
describe MessageHandler do
|
||||||
before do
|
before do
|
||||||
@handler = MessageHandler.new
|
@handler = MessageHandler.instance
|
||||||
@message_body = "I want to pump you up"
|
@message_body = "I want to pump you up"
|
||||||
@message_urls = ["http://www.google.com/", "http://yahoo.com/", "http://foo.com/"]
|
@message_urls = ["http://www.google.com/", "http://yahoo.com/", "http://foo.com/"]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
@handler.clear
|
||||||
|
end
|
||||||
|
|
||||||
describe 'GET messages' do
|
describe 'GET messages' do
|
||||||
describe 'creating a GET query' do
|
describe 'creating a GET query' do
|
||||||
it 'should be able to add a GET query to the queue with required destinations' do
|
it 'should be able to add a GET query to the queue with required destinations' do
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,9 @@ describe PersonRequest do
|
||||||
Person.where(:url => person.url).first.active.should be true
|
Person.where(:url => person.url).first.active.should be true
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue