if you write jobs, you should use them in you app

This commit is contained in:
maxwell 2011-01-07 14:03:46 -08:00
parent 868cb1efc1
commit 8f1f01f0a3
2 changed files with 5 additions and 3 deletions

View file

@ -19,7 +19,7 @@ class Postzord::Dispatch
unless @subscribers == nil
remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? }
user_ids = [*local_people].map{|x| x.owner_id }
local_users = User.all(:id.in => user_ids)
local_users = User.all(:id.in => user_ids, :fields => ['person_id, username, language, email'])
self.socket_to_users(local_users)
self.deliver_to_remote(remote_people)
self.deliver_to_local(local_people)
@ -53,7 +53,7 @@ class Postzord::Dispatch
deliver_to_hub
if @object.respond_to?(:message)
@sender.services.each do |service|
service.post(@object, url)
Resque.enqueue(Jobs::PostToService, service.id, @object.id, url)
end
end
end

View file

@ -119,12 +119,14 @@ describe Postzord::Dispatch do
end
it 'calls post for each of the users services' do
@service.should_receive(:post).once
Resque.stub!(:enqueue).with(Jobs::PublishToHub, anything)
Resque.should_receive(:enqueue).with(Jobs::PostToService, @service.id, anything, anything).once
@zord.instance_variable_get(:@sender).should_receive(:services).and_return([@service])
@zord.send(:deliver_to_services, nil)
end
it 'queues a job to notify the hub' do
Resque.stub!(:enqueue).with(Jobs::PostToService, anything, anything, anything)
Resque.should_receive(:enqueue).with(Jobs::PublishToHub, @user.public_url)
@zord.send(:deliver_to_services, nil)
end