From e61cc2fd3466e9666676c9780b9e591055142187 Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Tue, 22 Feb 2011 20:13:34 -0800 Subject: [PATCH] made the postzord take the services in individually --- app/controllers/status_messages_controller.rb | 4 +++- app/views/shared/_publisher.html.haml | 2 +- lib/postzord/dispatch.rb | 8 ++++---- spec/controllers/status_messages_controller_spec.rb | 9 ++++++--- spec/lib/postzord/dispatch_spec.rb | 10 +++++++++- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 3c8471007..77a6b3e5a 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -25,7 +25,9 @@ class StatusMessagesController < ApplicationController Rails.logger.info("event=create type=status_message chars=#{params[:status_message][:message].length}") current_user.add_to_streams(@status_message, aspects) - current_user.dispatch_post(@status_message, :url => post_url(@status_message), :services => current_user.services) + receiving_services = params[:services].map{|s| current_user.services.where( + :type => "Services::"+s.titleize).first} if params[:services] + current_user.dispatch_post(@status_message, :url => post_url(@status_message), :services => receiving_services) if !photos.empty? for photo in photos was_pending = photo.pending diff --git a/app/views/shared/_publisher.html.haml b/app/views/shared/_publisher.html.haml index d7676e165..3c97ad4d3 100644 --- a/app/views/shared/_publisher.html.haml +++ b/app/views/shared/_publisher.html.haml @@ -50,7 +50,7 @@ = link_to (image_tag "social_media_logos/feed-16x16.png", :title => "RSS"), current_user.public_url - if current_user.services - for service in current_user.services - = image_tag "social_media_logos/#{service.provider}-16x16.png", :title => service.provider + = image_tag "social_media_logos/#{service.provider}-16x16.png", :title => service.provider, :class => "service", :id =>"#{service.provider}" = link_to '(?)', "#question_mark_pane", :class => 'question_mark', :style=>"display:none;", :rel => 'facebox' diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatch.rb index 3ce17bf5a..244f1bb5d 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatch.rb @@ -58,10 +58,10 @@ class Postzord::Dispatch def deliver_to_services(url, services) if @object.respond_to?(:public) && @object.public deliver_to_hub - if @object.respond_to?(:message) - services.each do |service| - Resque.enqueue(Job::PostToService, service.id, @object.id, url) - end + end + if @object.respond_to?(:message) + services.each do |service| + Resque.enqueue(Job::PostToService, service.id, @object.id, url) end end end diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 56435fe24..77521f134 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -64,9 +64,12 @@ describe StatusMessagesController do response.status.should == 201 end - it "dispatches the post to the user's services" do - @user1.services << Services::Facebook.new - @user1.should_receive(:dispatch_post).with(anything(),hash_including(:services => @user1.services)) + it "dispatches the post to the specified services" do + s1 = Services::Facebook.new + @user1.services << s1 + @user1.services << Services::Twitter.new + status_message_hash[:services] = ['facebook'] + @user1.should_receive(:dispatch_post).with(anything(), hash_including(:services => [s1])) post :create, status_message_hash end diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatch_spec.rb index edd160bcb..ae64c9457 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatch_spec.rb @@ -273,7 +273,15 @@ describe Postzord::Dispatch do Resque.stub!(:enqueue).with(Job::PublishToHub, anything) Resque.should_receive(:enqueue).with(Job::PostToService, @s1.id, anything, anything) - mailman.post(:url => "http://joindiaspora.com/p/123", :services => [@s1, @s2]) + mailman.post(:url => "http://joindiaspora.com/p/123", :services => [@s1]) + end + + it 'does not push to services if none are specified' do + mailman = Postzord::Dispatch.new(@user, Factory(:status_message)) + + Resque.stub!(:enqueue).with(Job::PublishToHub, anything) + Resque.should_not_receive(:enqueue).with(Job::PostToService, anything, anything, anything) + mailman.post(:url => "http://joindiaspora.com/p/123") end end