This commit is contained in:
zhitomirskiyi 2011-02-20 19:30:37 -08:00
parent 78b242b110
commit 126925f28f
4 changed files with 27 additions and 15 deletions

View file

@ -25,7 +25,7 @@ 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))
current_user.dispatch_post(@status_message, :url => post_url(@status_message), :services => current_user.services)
if !photos.empty?
for photo in photos
was_pending = photo.pending

View file

@ -34,7 +34,7 @@ class Postzord::Dispatch
self.deliver_to_remote(remote_people)
end
self.deliver_to_services(opts[:url])
self.deliver_to_services(opts[:url], opts[:services] || [])
end
protected
@ -55,11 +55,11 @@ class Postzord::Dispatch
Resque.enqueue(Job::PublishToHub, @sender.public_url)
end
def deliver_to_services(url)
def deliver_to_services(url, services)
if @object.respond_to?(:public) && @object.public
deliver_to_hub
if @object.respond_to?(:message)
@sender.services.each do |service|
services.each do |service|
Resque.enqueue(Job::PostToService, service.id, @object.id, url)
end
end

View file

@ -64,6 +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))
post :create, status_message_hash
end
it "doesn't overwrite person_id" do
status_message_hash[:status_message][:person_id] = @user2.person.id
post :create, status_message_hash

View file

@ -250,24 +250,30 @@ describe Postzord::Dispatch do
@user.services << @service
end
it 'calls post for each of the users services' do
Resque.stub!(:enqueue).with(Job::PublishToHub, anything)
Resque.should_receive(:enqueue).with(Job::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(Job::PostToService, anything, anything, anything)
Resque.should_receive(:enqueue).with(Job::PublishToHub, @user.public_url)
@zord.send(:deliver_to_services, nil)
@zord.send(:deliver_to_services, nil, [])
end
it 'only pushes to services if the object is public' do
mailman = Postzord::Dispatch.new(@user, Factory(:status_message))
it 'does not push to hub for non-public posts' do
@sm = Factory(:status_message)
mailman = Postzord::Dispatch.new(@user, @sm)
mailman.should_not_receive(:deliver_to_hub)
mailman.instance_variable_get(:@sender).should_not_receive(:services)
mailman.post(:url => "http://joindiaspora.com/p/123")
end
it 'only pushes to specified services' do
@s1 = Factory.create(:service, :user_id => @user.id)
@user.services << @s1
@s2 = Factory.create(:service, :user_id => @user.id)
@user.services << @s2
mailman = Postzord::Dispatch.new(@user, Factory(:status_message))
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])
end
end