From 153c4925d6098a552fcfdb6456d7c2542ea22c07 Mon Sep 17 00:00:00 2001 From: maxwell <maxwell@joindiaspora.com> Date: Thu, 6 Jan 2011 17:19:13 -0800 Subject: [PATCH] test for pubsubhububb jobs --- app/models/jobs/publish_to_hub.rb | 13 +++++++++++++ lib/postzord/dispatch.rb | 2 +- spec/lib/postzord/dispatch_spec.rb | 6 +++--- spec/models/jobs/publish_to_hub_spec.rb | 18 ++++++++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 app/models/jobs/publish_to_hub.rb create mode 100644 spec/models/jobs/publish_to_hub_spec.rb diff --git a/app/models/jobs/publish_to_hub.rb b/app/models/jobs/publish_to_hub.rb new file mode 100644 index 0000000000..b33ae18e00 --- /dev/null +++ b/app/models/jobs/publish_to_hub.rb @@ -0,0 +1,13 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +module Jobs + class PublishToHub + +require File.join(Rails.root, 'lib/pubsubhubbub') + def self.perform(sender_public_url) + PubSubHubbub.new(AppConfig[:pubsub_server]).publish(sender_public_url) + end + end +end diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatch.rb index 90b7965178..5f8db8ba42 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatch.rb @@ -45,7 +45,7 @@ class Postzord::Dispatch def deliver_to_hub Rails.logger.debug("event=post_to_service type=pubsub sender_handle=#{@sender.diaspora_handle}") - PubSubHubbub.new(AppConfig[:pubsub_server]).publish(@sender.public_url) + Resque.enqueue(Jobs::PublishToHub, @sender.public_url) end def deliver_to_services(url) diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatch_spec.rb index 6fe7627f97..b942c66229 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatch_spec.rb @@ -124,9 +124,9 @@ describe Postzord::Dispatch do @zord.send(:deliver_to_services, nil) end - it 'notifies the hub' do - @zord.should_receive(:deliver_to_hub) - @zord.send(:deliver_to_services, nil) + it 'queues a job to notify the hub' do + Resque.should_receive(:enqueue).with(Jobs::PublishToHub, @user.public_url) + @zord.send(:deliver_to_services, nil) end it 'only pushes to services if the object is public' do diff --git a/spec/models/jobs/publish_to_hub_spec.rb b/spec/models/jobs/publish_to_hub_spec.rb new file mode 100644 index 0000000000..b759d6b68a --- /dev/null +++ b/spec/models/jobs/publish_to_hub_spec.rb @@ -0,0 +1,18 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe Jobs::PublishToHub do + describe '.perform' do + it 'calls pubsubhubbub' do + url = "http://publiczone.com/" + m = mock() + + m.should_receive(:publish).with(url) + PubSubHubbub.should_receive(:new).with(AppConfig[:pubsub_server]).and_return(m) + Jobs::PublishToHub.perform(url) + end + end +end -- GitLab