DG MS renamed private dispatcher; started refactor including public

dispatcher
This commit is contained in:
Maxwell Salzberg 2011-09-12 16:25:37 -07:00
parent ca8a9e8025
commit 665facaeb0
54 changed files with 222 additions and 204 deletions

View file

@ -23,7 +23,7 @@ class CommentsController < ApplicationController
if @comment.save if @comment.save
Rails.logger.info(:event => :create, :type => :comment, :user => current_user.diaspora_handle, Rails.logger.info(:event => :create, :type => :comment, :user => current_user.diaspora_handle,
:status => :success, :comment => @comment.id, :chars => params[:text].length) :status => :success, :comment => @comment.id, :chars => params[:text].length)
Postzord::Dispatch.new(current_user, @comment).post Postzord::Dispatcher.new(current_user, @comment).post
respond_to do |format| respond_to do |format|
format.js{ render(:create, :status => 201)} format.js{ render(:create, :status => 201)}

View file

@ -33,7 +33,7 @@ class ConversationsController < ApplicationController
@conversation = Conversation.new(params[:conversation]) @conversation = Conversation.new(params[:conversation])
if @conversation.save if @conversation.save
Postzord::Dispatch.new(current_user, @conversation).post Postzord::Dispatcher.new(current_user, @conversation).post
flash[:notice] = I18n.t('conversations.create.sent') flash[:notice] = I18n.t('conversations.create.sent')
else else
flash[:error] = I18n.t('conversations.create.fail') flash[:error] = I18n.t('conversations.create.fail')

View file

@ -15,7 +15,7 @@ class LikesController < ApplicationController
if @like.save if @like.save
Rails.logger.info("event=create type=like user=#{current_user.diaspora_handle} status=success like=#{@like.id} positive=#{positive}") Rails.logger.info("event=create type=like user=#{current_user.diaspora_handle} status=success like=#{@like.id} positive=#{positive}")
Postzord::Dispatch.new(current_user, @like).post Postzord::Dispatcher.new(current_user, @like).post
respond_to do |format| respond_to do |format|
format.js { render 'likes/update', :status => 201 } format.js { render 'likes/update', :status => 201 }

View file

@ -18,7 +18,7 @@ class MessagesController < ApplicationController
if message.save if message.save
Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:message][:text].length}") Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:message][:text].length}")
Postzord::Dispatch.new(current_user, message).post Postzord::Dispatcher.new(current_user, message).post
else else
flash[:error] = I18n.t('conversations.new_message.fail') flash[:error] = I18n.t('conversations.new_message.fail')
end end

View file

@ -44,7 +44,7 @@ class Contact < ActiveRecord::Base
def dispatch_request def dispatch_request
request = self.generate_request request = self.generate_request
Postzord::Dispatch.new(self.user, request).post Postzord::Dispatcher.new(self.user, request).post
request request
end end

View file

@ -10,7 +10,7 @@ module Job
def self.perform(user_id, xml, salmon_author_id) def self.perform(user_id, xml, salmon_author_id)
user = User.find(user_id) user = User.find(user_id)
salmon_author = Person.find(salmon_author_id) salmon_author = Person.find(salmon_author_id)
zord = Postzord::Receiver.new(user, :person => salmon_author) zord = Postzord::Receiver::Private.new(user, :person => salmon_author)
zord.parse_and_receive(xml) zord.parse_and_receive(xml)
end end
end end

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require File.join(Rails.root, 'lib/postzord/receiver') require File.join(Rails.root, 'lib/postzord/receiver/private')
require File.join(Rails.root, 'lib/postzord/receiver/local_post_batch') require File.join(Rails.root, 'lib/postzord/receiver/local_post_batch')
module Job module Job

View file

@ -1,11 +1,10 @@
# Copyright (c) 2010, Diaspora Inc. This file is # Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require File.join(Rails.root, 'lib/postzord/receiver/private')
module Job module Job
class ReceivePublicSalmon < Base class ReceivePublicSalmon < Base
require File.join(Rails.root, 'lib/postzord/receiver')
@queue = :receive @queue = :receive

View file

@ -3,7 +3,7 @@
# the COPYRIGHT file. # the COPYRIGHT file.
require File.join(Rails.root, 'lib/postzord/receiver') require File.join(Rails.root, 'lib/postzord/receiver/private')
module Job module Job
class ReceiveSalmon < Base class ReceiveSalmon < Base
@queue = :receive_salmon @queue = :receive_salmon

View file

@ -33,7 +33,7 @@ class RelayableRetraction < SignedRetraction
elsif self.parent.author == recipient.person && self.target_author_signature_valid? elsif self.parent.author == recipient.person && self.target_author_signature_valid?
#this is a retraction from the downstream object creator, and the recipient is the upstream owner #this is a retraction from the downstream object creator, and the recipient is the upstream owner
self.parent_author_signature = self.sign_with_key(recipient.encryption_key) self.parent_author_signature = self.sign_with_key(recipient.encryption_key)
Postzord::Dispatch.new(recipient, self).post Postzord::Dispatcher.new(recipient, self).post
self.perform(recipient) self.perform(recipient)
elsif self.parent_author_signature_valid? elsif self.parent_author_signature_valid?
#this is a retraction from the upstream owner #this is a retraction from the upstream owner

View file

@ -67,7 +67,7 @@ class SignedRetraction
if reshare = Reshare.where(:author_id => receiving_user.person.id, :root_guid => target_guid).first if reshare = Reshare.where(:author_id => receiving_user.person.id, :root_guid => target_guid).first
onward_retraction = self.dup onward_retraction = self.dup
onward_retraction.sender = receiving_user.person onward_retraction.sender = receiving_user.person
Postzord::Dispatch.new(receiving_user, onward_retraction).post Postzord::Dispatcher.new(receiving_user, onward_retraction).post
end end
if target if target
self.target.unsocket_from_user receiving_user if target.respond_to? :unsocket_from_user self.target.unsocket_from_user receiving_user if target.respond_to? :unsocket_from_user

View file

