Write webfinger job for search

This commit is contained in:
Raphael 2010-12-02 11:37:24 -08:00
parent 6cfa6577a5
commit c76f38ca23
4 changed files with 67 additions and 11 deletions

View file

@ -116,13 +116,6 @@ class PeopleController < ApplicationController
end
end
def webfinger(account, opts = {})
finger = Webfinger.new(account)
begin
result = finger.fetch
response.socket_to_uid(current_user.id, opts)
rescue
require File.join(Rails.root,'lib/diaspora/web_socket')
Diaspora::WebSocket.queue_to_user(current_user.id, {:class => 'people', :status => 'fail', :query => account, :response => I18n.t('people.webfinger.fail')}.to_json)
end
Resque.enqueue(Jobs::SocketWebfinger, current_user.id, account, opts)
end
end

View file

@ -0,0 +1,15 @@
module Jobs
class SocketWebfinger
@queue = :receive
def self.perform(user_id, account, opts={})
finger = Webfinger.new(account)
begin
result = finger.fetch
result.socket_to_uid(user_id, opts)
rescue
Diaspora::WebSocket.queue_to_user(user_id, {:class => 'people', :status => 'fail', :query => account, :response => I18n.t('people.webfinger.fail')}.to_json)
end
end
end
end

View file

@ -94,9 +94,9 @@ describe PeopleController do
end
end
describe '#retrieve_remote' do
it 'sockets a local user' do
Diaspora::WebSocket.should_receive(:queue_to_user).with(user.id, anything)
describe '#webfinger' do
it 'enqueues a webfinger job' do
Resque.should_receive(:enqueue).with(Jobs::SocketWebfinger, user.id, user.diaspora_handle, anything).once
get :retrieve_remote, :diaspora_handle => user.diaspora_handle
end
end

View file

@ -0,0 +1,48 @@
require 'spec/spec_helper'
describe Jobs::SocketWebfinger do
before do
@user = make_user
@account = "tom@tom.joindiaspora.com"
end
it 'Makes a Webfinger object' do
Webfinger.should_receive(:new).with(@account)
Jobs::SocketWebfinger.perform(@user.id, @account)
end
it 'Queries the target account' do
finger = mock()
Webfinger.stub(:new).and_return(finger)
finger.should_receive(:fetch).and_return(Factory.create(:person))
Jobs::SocketWebfinger.perform(@user.id, @account)
end
it 'Sockets the resulting person on success' do
finger = mock()
Webfinger.stub(:new).and_return(finger)
person = Factory.create(:person)
finger.stub(:fetch).and_return(person)
person.should_receive(:socket_to_uid).with(@user.id, {})
Jobs::SocketWebfinger.perform(@user.id, @account)
end
it 'Passes opts through on success' do
finger = mock()
Webfinger.stub(:new).and_return(finger)
person = Factory.create(:person)
finger.stub(:fetch).and_return(person)
opts = {:symbol => true}
person.should_receive(:socket_to_uid).with(@user.id, opts)
Jobs::SocketWebfinger.perform(@user.id, @account, opts)
end
it 'sockets failure message on failure' do
finger = mock()
Webfinger.stub(:new).and_return(finger)
finger.stub(:fetch).and_raise(Webfinger::WebfingerFailedError)
opts = {:class => 'people', :status => 'fail', :query => @account, :response => I18n.t('people.webfinger.fail')}.to_json
Diaspora::WebSocket.should_receive(:queue_to_user).with(@user.id, opts)
Jobs::SocketWebfinger.perform(@user.id, @account)
end
end