comments do not queue up jobs for local users.

This commit is contained in:
danielvincent 2011-01-08 17:53:01 -08:00
parent f2f3059d72
commit c16d0c46a2
2 changed files with 20 additions and 9 deletions

View file

@ -18,16 +18,18 @@ class Postzord::Dispatch
def post(opts = {}) def post(opts = {})
unless @subscribers == nil unless @subscribers == nil
remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? } remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? }
if @object.is_a?(Comment) if @object.is_a?(Comment)
user_ids = [*local_people].map{|x| x.owner_id } user_ids = [*local_people].map{|x| x.owner_id }
local_users = User.all(:id.in => user_ids, :fields => ['person_id, username, language, email']) local_users = User.all(:id.in => user_ids, :fields => ['person_id, username, language, email'])
self.socket_to_users(local_users) self.socket_to_users(local_users)
else
self.deliver_to_local(local_people)
end end
self.deliver_to_remote(remote_people) self.deliver_to_remote(remote_people)
self.deliver_to_local(local_people)
end end
self.deliver_to_services(opts[:url]) self.deliver_to_services(opts[:url])
end end
protected protected

View file

@ -82,14 +82,23 @@ describe Postzord::Dispatch do
mailman.should_receive(:socket_to_users) mailman.should_receive(:socket_to_users)
mailman.post mailman.post
end 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 end
describe '#deliver_to_remote' do describe '#deliver_to_remote' do
before do before do
@remote_people = [] @remote_people = []
@remote_people << @user.person @remote_people << @user.person
@mailman = Postzord::Dispatch.new(@user, @sm) @mailman = Postzord::Dispatch.new(@user, @sm)
end end
it 'should queue an HttpPost job for each remote person' do 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 it 'only pushes to services if the object is public' do
mailman = Postzord::Dispatch.new(@user, Factory(:status_message)) mailman = Postzord::Dispatch.new(@user, Factory(:status_message))
mailman.should_not_receive(:deliver_to_hub) mailman.should_not_receive(:deliver_to_hub)
mailman.instance_variable_get(:@sender).should_not_receive(:services) mailman.instance_variable_get(:@sender).should_not_receive(:services)
end end
@ -147,13 +156,13 @@ describe Postzord::Dispatch do
@zord.instance_variable_get(:@object).should_receive(:socket_to_uid) @zord.instance_variable_get(:@object).should_receive(:socket_to_uid)
@zord.send(:socket_to_users, [@local_user]) @zord.send(:socket_to_users, [@local_user])
end end
it 'only tries to socket when the object responds to #socket_to_uid' do it 'only tries to socket when the object responds to #socket_to_uid' do
f = Request.new f = Request.new
f.stub!(:subscribers) f.stub!(:subscribers)
users = [@user] users = [@user]
z = Postzord::Dispatch.new(@user, f) 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) z.send(:socket_to_users, users)
end end
end end