@ -4,7 +4,7 @@
require File.join(Rails.root, 'lib/diaspora/user') require File.join(Rails.root, 'lib/diaspora/user')
require File.join(Rails.root, 'lib/salmon/salmon') require File.join(Rails.root, 'lib/salmon/salmon')
require File.join(Rails.root, 'lib/postzord/dispatch') require File.join(Rails.root, 'lib/postzord/dispatcher')
require 'rest-client' require 'rest-client'
class User < ActiveRecord::Base class User < ActiveRecord::Base
@ -186,14 +186,14 @@ class User < ActiveRecord::Base
def dispatch_post(post, opts = {}) def dispatch_post(post, opts = {})
additional_people = opts.delete(:additional_subscribers) additional_people = opts.delete(:additional_subscribers)
mailman = Postzord::Dispatch.new(self, post, :additional_subscribers => additional_people) mailman = Postzord::Dispatcher.new(self, post, :additional_subscribers => additional_people)
mailman.post(opts) mailman.post(opts)
end end
def update_post(post, post_hash = {}) def update_post(post, post_hash = {})
if self.owns? post if self.owns? post
post.update_attributes(post_hash) post.update_attributes(post_hash)
Postzord::Dispatch.new(self, post).post Postzord::Dispatcher.new(self, post).post
end end
end end
@ -292,7 +292,7 @@ class User < ActiveRecord::Base
opts[:additional_subscribers] = target.resharers opts[:additional_subscribers] = target.resharers
end end
mailman = Postzord::Dispatch.new(self, retraction, opts) mailman = Postzord::Dispatcher.new(self, retraction, opts)
mailman.post mailman.post
retraction.perform(self) retraction.perform(self)
@ -309,7 +309,7 @@ class User < ActiveRecord::Base
params[:image_url_small] = photo.url(:thumb_small) params[:image_url_small] = photo.url(:thumb_small)
end end
if self.person.profile.update_attributes(params) if self.person.profile.update_attributes(params)
Postzord::Dispatch.new(self, profile).post Postzord::Dispatcher.new(self, profile).post
true true
else else
false false

View file

@ -29,6 +29,9 @@ module Diaspora
# Add additional load paths for your own custom dirs # Add additional load paths for your own custom dirs
#config.autoload_paths += %W(#{config.root}/lib) #config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += %W(#{config.root}/lib) config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += %W(#{config.root}/lib/*)
config.autoload_paths += %W(#{config.root}/lib/*/*)
config.autoload_paths += %W(#{config.root}/lib/*/*/*)
# Only load the plugins named here, in the order given (default is alphabetical). # Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named # :all can be used as a placeholder for all plugins not explicitly named

View file

@ -58,7 +58,7 @@ module Diaspora
#dispatch object DOWNSTREAM, received it via UPSTREAM #dispatch object DOWNSTREAM, received it via UPSTREAM
unless user.owns?(comment_or_like) unless user.owns?(comment_or_like)
comment_or_like.save comment_or_like.save
Postzord::Dispatch.new(user, comment_or_like).post Postzord::Dispatcher.new(user, comment_or_like).post
end end
comment_or_like.socket_to_user(user) if comment_or_like.respond_to? :socket_to_user comment_or_like.socket_to_user(user) if comment_or_like.respond_to? :socket_to_user

View file

@ -61,7 +61,7 @@ module Diaspora
Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}") Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}")
retraction = Retraction.for(self) retraction = Retraction.for(self)
retraction.subscribers = [person]#HAX retraction.subscribers = [person]#HAX
Postzord::Dispatch.new(self, retraction).post Postzord::Dispatcher.new(self, retraction).post
AspectMembership.where(:contact_id => bad_contact.id).delete_all AspectMembership.where(:contact_id => bad_contact.id).delete_all
remove_contact(bad_contact) remove_contact(bad_contact)

View file

@ -0,0 +1,22 @@
# Copyright (c) 2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Postzord::Dispatcher
attr_reader :zord
delegate :post, :to => :zord
def initialize(user, object, opts={})
unless object.respond_to? :to_diaspora_xml
raise 'this object does not respond_to? to_diaspora xml. try including Diaspora::Webhooks into your object'
end
#if object.respond_to?(:public) && object.public?
# Postzord::Dispatcher::Public.new(user, object, opts)
#else
@zord = Postzord::Dispatcher::Private.new(user, object, opts)
#end
end
end

View file

@ -1,9 +1,8 @@
# Copyright (c) 2010, Diaspora Inc. This file is # Copyright (c) 2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
class Postzord::Dispatch class Postzord::Dispatcher::Private
# @note Takes :additional_subscribers param to add to subscribers to dispatch to # @note Takes :additional_subscribers param to add to subscribers to dispatch to
def initialize(user, object, opts={}) def initialize(user, object, opts={})
unless object.respond_to? :to_diaspora_xml unless object.respond_to? :to_diaspora_xml

View file

