From 31bfef9dd240e7df0ac623177e1d5ee17b55a911 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Fri, 27 Jan 2012 16:05:38 -0800 Subject: [PATCH] pass in service_type strings instead of objects to deferred_dispatcher. --- app/controllers/status_messages_controller.rb | 4 ++-- app/models/jobs/deferred_dispatch.rb | 1 + lib/postzord/dispatcher.rb | 3 +-- spec/controllers/status_messages_controller_spec.rb | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 8e5529186..afbbbefba 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -51,9 +51,9 @@ class StatusMessagesController < ApplicationController if @status_message.save aspects = current_user.aspects_from_ids(destination_aspect_ids) current_user.add_to_streams(@status_message, aspects) - receiving_services = current_user.services.where(:type => Service.titles(services)) - current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :services => receiving_services) + receiving_services = Service.titles(services) + current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :service_types => receiving_services) if coming_from_profile_page? # if this is a post coming from a profile page flash[:notice] = successful_mention_message diff --git a/app/models/jobs/deferred_dispatch.rb b/app/models/jobs/deferred_dispatch.rb index 205287ced..b3b2465f1 100644 --- a/app/models/jobs/deferred_dispatch.rb +++ b/app/models/jobs/deferred_dispatch.rb @@ -9,6 +9,7 @@ module Jobs def self.perform(user_id, object_class_name, object_id, opts) user = User.find(user_id) object = object_class_name.constantize.find(object_id) + opts[:services] = user.services.where(:type => opts.delete(:service_types)).all if opts[:additional_subscribers].present? opts[:additional_subscribers] = Person.where(:id => opts[:additional_subscribers]) diff --git a/lib/postzord/dispatcher.rb b/lib/postzord/dispatcher.rb index 778ef75b6..24cc5341a 100644 --- a/lib/postzord/dispatcher.rb +++ b/lib/postzord/dispatcher.rb @@ -25,7 +25,7 @@ class Postzord::Dispatcher # @return [Postzord::Dispatcher] Public or private dispatcher depending on the object's intended audience def self.build(user, object, opts={}) unless object.respond_to? :to_diaspora_xml - raise 'this object does not respond_to? to_diaspora xml. try including Diaspora::Webhooks into your object' + raise 'This object does not respond_to? to_diaspora xml. Try including Diaspora::Webhooks into your object' end if self.object_should_be_processed_as_public?(object) @@ -36,7 +36,6 @@ class Postzord::Dispatcher end def self.defer_build_and_post(user, object, opts={}) - opts[:additional_subscribers] ||= [] opts[:additional_subscribers] = [*opts[:additional_subscribers]].map(&:id) Resque.enqueue(Jobs::DeferredDispatch, user.id, object.class.to_s, object.id, opts) end diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 6280484d6..466b8fca7 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -68,7 +68,8 @@ describe StatusMessagesController do alice.services << s1 alice.services << Services::Twitter.new status_message_hash[:services] = ['facebook'] - alice.should_receive(:dispatch_post).with(anything(), hash_including(:services => [s1])) + service_types = Service.titles(status_message_hash[:services]) + alice.should_receive(:dispatch_post).with(anything(), hash_including(:service_types => service_types)) post :create, status_message_hash end @@ -76,7 +77,7 @@ describe StatusMessagesController do s1 = Services::Facebook.new alice.services << s1 status_message_hash[:services] = "facebook" - alice.should_receive(:dispatch_post).with(anything(), hash_including(:services => [s1])) + alice.should_receive(:dispatch_post).with(anything(), hash_including(:service_types => ["Services::Facebook"])) post :create, status_message_hash end