From c16d0c46a297087045b3695693ed4866273fc259 Mon Sep 17 00:00:00 2001 From: danielvincent Date: Sat, 8 Jan 2011 17:53:01 -0800 Subject: [PATCH] comments do not queue up jobs for local users. --- lib/postzord/dispatch.rb | 8 +++++--- spec/lib/postzord/dispatch_spec.rb | 21 +++++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatch.rb index 8295963c8..96db24f0e 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatch.rb @@ -18,16 +18,18 @@ class Postzord::Dispatch def post(opts = {}) unless @subscribers == nil remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? } - + if @object.is_a?(Comment) user_ids = [*local_people].map{|x| x.owner_id } local_users = User.all(:id.in => user_ids, :fields => ['person_id, username, language, email']) self.socket_to_users(local_users) + else + self.deliver_to_local(local_people) end + self.deliver_to_remote(remote_people) - self.deliver_to_local(local_people) end - self.deliver_to_services(opts[:url]) + self.deliver_to_services(opts[:url]) end protected diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatch_spec.rb index cae8d18ac..46ef9f62c 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatch_spec.rb @@ -82,14 +82,23 @@ describe Postzord::Dispatch do mailman.should_receive(:socket_to_users) mailman.post end + + it 'does not call deliver_to_local if the object is a comment' do + comment = @local_user.comment "yo", :on => Factory(:status_message) + comment.should_receive(:subscribers).and_return([@local_user]) + mailman = Postzord::Dispatch.new(@user, comment) + mailman.should_receive(:socket_to_users) + mailman.should_not_receive(:deliver_to_local) + mailman.post + end end - + describe '#deliver_to_remote' do - + before do @remote_people = [] @remote_people << @user.person - @mailman = Postzord::Dispatch.new(@user, @sm) + @mailman = Postzord::Dispatch.new(@user, @sm) end it 'should queue an HttpPost job for each remote person' do @@ -136,7 +145,7 @@ describe Postzord::Dispatch do it 'only pushes to services if the object is public' do mailman = Postzord::Dispatch.new(@user, Factory(:status_message)) - + mailman.should_not_receive(:deliver_to_hub) mailman.instance_variable_get(:@sender).should_not_receive(:services) end @@ -147,13 +156,13 @@ describe Postzord::Dispatch do @zord.instance_variable_get(:@object).should_receive(:socket_to_uid) @zord.send(:socket_to_users, [@local_user]) end - + it 'only tries to socket when the object responds to #socket_to_uid' do f = Request.new f.stub!(:subscribers) users = [@user] z = Postzord::Dispatch.new(@user, f) - users.should_not_receive(:each) # checking if each is called due to respond_to, actually trying to + users.should_not_receive(:each) # checking if each is called due to respond_to, actually trying to z.send(:socket_to_users, users) end end