@ -1,93 +0,0 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
require File.join(Rails.root, 'lib/webfinger')
require File.join(Rails.root, 'lib/diaspora/parser')
module Postzord
class Receiver
def initialize(user, opts={})
@user = user
@user_person = @user.person
@salmon_xml = opts[:salmon_xml]
@sender = opts[:person] || Webfinger.new(self.salmon.author_email).fetch
@author = @sender
@object = opts[:object]
end
def perform
if @sender && self.salmon.verified_for_key?(@sender.public_key)
parse_and_receive(salmon.parsed_data)
else
Rails.logger.info("event=receive status=abort recipient=#{@user.diaspora_handle} sender=#{@salmon.author_email} reason='not_verified for key'")
nil
end
end
def parse_and_receive(xml)
@object ||= Diaspora::Parser.from_xml(xml)
Rails.logger.info("event=receive status=start recipient=#{@user_person.diaspora_handle} payload_type=#{@object.class} sender=#{@sender.diaspora_handle}")
if self.validate_object
receive_object
end
end
def receive_object
obj = @object.receive(@user, @author)
Notification.notify(@user, obj, @author) if obj.respond_to?(:notification_type)
Rails.logger.info("event=receive status=complete recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{obj.class}")
obj
end
protected
def salmon
@salmon ||= Salmon::EncryptedSlap.from_xml(@salmon_xml, @user)
end
def xml_author
if @object.respond_to?(:relayable?)
#if A and B are friends, and A sends B a comment from C, we delegate the validation to the owner of the post being commented on
xml_author = @user.owns?(@object.parent) ? @object.diaspora_handle : @object.parent.author.diaspora_handle
@author = Webfinger.new(@object.diaspora_handle).fetch if @object.author
else
xml_author = @object.diaspora_handle
end
xml_author
end
def validate_object
#begin similar
unless @object.is_a?(Request) || @user.contact_for(@sender)
Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
return false
end
#special casey
if @object.is_a?(Request)
@object.sender_handle = @sender.diaspora_handle
end
# abort if we haven't received the post to a comment
if @object.respond_to?(:relayable?) && @object.parent.nil?
Rails.logger.info("event=receive status=abort reason='received a comment but no corresponding post' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class})")
return false
end
if (@author.diaspora_handle != xml_author)
Rails.logger.info("event=receive status=abort reason='author in xml does not match retrieved person' payload_type=#{@object.class} recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
return false
end
if @author
@object.author = @author if @object.respond_to? :author=
@object.person = @author if @object.respond_to? :person=
end
@object
end
end
end

View file

@ -1,5 +1,5 @@
module Postzord module Postzord
class Receiver module Receiver
class LocalPostBatch class LocalPostBatch
attr_reader :post, :recipient_user_ids, :users attr_reader :post, :recipient_user_ids, :users

View file

@ -0,0 +1,95 @@
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
#
require File.join(Rails.root, 'lib/webfinger')
require File.join(Rails.root, 'lib/diaspora/parser')
module Postzord
module Receiver
class Private
def initialize(user, opts={})
@user = user
@user_person = @user.person
@salmon_xml = opts[:salmon_xml]
@sender = opts[:person] || Webfinger.new(self.salmon.author_email).fetch
@author = @sender
@object = opts[:object]
end
def perform
if @sender && self.salmon.verified_for_key?(@sender.public_key)
parse_and_receive(salmon.parsed_data)
else
Rails.logger.info("event=receive status=abort recipient=#{@user.diaspora_handle} sender=#{@salmon.author_email} reason='not_verified for key'")
nil
end
end
def parse_and_receive(xml)
@object ||= Diaspora::Parser.from_xml(xml)
Rails.logger.info("event=receive status=start recipient=#{@user_person.diaspora_handle} payload_type=#{@object.class} sender=#{@sender.diaspora_handle}")
if self.validate_object
receive_object
end
end
def receive_object
obj = @object.receive(@user, @author)
Notification.notify(@user, obj, @author) if obj.respond_to?(:notification_type)
Rails.logger.info("event=receive status=complete recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{obj.class}")
obj
end
protected
def salmon
@salmon ||= Salmon::EncryptedSlap.from_xml(@salmon_xml, @user)
end
def xml_author
if @object.respond_to?(:relayable?)
#if A and B are friends, and A sends B a comment from C, we delegate the validation to the owner of the post being commented on
xml_author = @user.owns?(@object.parent) ? @object.diaspora_handle : @object.parent.author.diaspora_handle
@author = Webfinger.new(@object.diaspora_handle).fetch if @object.author
else
xml_author = @object.diaspora_handle
end
xml_author
end
def validate_object
#begin similar
unless @object.is_a?(Request) || @user.contact_for(@sender)
Rails.logger.info("event=receive status=abort reason='sender not connected to recipient' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
return false
end
#special casey
if @object.is_a?(Request)
@object.sender_handle = @sender.diaspora_handle
end
# abort if we haven't received the post to a comment
if @object.respond_to?(:relayable?) && @object.parent.nil?
Rails.logger.info("event=receive status=abort reason='received a comment but no corresponding post' recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle} payload_type=#{@object.class})")
return false
end
if (@author.diaspora_handle != xml_author)
Rails.logger.info("event=receive status=abort reason='author in xml does not match retrieved person' payload_type=#{@object.class} recipient=#{@user_person.diaspora_handle} sender=#{@sender.diaspora_handle}")
return false
end
if @author
@object.author = @author if @object.respond_to? :author=
@object.person = @author if @object.respond_to? :person=
end
@object
end
end
end
end

View file

@ -3,7 +3,7 @@
# the COPYRIGHT file. # the COPYRIGHT file.
# #
module Postzord module Postzord
class Receiver module Receiver
class Public class Public
attr_accessor :salmon, :author attr_accessor :salmon, :author

View file

@ -94,8 +94,8 @@ describe ConversationsController do
} }
) )
p = Postzord::Dispatch.new(alice, cnv) p = Postzord::Dispatcher.new(alice, cnv)
Postzord::Dispatch.stub!(:new).and_return(p) Postzord::Dispatcher.stub!(:new).and_return(p)
p.should_receive(:post) p.should_receive(:post)
post :create, @hash post :create, @hash
end end

View file

@ -27,7 +27,7 @@ describe "attack vectors" do
bad_user.delete bad_user.delete
post_count = Post.count post_count = Post.count
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
user.visible_posts.include?(post_from_non_contact).should be_false user.visible_posts.include?(post_from_non_contact).should be_false
@ -46,7 +46,7 @@ describe "attack vectors" do
user3.contacts.create(:person => user2.person, :aspects => [user3.aspects.first]) user3.contacts.create(:person => user2.person, :aspects => [user3.aspects.first])
salmon_xml = user.salmon(original_message).xml_for(user3.person) salmon_xml = user.salmon(original_message).xml_for(user3.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
user3.reload.visible_posts.should_not include(StatusMessage.find(original_message.id)) user3.reload.visible_posts.should_not include(StatusMessage.find(original_message.id))
@ -64,12 +64,12 @@ describe "attack vectors" do
salmon_xml = user2.salmon(original_message).xml_for(user.person) salmon_xml = user2.salmon(original_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
malicious_message = Factory.build(:status_message, :id => original_message.id, :text => 'BAD!!!', :author => user3.person) malicious_message = Factory.build(:status_message, :id => original_message.id, :text => 'BAD!!!', :author => user3.person)
salmon_xml = user3.salmon(malicious_message).xml_for(user.person) salmon_xml = user3.salmon(malicious_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
original_message.reload.text.should == "store this!" original_message.reload.text.should == "store this!"
@ -79,14 +79,14 @@ describe "attack vectors" do
original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id
salmon_xml = user2.salmon(original_message).xml_for(user.person) salmon_xml = user2.salmon(original_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
lambda { lambda {
malicious_message = Factory.build( :status_message, :id => original_message.id, :text => 'BAD!!!', :author => user2.person) malicious_message = Factory.build( :status_message, :id => original_message.id, :text => 'BAD!!!', :author => user2.person)
salmon_xml2 = user3.salmon(malicious_message).xml_for(user.person) salmon_xml2 = user3.salmon(malicious_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
}.should_not change{user.reload.visible_posts.count} }.should_not change{user.reload.visible_posts.count}
@ -104,7 +104,7 @@ describe "attack vectors" do
first_name = user2.profile.first_name first_name = user2.profile.first_name
salmon_xml = user3.salmon(profile).xml_for(user.person) salmon_xml = user3.salmon(profile).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
user2.reload user2.reload
@ -116,7 +116,7 @@ describe "attack vectors" do
original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id
salmon_xml = user2.salmon(original_message).xml_for(user.person) salmon_xml = user2.salmon(original_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
user.visible_posts.count.should == 1 user.visible_posts.count.should == 1
@ -128,7 +128,7 @@ describe "attack vectors" do
ret.type = original_message.class.to_s ret.type = original_message.class.to_s
salmon_xml = user3.salmon(ret).xml_for(user.person) salmon_xml = user3.salmon(ret).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
StatusMessage.count.should == 1 StatusMessage.count.should == 1
@ -150,7 +150,7 @@ describe "attack vectors" do
StatusMessage.count.should == 0 StatusMessage.count.should == 0
proc { proc {
salmon_xml = user3.salmon(ret).xml_for(user.person) salmon_xml = user3.salmon(ret).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
}.should_not raise_error }.should_not raise_error
end end
@ -159,7 +159,7 @@ describe "attack vectors" do
original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id
salmon_xml = user2.salmon(original_message).xml_for(user.person) salmon_xml = user2.salmon(original_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
@ -173,7 +173,7 @@ describe "attack vectors" do
lambda { lambda {
salmon_xml = user3.salmon(ret).xml_for(user.person) salmon_xml = user3.salmon(ret).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
}.should_not change(StatusMessage, :count) }.should_not change(StatusMessage, :count)
@ -189,7 +189,7 @@ describe "attack vectors" do
proc{ proc{
salmon_xml = user3.salmon(ret).xml_for(user.person) salmon_xml = user3.salmon(ret).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
}.should_not change{user.reload.contacts.count} }.should_not change{user.reload.contacts.count}
@ -203,7 +203,7 @@ describe "attack vectors" do
proc{ proc{
salmon_xml = user3.salmon(ret).xml_for(user.person) salmon_xml = user3.salmon(ret).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
}.should_not change{user.reload.contacts.count} }.should_not change{user.reload.contacts.count}
end end
@ -212,7 +212,7 @@ describe "attack vectors" do
original_message = user2.post(:photo, :user_file => uploaded_photo, :text => "store this!", :to => aspect2.id) original_message = user2.post(:photo, :user_file => uploaded_photo, :text => "store this!", :to => aspect2.id)
salmon_xml = user2.salmon(original_message).xml_for(user.person) salmon_xml = user2.salmon(original_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
original_message.diaspora_handle = user3.diaspora_handle original_message.diaspora_handle = user3.diaspora_handle
@ -220,7 +220,7 @@ describe "attack vectors" do
salmon_xml = user3.salmon(original_message).xml_for(user.person) salmon_xml = user3.salmon(original_message).xml_for(user.person)
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml)
zord.perform zord.perform
original_message.reload.text.should == "store this!" original_message.reload.text.should == "store this!"

View file

@ -7,7 +7,7 @@ require 'spec_helper'
describe 'a user receives a post' do describe 'a user receives a post' do
def receive_with_zord(user, person, xml) def receive_with_zord(user, person, xml)
zord = Postzord::Receiver.new(user, :person => person) zord = Postzord::Receiver::Private.new(user, :person => person)
zord.parse_and_receive(xml) zord.parse_and_receive(xml)
end end
@ -25,7 +25,7 @@ describe 'a user receives a post' do
status = bob.build_post(:status_message, :text => "Users do things", :to => @bobs_aspect.id) status = bob.build_post(:status_message, :text => "Users do things", :to => @bobs_aspect.id)
Diaspora::WebSocket.stub!(:is_connected?).and_return(true) Diaspora::WebSocket.stub!(:is_connected?).and_return(true)
Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once) Diaspora::WebSocket.should_receive(:queue_to_user).exactly(:once)
zord = Postzord::Receiver.new(alice, :object => status, :person => bob.person) zord = Postzord::Receiver::Private.new(alice, :object => status, :person => bob.person)
zord.receive_object zord.receive_object
end end
@ -74,10 +74,10 @@ describe 'a user receives a post' do
bob.add_to_streams(@sm, [bob.aspects.first]) bob.add_to_streams(@sm, [bob.aspects.first])
@sm.save @sm.save
zord = Postzord::Receiver.new(alice, :object => @sm, :person => bob.person) zord = Postzord::Receiver::Private.new(alice, :object => @sm, :person => bob.person)
zord.receive_object zord.receive_object
zord = Postzord::Receiver.new(eve, :object => @sm, :person => bob.person) zord = Postzord::Receiver::Private.new(eve, :object => @sm, :person => bob.person)
zord.receive_object zord.receive_object
end end
@ -91,7 +91,7 @@ describe 'a user receives a post' do
@sm.stub!(:socket_to_user) @sm.stub!(:socket_to_user)
@sm.save @sm.save
zord = Postzord::Receiver.new(alice, :object => @sm, :person => bob.person) zord = Postzord::Receiver::Private.new(alice, :object => @sm, :person => bob.person)
zord.receive_object zord.receive_object
end end
@ -103,7 +103,7 @@ describe 'a user receives a post' do
eve.add_to_streams(@sm, [eve.aspects.first]) eve.add_to_streams(@sm, [eve.aspects.first])
@sm.save @sm.save
zord = Postzord::Receiver.new(alice, :object => @sm, :person => bob.person) zord = Postzord::Receiver::Private.new(alice, :object => @sm, :person => bob.person)
zord.receive_object zord.receive_object
end end
end end
@ -333,7 +333,7 @@ describe 'a user receives a post' do
it 'processes a salmon for a post' do it 'processes a salmon for a post' do
salmon_xml = salmon.xml_for(bob.person) salmon_xml = salmon.xml_for(bob.person)
zord = Postzord::Receiver.new(bob, :salmon_xml => salmon_xml) zord = Postzord::Receiver::Private.new(bob, :salmon_xml => salmon_xml)
zord.perform zord.perform
bob.visible_posts.include?(post).should be_true bob.visible_posts.include?(post).should be_true
@ -348,7 +348,7 @@ describe 'a user receives a post' do
xml = retraction.to_diaspora_xml xml = retraction.to_diaspora_xml
lambda { lambda {
zord = Postzord::Receiver.new(alice, :person => bob.person) zord = Postzord::Receiver::Private.new(alice, :person => bob.person)
zord.parse_and_receive(xml) zord.parse_and_receive(xml)
}.should change(StatusMessage, :count).by(-1) }.should change(StatusMessage, :count).by(-1)
end end
@ -370,7 +370,7 @@ describe 'a user receives a post' do
xml = new_profile.to_diaspora_xml xml = new_profile.to_diaspora_xml
#Marshal profile #Marshal profile
zord = Postzord::Receiver.new(alice, :person => person) zord = Postzord::Receiver::Private.new(alice, :person => person)
zord.parse_and_receive(xml) zord.parse_and_receive(xml)
#Check that marshaled profile is the same as old profile #Check that marshaled profile is the same as old profile

View file

@ -1,13 +1,12 @@
# Copyright (c) 2010, Diaspora Inc. This file is # Copyright (c) 2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require 'spec_helper' require 'spec_helper'
require File.join(Rails.root, 'lib/postzord') require File.join(Rails.root, 'lib/postzord/dispatcher/private')
require File.join(Rails.root, 'lib/postzord/dispatch')
describe Postzord::Dispatch do describe Postzord::Dispatcher::Private do
before do before do
@sm = Factory(:status_message, :public => true, :author => alice.person) @sm = Factory(:status_message, :public => true, :author => alice.person)
@subscribers = [] @subscribers = []
@ -18,7 +17,7 @@ describe Postzord::Dispatch do
describe '.initialize' do describe '.initialize' do
it 'takes an sender(User) and object (responds_to #subscibers) and sets then to @sender and @object' do it 'takes an sender(User) and object (responds_to #subscibers) and sets then to @sender and @object' do
zord = Postzord::Dispatch.new(alice, @sm) zord = Postzord::Dispatcher::Private.new(alice, @sm)
zord.instance_variable_get(:@sender).should == alice zord.instance_variable_get(:@sender).should == alice
zord.instance_variable_get(:@object).should == @sm zord.instance_variable_get(:@object).should == @sm
end end
@ -26,7 +25,7 @@ describe Postzord::Dispatch do
context 'setting @subscribers' do context 'setting @subscribers' do
it 'sets @subscribers from object' do it 'sets @subscribers from object' do
@sm.should_receive(:subscribers).and_return(@subscribers) @sm.should_receive(:subscribers).and_return(@subscribers)
zord = Postzord::Dispatch.new(alice, @sm) zord = Postzord::Dispatcher::Private.new(alice, @sm)
zord.instance_variable_get(:@subscribers).should == @subscribers zord.instance_variable_get(:@subscribers).should == @subscribers
end end
@ -34,24 +33,24 @@ describe Postzord::Dispatch do
new_person = Factory(:person) new_person = Factory(:person)
@sm.should_receive(:subscribers).and_return(@subscribers) @sm.should_receive(:subscribers).and_return(@subscribers)
zord = Postzord::Dispatch.new(alice, @sm, :additional_subscribers => new_person) zord = Postzord::Dispatcher::Private.new(alice, @sm, :additional_subscribers => new_person)
zord.instance_variable_get(:@subscribers).should == @subscribers | [new_person] zord.instance_variable_get(:@subscribers).should == @subscribers | [new_person]
end end
end end
it 'sets the @sender_person object' do it 'sets the @sender_person object' do
zord = Postzord::Dispatch.new(alice, @sm) zord = Postzord::Dispatcher::Private.new(alice, @sm)
zord.instance_variable_get(:@sender_person).should == alice.person zord.instance_variable_get(:@sender_person).should == alice.person
end end
it 'raises and gives you a helpful message if the object can not federate' do it 'raises and gives you a helpful message if the object can not federate' do
proc{ Postzord::Dispatch.new(alice, []) proc{ Postzord::Dispatcher::Private.new(alice, [])
}.should raise_error /Diaspora::Webhooks/ }.should raise_error /Diaspora::Webhooks/
end end
end end
it 'creates a salmon base object' do it 'creates a salmon base object' do
zord = Postzord::Dispatch.new(alice, @sm) zord = Postzord::Dispatcher::Private.new(alice, @sm)
zord.salmon.should_not be nil zord.salmon.should_not be nil
end end
@ -60,7 +59,7 @@ describe Postzord::Dispatch do
@subscribers << bob.person @subscribers << bob.person
@remote_people, @local_people = @subscribers.partition{ |person| person.owner_id.nil? } @remote_people, @local_people = @subscribers.partition{ |person| person.owner_id.nil? }
@sm.stub!(:subscribers).and_return @subscribers @sm.stub!(:subscribers).and_return @subscribers
@zord = Postzord::Dispatch.new(alice, @sm) @zord = Postzord::Dispatcher::Private.new(alice, @sm)
end end
describe '#post' do describe '#post' do
@ -99,7 +98,7 @@ describe Postzord::Dispatch do
end end
context "local leia's mailman" do context "local leia's mailman" do
before do before do
@mailman = Postzord::Dispatch.new(@local_leia, @comment) @mailman = Postzord::Dispatcher::Private.new(@local_leia, @comment)
end end
it 'calls deliver_to_local with local_luke' do it 'calls deliver_to_local with local_luke' do
@mailman.should_receive(:deliver_to_local).with([@local_luke.person]) @mailman.should_receive(:deliver_to_local).with([@local_luke.person])
@ -120,7 +119,7 @@ describe Postzord::Dispatch do
end end
context "local luke's mailman" do context "local luke's mailman" do
before do before do
@mailman = Postzord::Dispatch.new(@local_luke, @comment) @mailman = Postzord::Dispatcher::Private.new(@local_luke, @comment)
end end
it 'does not call deliver_to_local' do it 'does not call deliver_to_local' do
@mailman.should_not_receive(:deliver_to_local) @mailman.should_not_receive(:deliver_to_local)
@ -145,7 +144,7 @@ describe Postzord::Dispatch do
before do before do
@comment = Factory.build(:comment, :author => @remote_raphael, :post => @post) @comment = Factory.build(:comment, :author => @remote_raphael, :post => @post)
@comment.save @comment.save
@mailman = Postzord::Dispatch.new(@local_luke, @comment) @mailman = Postzord::Dispatcher::Private.new(@local_luke, @comment)
end end
it 'does not call deliver_to_local' do it 'does not call deliver_to_local' do
@mailman.should_not_receive(:deliver_to_local) @mailman.should_not_receive(:deliver_to_local)
@ -168,7 +167,7 @@ describe Postzord::Dispatch do
before do before do
@comment = @local_luke.build_comment :text => "yo", :post => @post @comment = @local_luke.build_comment :text => "yo", :post => @post
@comment.save @comment.save
@mailman = Postzord::Dispatch.new(@local_luke, @comment) @mailman = Postzord::Dispatcher::Private.new(@local_luke, @comment)
end end
it 'does not call deliver_to_local' do it 'does not call deliver_to_local' do
@mailman.should_not_receive(:deliver_to_local) @mailman.should_not_receive(:deliver_to_local)
@ -194,7 +193,7 @@ describe Postzord::Dispatch do
@post = Factory(:status_message, :author => @remote_raphael) @post = Factory(:status_message, :author => @remote_raphael)
@comment = @local_luke.build_comment :text => "yo", :post => @post @comment = @local_luke.build_comment :text => "yo", :post => @post
@comment.save @comment.save
@mailman = Postzord::Dispatch.new(@local_luke, @comment) @mailman = Postzord::Dispatcher::Private.new(@local_luke, @comment)
end end
it 'calls deliver_to_remote with remote_raphael' do it 'calls deliver_to_remote with remote_raphael' do
@mailman.should_receive(:deliver_to_remote).with([@remote_raphael]) @mailman.should_receive(:deliver_to_remote).with([@remote_raphael])
@ -219,7 +218,7 @@ describe Postzord::Dispatch do
before do before do
@remote_people = [] @remote_people = []
@remote_people << alice.person @remote_people << alice.person
@mailman = Postzord::Dispatch.new(alice, @sm) @mailman = Postzord::Dispatcher::Private.new(alice, @sm)
@hydra = mock() @hydra = mock()
Typhoeus::Hydra.stub!(:new).and_return(@hydra) Typhoeus::Hydra.stub!(:new).and_return(@hydra)
end end
@ -243,7 +242,7 @@ describe Postzord::Dispatch do
describe '#deliver_to_local' do describe '#deliver_to_local' do
before do before do
@mailman = Postzord::Dispatch.new(alice, @sm) @mailman = Postzord::Dispatcher::Private.new(alice, @sm)
end end
it 'queues a batch receive' do it 'queues a batch receive' do
@ -280,7 +279,7 @@ describe Postzord::Dispatch do
it 'does not push to hub for non-public posts' do it 'does not push to hub for non-public posts' do
@sm = Factory(:status_message) @sm = Factory(:status_message)
mailman = Postzord::Dispatch.new(alice, @sm) mailman = Postzord::Dispatcher::Private.new(alice, @sm)
mailman.should_not_receive(:deliver_to_hub) mailman.should_not_receive(:deliver_to_hub)
mailman.post(:url => "http://joindiaspora.com/p/123") mailman.post(:url => "http://joindiaspora.com/p/123")
@ -291,7 +290,7 @@ describe Postzord::Dispatch do
alice.services << @s1 alice.services << @s1
@s2 = Factory.create(:service, :user_id => alice.id) @s2 = Factory.create(:service, :user_id => alice.id)
alice.services << @s2 alice.services << @s2
mailman = Postzord::Dispatch.new(alice, Factory(:status_message)) mailman = Postzord::Dispatcher::Private.new(alice, Factory(:status_message))
Resque.stub!(:enqueue).with(Job::PublishToHub, anything) Resque.stub!(:enqueue).with(Job::PublishToHub, anything)
Resque.stub!(:enqueue).with(Job::HttpMulti, anything, anything, anything) Resque.stub!(:enqueue).with(Job::HttpMulti, anything, anything, anything)
@ -300,7 +299,7 @@ describe Postzord::Dispatch do
end end
it 'does not push to services if none are specified' do it 'does not push to services if none are specified' do
mailman = Postzord::Dispatch.new(alice, Factory(:status_message)) mailman = Postzord::Dispatcher::Private.new(alice, Factory(:status_message))
Resque.stub!(:enqueue).with(Job::PublishToHub, anything) Resque.stub!(:enqueue).with(Job::PublishToHub, anything)
Resque.should_not_receive(:enqueue).with(Job::PostToService, anything, anything, anything) Resque.should_not_receive(:enqueue).with(Job::PostToService, anything, anything, anything)
@ -323,7 +322,7 @@ describe Postzord::Dispatch do
f.stub!(:subscribers) f.stub!(:subscribers)
f.stub!(:to_diaspora_xml) f.stub!(:to_diaspora_xml)
users = [bob] users = [bob]
z = Postzord::Dispatch.new(alice, f) z = Postzord::Dispatcher::Private.new(alice, f)
z.instance_variable_get(:@object).should_receive(:socket_to_user).once z.instance_variable_get(:@object).should_receive(:socket_to_user).once
z.send(:socket_to_users, users) z.send(:socket_to_users, users)
end end

View file

@ -5,9 +5,9 @@
require 'spec_helper' require 'spec_helper'
require File.join(Rails.root, 'lib/postzord') require File.join(Rails.root, 'lib/postzord')
require File.join(Rails.root, 'lib/postzord/receiver') require File.join(Rails.root, 'lib/postzord/receiver/private')
describe Postzord::Receiver do describe Postzord::Receiver::Private do
before do before do
@user = alice @user = alice
@ -26,7 +26,7 @@ describe Postzord::Receiver do
Webfinger.should_not_receive(:new) Webfinger.should_not_receive(:new)
Salmon::EncryptedSlap.should_not_receive(:from_xml) Salmon::EncryptedSlap.should_not_receive(:from_xml)
zord = Postzord::Receiver.new(@user, :person => @person2, :object => @original_post) zord = Postzord::Receiver::Private.new(@user, :person => @person2, :object => @original_post)
zord.instance_variable_get(:@user).should_not be_nil zord.instance_variable_get(:@user).should_not be_nil
zord.instance_variable_get(:@sender).should_not be_nil zord.instance_variable_get(:@sender).should_not be_nil
zord.instance_variable_get(:@object).should_not be_nil zord.instance_variable_get(:@object).should_not be_nil
@ -40,7 +40,7 @@ describe Postzord::Receiver do
Salmon::EncryptedSlap.should_receive(:from_xml).with(@salmon_xml, @user).and_return(salmon_mock) Salmon::EncryptedSlap.should_receive(:from_xml).with(@salmon_xml, @user).and_return(salmon_mock)
Webfinger.should_receive(:new).and_return(web_mock) Webfinger.should_receive(:new).and_return(web_mock)
zord = Postzord::Receiver.new(@user, :salmon_xml => @salmon_xml) zord = Postzord::Receiver::Private.new(@user, :salmon_xml => @salmon_xml)
zord.instance_variable_get(:@user).should_not be_nil zord.instance_variable_get(:@user).should_not be_nil
zord.instance_variable_get(:@sender).should_not be_nil zord.instance_variable_get(:@sender).should_not be_nil
zord.instance_variable_get(:@salmon_xml).should_not be_nil zord.instance_variable_get(:@salmon_xml).should_not be_nil
@ -49,7 +49,7 @@ describe Postzord::Receiver do
describe '#perform' do describe '#perform' do
before do before do
@zord = Postzord::Receiver.new(@user, :salmon_xml => @salmon_xml) @zord = Postzord::Receiver::Private.new(@user, :salmon_xml => @salmon_xml)
@salmon = @zord.instance_variable_get(:@salmon) @salmon = @zord.instance_variable_get(:@salmon)
end end
@ -80,7 +80,7 @@ describe Postzord::Receiver do
describe 'receive_object' do describe 'receive_object' do
before do before do
@zord = Postzord::Receiver.new(@user, :person => @person2, :object => @original_post) @zord = Postzord::Receiver::Private.new(@user, :person => @person2, :object => @original_post)
@salmon = @zord.instance_variable_get(:@salmon) @salmon = @zord.instance_variable_get(:@salmon)
end end
@ -89,7 +89,7 @@ describe Postzord::Receiver do
cm.stub!(:receive).and_return(cm) cm.stub!(:receive).and_return(cm)
Notification.should_receive(:notify).with(@user, cm, @person2) Notification.should_receive(:notify).with(@user, cm, @person2)
zord = Postzord::Receiver.new(@user, :person => @person2, :object => cm) zord = Postzord::Receiver::Private.new(@user, :person => @person2, :object => cm)
zord.receive_object zord.receive_object
end end

View file

@ -56,7 +56,7 @@ describe 'making sure the spec runner works' do
person_status = Factory.create(:status_message, :author => person) person_status = Factory.create(:status_message, :author => person)
m = mock() m = mock()
m.stub!(:post) m.stub!(:post)
Postzord::Dispatch.should_receive(:new).and_return(m) Postzord::Dispatcher.should_receive(:new).and_return(m)
alice.comment "yo", :post => person_status alice.comment "yo", :post => person_status
end end

View file

@ -169,7 +169,7 @@ describe Contact do
@contact.stub(:user).and_return(@user) @contact.stub(:user).and_return(@user)
m = mock() m = mock()
m.should_receive(:post) m.should_receive(:post)
Postzord::Dispatch.should_receive(:new).and_return(m) Postzord::Dispatcher.should_receive(:new).and_return(m)
@contact.dispatch_request @contact.dispatch_request
end end
end end

View file

@ -17,7 +17,7 @@ describe Job::Receive do
it 'calls receive' do it 'calls receive' do
zord_mock = mock() zord_mock = mock()
zord_mock.should_receive(:parse_and_receive).with(@xml) zord_mock.should_receive(:parse_and_receive).with(@xml)
Postzord::Receiver.should_receive(:new).with(@user, anything).and_return(zord_mock) Postzord::Receiver::Private.should_receive(:new).with(@user, anything).and_return(zord_mock)
Job::Receive.perform(@user.id, @xml, @person.id) Job::Receive.perform(@user.id, @xml, @person.id)
end end
end end

View file

@ -82,7 +82,7 @@ describe Message do
msg_hash = {:author => @local_luke.person, :text => 'yo', :conversation => @local_parent} msg_hash = {:author => @local_luke.person, :text => 'yo', :conversation => @local_parent}
@object_by_parent_author = Message.create(msg_hash.dup) @object_by_parent_author = Message.create(msg_hash.dup)
Postzord::Dispatch.new(@local_luke, @object_by_parent_author).post Postzord::Dispatcher.new(@local_luke, @object_by_parent_author).post
msg_hash[:author] = @local_leia.person msg_hash[:author] = @local_leia.person
@object_by_recipient = Message.create(msg_hash.dup) @object_by_recipient = Message.create(msg_hash.dup)
@ -92,7 +92,7 @@ describe Message do
msg_hash[:author] = @local_luke.person msg_hash[:author] = @local_luke.person
msg_hash[:conversation] = @remote_parent msg_hash[:conversation] = @remote_parent
@object_on_remote_parent = Message.create(msg_hash) @object_on_remote_parent = Message.create(msg_hash)
Postzord::Dispatch.new(@local_luke, @object_on_remote_parent).post Postzord::Dispatcher.new(@local_luke, @object_on_remote_parent).post
end end
it_should_behave_like 'it is relayable' it_should_behave_like 'it is relayable'

View file

@ -119,15 +119,12 @@ describe Notification do
end end
end end
context 'multiple people' do context 'multiple people' do
before do before do
@user3 = bob @user3 = bob
@sm = @user3.post(:status_message, :text => "comment!", :to => :all) @sm = @user3.post(:status_message, :text => "comment!", :to => :all)
Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :post => @sm)).receive_object Postzord::Receiver::Private.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :post => @sm)).receive_object
Postzord::Receiver.new(@user3, :person => @user.person, :object => @user.comment("hey", :post => @sm)).receive_object Postzord::Receiver::Private.new(@user3, :person => @user.person, :object => @user.comment("hey", :post => @sm)).receive_object
end end
it "updates the notification with a more people if one already exists" do it "updates the notification with a more people if one already exists" do
@ -135,10 +132,9 @@ describe Notification do
end end
it 'handles double comments from the same person without raising' do it 'handles double comments from the same person without raising' do
Postzord::Receiver.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :post => @sm)).receive_object Postzord::Receiver::Private.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :post => @sm)).receive_object
Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :target_id => @sm.id).first.actors.count.should == 2 Notification.where(:recipient_id => @user3.id, :target_type => @sm.class.base_class, :target_id => @sm.id).first.actors.count.should == 2
end end
end end
end end
end end

View file

@ -164,7 +164,7 @@ describe Photo do
xml = @photo.to_diaspora_xml xml = @photo.to_diaspora_xml
@photo.destroy @photo.destroy
zord = Postzord::Receiver.new(user2, :person => @photo.author) zord = Postzord::Receiver::Private.new(user2, :person => @photo.author)
zord.parse_and_receive(xml) zord.parse_and_receive(xml)
new_photo = Photo.where(:guid => @photo.guid).first new_photo = Photo.where(:guid => @photo.guid).first

View file

@ -49,7 +49,7 @@ describe RelayableRetraction do
it 'dispatches' do it 'dispatches' do
zord = mock() zord = mock()
zord.should_receive(:post) zord.should_receive(:post)
Postzord::Dispatch.should_receive(:new).with(@local_luke, @retraction).and_return zord Postzord::Dispatcher.should_receive(:new).with(@local_luke, @retraction).and_return zord
@retraction.receive(@recipient, @comment.author) @retraction.receive(@recipient, @comment.author)
end end
it 'performs' do it 'performs' do
@ -71,7 +71,7 @@ describe RelayableRetraction do
@retraction.receive(@recipient, @remote_raphael) @retraction.receive(@recipient, @remote_raphael)
end end
it 'does not dispatch' do it 'does not dispatch' do
Postzord::Dispatch.should_not_receive(:new) Postzord::Dispatcher.should_not_receive(:new)
@retraction.receive(@recipient, @remote_raphael) @retraction.receive(@recipient, @remote_raphael)
end end
end end

View file

@ -14,7 +14,7 @@ describe SignedRetraction do
retraction.should_receive(:dup).and_return(onward_retraction) retraction.should_receive(:dup).and_return(onward_retraction)
dis = mock dis = mock
Postzord::Dispatch.should_receive(:new).with(@resharer, onward_retraction).and_return(dis) Postzord::Dispatcher.should_receive(:new).with(@resharer, onward_retraction).and_return(dis)
dis.should_receive(:post) dis.should_receive(:post)
retraction.perform(@resharer) retraction.perform(@resharer)
@ -35,7 +35,7 @@ describe SignedRetraction do
Post.exists?(:id => remote_post.id).should be_false Post.exists?(:id => remote_post.id).should be_false
dis = mock dis = mock
Postzord::Dispatch.should_receive(:new){ |sender, retraction| Postzord::Dispatcher.should_receive(:new){ |sender, retraction|
sender.should == alice sender.should == alice
retraction.sender.should == alice.person retraction.sender.should == alice.person
dis dis

View file

@ -58,7 +58,7 @@ describe Diaspora::UserModules::Connecting do
it 'dispatches a retraction' do it 'dispatches a retraction' do
p = mock() p = mock()
Postzord::Dispatch.should_receive(:new).and_return(p) Postzord::Dispatcher.should_receive(:new).and_return(p)
p.should_receive(:post) p.should_receive(:post)
bob.disconnect bob.contact_for(eve.person) bob.disconnect bob.contact_for(eve.person)

View file

@ -440,16 +440,14 @@ describe User do
it 'dispatches the profile when tags are set' do it 'dispatches the profile when tags are set' do
@params = {:tags => '#what #hey'} @params = {:tags => '#what #hey'}
mailman = Postzord::Dispatch.new(alice, Profile.new) mailman = Postzord::Dispatcher.new(alice, Profile.new)
Postzord::Dispatch.should_receive(:new).and_return(mailman) Postzord::Dispatcher.should_receive(:new).and_return(mailman)
mailman.should_receive(:deliver_to_local)
alice.update_profile(@params).should be_true alice.update_profile(@params).should be_true
end end
it 'sends a profile to their contacts' do it 'sends a profile to their contacts' do
mailman = Postzord::Dispatch.new(alice, Profile.new) mailman = Postzord::Dispatcher.new(alice, Profile.new)
Postzord::Dispatch.should_receive(:new).and_return(mailman) Postzord::Dispatcher.should_receive(:new).and_return(mailman)
mailman.should_receive(:deliver_to_local)
alice.update_profile(@params).should be_true alice.update_profile(@params).should be_true
end end
@ -498,7 +496,7 @@ describe User do
it 'sends a notification to aspects' do it 'sends a notification to aspects' do
m = mock() m = mock()
m.should_receive(:post) m.should_receive(:post)
Postzord::Dispatch.should_receive(:new).and_return(m) Postzord::Dispatcher.should_receive(:new).and_return(m)
photo = alice.build_post(:photo, :user_file => uploaded_photo, :text => "hello", :to => alice.aspects.first.id) photo = alice.build_post(:photo, :user_file => uploaded_photo, :text => "hello", :to => alice.aspects.first.id)
alice.update_post(photo, :text => 'hellp') alice.update_post(photo, :text => 'hellp')
end end
@ -950,7 +948,7 @@ describe User do
it 'sends a retraction' do it 'sends a retraction' do
dispatcher = mock dispatcher = mock
Postzord::Dispatch.should_receive(:new).with(bob, @retraction, anything()).and_return(dispatcher) Postzord::Dispatcher.should_receive(:new).with(bob, @retraction, anything()).and_return(dispatcher)
dispatcher.should_receive(:post) dispatcher.should_receive(:post)
bob.retract(@post) bob.retract(@post)
@ -962,7 +960,7 @@ describe User do
@post.reshares << reshare @post.reshares << reshare
dispatcher = mock dispatcher = mock
Postzord::Dispatch.should_receive(:new).with(bob, @retraction, {:additional_subscribers => [person]}).and_return(dispatcher) Postzord::Dispatcher.should_receive(:new).with(bob, @retraction, {:additional_subscribers => [person]}).and_return(dispatcher)
dispatcher.should_receive(:post) dispatcher.should_receive(:post)
bob.retract(@post) bob.retract(@post)

View file

@ -60,9 +60,9 @@ describe Diaspora::Relayable do
end end
it 'dispatches when the person receiving is the parent author' do it 'dispatches when the person receiving is the parent author' do
p = Postzord::Dispatch.new(@local_luke, @object_by_recipient) p = Postzord::Dispatcher.new(@local_luke, @object_by_recipient)
p.should_receive(:post) p.should_receive(:post)
Postzord::Dispatch.stub!(:new).and_return(p) Postzord::Dispatcher.stub!(:new).and_return(p)
@object_by_recipient.receive(@local_luke, @local_leia.person) @object_by_recipient.receive(@local_luke, @local_leia.person)
end end

View file

@ -36,7 +36,7 @@ class User
fantasy_resque do fantasy_resque do
c = build_comment(options.merge(:text => text)) c = build_comment(options.merge(:text => text))
if c.save! if c.save!
Postzord::Dispatch.new(self, c).post Postzord::Dispatcher.new(self, c).post
end end
c c
end end
@ -46,7 +46,7 @@ class User
fantasy_resque do fantasy_resque do
l = build_like(options.merge(:positive => positive)) l = build_like(options.merge(:positive => positive))
if l.save! if l.save!
Postzord::Dispatch.new(self, l).post Postzord::Dispatcher.new(self, l).post
end end
l l
end end