Skip to content
Extraits de code Groupes Projets
Valider 126925f2 rédigé par zhitomirskiyi's avatar zhitomirskiyi
Parcourir les fichiers

wip

parent 78b242b1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter