diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 8f591d9af..3020a6014 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -23,7 +23,7 @@ class CommentsController < ApplicationController if @comment.save Rails.logger.info(:event => :create, :type => :comment, :user => current_user.diaspora_handle, :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| format.js{ render(:create, :status => 201)} diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index 93342958f..5baf9a9b9 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -33,7 +33,7 @@ class ConversationsController < ApplicationController @conversation = Conversation.new(params[:conversation]) if @conversation.save - Postzord::Dispatch.new(current_user, @conversation).post + Postzord::Dispatcher.new(current_user, @conversation).post flash[:notice] = I18n.t('conversations.create.sent') else flash[:error] = I18n.t('conversations.create.fail') diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 251f0c3e3..392842985 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -15,7 +15,7 @@ class LikesController < ApplicationController if @like.save 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| format.js { render 'likes/update', :status => 201 } diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index c6f656166..9aedb43b5 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -18,7 +18,7 @@ class MessagesController < ApplicationController 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}") - Postzord::Dispatch.new(current_user, message).post + Postzord::Dispatcher.new(current_user, message).post else flash[:error] = I18n.t('conversations.new_message.fail') end diff --git a/app/models/contact.rb b/app/models/contact.rb index e4e18fd62..b34362842 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -44,7 +44,7 @@ class Contact < ActiveRecord::Base def dispatch_request request = self.generate_request - Postzord::Dispatch.new(self.user, request).post + Postzord::Dispatcher.new(self.user, request).post request end diff --git a/app/models/job/receive.rb b/app/models/job/receive.rb index 8b675c675..074408ca8 100644 --- a/app/models/job/receive.rb +++ b/app/models/job/receive.rb @@ -10,7 +10,7 @@ module Job def self.perform(user_id, xml, salmon_author_id) user = User.find(user_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) end end diff --git a/app/models/job/receive_local_batch.rb b/app/models/job/receive_local_batch.rb index f5689e797..4300f0866 100644 --- a/app/models/job/receive_local_batch.rb +++ b/app/models/job/receive_local_batch.rb @@ -2,7 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # 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') module Job diff --git a/app/models/job/receive_public_salmon.rb b/app/models/job/receive_public_salmon.rb index d7f700576..26d3173ef 100644 --- a/app/models/job/receive_public_salmon.rb +++ b/app/models/job/receive_public_salmon.rb @@ -1,11 +1,10 @@ # 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/postzord/receiver/private') module Job class ReceivePublicSalmon < Base - require File.join(Rails.root, 'lib/postzord/receiver') @queue = :receive diff --git a/app/models/job/receive_salmon.rb b/app/models/job/receive_salmon.rb index 5c854bfec..ed5a713c8 100644 --- a/app/models/job/receive_salmon.rb +++ b/app/models/job/receive_salmon.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. -require File.join(Rails.root, 'lib/postzord/receiver') +require File.join(Rails.root, 'lib/postzord/receiver/private') module Job class ReceiveSalmon < Base @queue = :receive_salmon diff --git a/app/models/relayable_retraction.rb b/app/models/relayable_retraction.rb index d2218af68..371edf2fc 100644 --- a/app/models/relayable_retraction.rb +++ b/app/models/relayable_retraction.rb @@ -33,7 +33,7 @@ class RelayableRetraction < SignedRetraction 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 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) elsif self.parent_author_signature_valid? #this is a retraction from the upstream owner diff --git a/app/models/signed_retraction.rb b/app/models/signed_retraction.rb index ea152ab76..18e12848d 100644 --- a/app/models/signed_retraction.rb +++ b/app/models/signed_retraction.rb @@ -67,7 +67,7 @@ class SignedRetraction if reshare = Reshare.where(:author_id => receiving_user.person.id, :root_guid => target_guid).first onward_retraction = self.dup onward_retraction.sender = receiving_user.person - Postzord::Dispatch.new(receiving_user, onward_retraction).post + Postzord::Dispatcher.new(receiving_user, onward_retraction).post end if target self.target.unsocket_from_user receiving_user if target.respond_to? :unsocket_from_user diff --git a/app/models/user.rb b/app/models/user.rb index 4b1e8684b..2080ef511 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,7 +4,7 @@ require File.join(Rails.root, 'lib/diaspora/user') 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' class User < ActiveRecord::Base @@ -186,14 +186,14 @@ class User < ActiveRecord::Base def dispatch_post(post, opts = {}) 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) end def update_post(post, post_hash = {}) if self.owns? post post.update_attributes(post_hash) - Postzord::Dispatch.new(self, post).post + Postzord::Dispatcher.new(self, post).post end end @@ -292,7 +292,7 @@ class User < ActiveRecord::Base opts[:additional_subscribers] = target.resharers end - mailman = Postzord::Dispatch.new(self, retraction, opts) + mailman = Postzord::Dispatcher.new(self, retraction, opts) mailman.post retraction.perform(self) @@ -309,7 +309,7 @@ class User < ActiveRecord::Base params[:image_url_small] = photo.url(:thumb_small) end if self.person.profile.update_attributes(params) - Postzord::Dispatch.new(self, profile).post + Postzord::Dispatcher.new(self, profile).post true else false diff --git a/config/application.rb b/config/application.rb index d5cf71334..8ca302ed7 100644 --- a/config/application.rb +++ b/config/application.rb @@ -29,6 +29,9 @@ module Diaspora # 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/*/*/*) # 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 diff --git a/lib/diaspora/relayable.rb b/lib/diaspora/relayable.rb index 08ad4a8bd..d5b85263a 100644 --- a/lib/diaspora/relayable.rb +++ b/lib/diaspora/relayable.rb @@ -58,7 +58,7 @@ module Diaspora #dispatch object DOWNSTREAM, received it via UPSTREAM unless user.owns?(comment_or_like) comment_or_like.save - Postzord::Dispatch.new(user, comment_or_like).post + Postzord::Dispatcher.new(user, comment_or_like).post end comment_or_like.socket_to_user(user) if comment_or_like.respond_to? :socket_to_user diff --git a/lib/diaspora/user/connecting.rb b/lib/diaspora/user/connecting.rb index d56d825dd..2e6abe757 100644 --- a/lib/diaspora/user/connecting.rb +++ b/lib/diaspora/user/connecting.rb @@ -61,7 +61,7 @@ module Diaspora Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{person.diaspora_handle}") retraction = Retraction.for(self) 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 remove_contact(bad_contact) diff --git a/lib/postzord/dispatcher.rb b/lib/postzord/dispatcher.rb new file mode 100644 index 000000000..65261724c --- /dev/null +++ b/lib/postzord/dispatcher.rb @@ -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 + diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatcher/private.rb similarity index 97% rename from lib/postzord/dispatch.rb rename to lib/postzord/dispatcher/private.rb index a04c65bdf..140f63129 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatcher/private.rb @@ -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 # the COPYRIGHT file. -class Postzord::Dispatch - +class Postzord::Dispatcher::Private # @note Takes :additional_subscribers param to add to subscribers to dispatch to def initialize(user, object, opts={}) unless object.respond_to? :to_diaspora_xml diff --git a/lib/postzord/receiver.rb b/lib/postzord/receiver.rb deleted file mode 100644 index eb41080fe..000000000 --- a/lib/postzord/receiver.rb +++ /dev/null @@ -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 diff --git a/lib/postzord/receiver/local_post_batch.rb b/lib/postzord/receiver/local_post_batch.rb index 7c035a142..792389ed1 100644 --- a/lib/postzord/receiver/local_post_batch.rb +++ b/lib/postzord/receiver/local_post_batch.rb @@ -1,5 +1,5 @@ module Postzord - class Receiver + module Receiver class LocalPostBatch attr_reader :post, :recipient_user_ids, :users diff --git a/lib/postzord/receiver/private.rb b/lib/postzord/receiver/private.rb new file mode 100644 index 000000000..54019624d --- /dev/null +++ b/lib/postzord/receiver/private.rb @@ -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 diff --git a/lib/postzord/receiver/public.rb b/lib/postzord/receiver/public.rb index abc7a37de..8a7971e0c 100644 --- a/lib/postzord/receiver/public.rb +++ b/lib/postzord/receiver/public.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. # module Postzord - class Receiver + module Receiver class Public attr_accessor :salmon, :author diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index 09c93b403..24e9596ed 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -94,8 +94,8 @@ describe ConversationsController do } ) - p = Postzord::Dispatch.new(alice, cnv) - Postzord::Dispatch.stub!(:new).and_return(p) + p = Postzord::Dispatcher.new(alice, cnv) + Postzord::Dispatcher.stub!(:new).and_return(p) p.should_receive(:post) post :create, @hash end diff --git a/spec/models/user/attack_vectors_spec.rb b/spec/integration/attack_vectors_spec.rb similarity index 84% rename from spec/models/user/attack_vectors_spec.rb rename to spec/integration/attack_vectors_spec.rb index f56b274d1..48843e6a6 100644 --- a/spec/models/user/attack_vectors_spec.rb +++ b/spec/integration/attack_vectors_spec.rb @@ -27,7 +27,7 @@ describe "attack vectors" do bad_user.delete 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 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]) 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 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) - zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) + zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml) zord.perform 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) - zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) + zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml) zord.perform 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 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 lambda { 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) - zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) + zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml) zord.perform }.should_not change{user.reload.visible_posts.count} @@ -104,7 +104,7 @@ describe "attack vectors" do first_name = user2.profile.first_name 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 user2.reload @@ -116,7 +116,7 @@ describe "attack vectors" do original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id 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 user.visible_posts.count.should == 1 @@ -128,7 +128,7 @@ describe "attack vectors" do ret.type = original_message.class.to_s 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 StatusMessage.count.should == 1 @@ -150,7 +150,7 @@ describe "attack vectors" do StatusMessage.count.should == 0 proc { 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 }.should_not raise_error end @@ -159,7 +159,7 @@ describe "attack vectors" do original_message = user2.post :status_message, :text => 'store this!', :to => aspect2.id 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 @@ -173,7 +173,7 @@ describe "attack vectors" do lambda { 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 }.should_not change(StatusMessage, :count) @@ -189,7 +189,7 @@ describe "attack vectors" do proc{ 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 }.should_not change{user.reload.contacts.count} @@ -203,7 +203,7 @@ describe "attack vectors" do proc{ 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 }.should_not change{user.reload.contacts.count} end @@ -212,7 +212,7 @@ describe "attack vectors" do 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) - zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) + zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml) zord.perform 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) - zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml) + zord = Postzord::Receiver::Private.new(user, :salmon_xml => salmon_xml) zord.perform original_message.reload.text.should == "store this!" diff --git a/spec/integration/receiving_spec.rb b/spec/integration/receiving_spec.rb index 2b49828f0..3b12785df 100644 --- a/spec/integration/receiving_spec.rb +++ b/spec/integration/receiving_spec.rb @@ -7,7 +7,7 @@ require 'spec_helper' describe 'a user receives a post' do 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) 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) Diaspora::WebSocket.stub!(:is_connected?).and_return(true) 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 end @@ -74,10 +74,10 @@ describe 'a user receives a post' do bob.add_to_streams(@sm, [bob.aspects.first]) @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 = Postzord::Receiver.new(eve, :object => @sm, :person => bob.person) + zord = Postzord::Receiver::Private.new(eve, :object => @sm, :person => bob.person) zord.receive_object end @@ -91,7 +91,7 @@ describe 'a user receives a post' do @sm.stub!(:socket_to_user) @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 end @@ -103,7 +103,7 @@ describe 'a user receives a post' do eve.add_to_streams(@sm, [eve.aspects.first]) @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 end end @@ -333,7 +333,7 @@ describe 'a user receives a post' do it 'processes a salmon for a post' do 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 bob.visible_posts.include?(post).should be_true @@ -348,7 +348,7 @@ describe 'a user receives a post' do xml = retraction.to_diaspora_xml lambda { - zord = Postzord::Receiver.new(alice, :person => bob.person) + zord = Postzord::Receiver::Private.new(alice, :person => bob.person) zord.parse_and_receive(xml) }.should change(StatusMessage, :count).by(-1) end @@ -370,7 +370,7 @@ describe 'a user receives a post' do xml = new_profile.to_diaspora_xml #Marshal profile - zord = Postzord::Receiver.new(alice, :person => person) + zord = Postzord::Receiver::Private.new(alice, :person => person) zord.parse_and_receive(xml) #Check that marshaled profile is the same as old profile diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatcher/private_spec.rb similarity index 88% rename from spec/lib/postzord/dispatch_spec.rb rename to spec/lib/postzord/dispatcher/private_spec.rb index 68a99eb33..85ae8bc52 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatcher/private_spec.rb @@ -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 # the COPYRIGHT file. require 'spec_helper' -require File.join(Rails.root, 'lib/postzord') -require File.join(Rails.root, 'lib/postzord/dispatch') +require File.join(Rails.root, 'lib/postzord/dispatcher/private') -describe Postzord::Dispatch do +describe Postzord::Dispatcher::Private do before do @sm = Factory(:status_message, :public => true, :author => alice.person) @subscribers = [] @@ -18,7 +17,7 @@ describe Postzord::Dispatch do describe '.initialize' 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(:@object).should == @sm end @@ -26,7 +25,7 @@ describe Postzord::Dispatch do context 'setting @subscribers' do it 'sets @subscribers from object' do @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 end @@ -34,24 +33,24 @@ describe Postzord::Dispatch do new_person = Factory(:person) @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] end end 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 end 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/ end end 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 end @@ -60,7 +59,7 @@ describe Postzord::Dispatch do @subscribers << bob.person @remote_people, @local_people = @subscribers.partition{ |person| person.owner_id.nil? } @sm.stub!(:subscribers).and_return @subscribers - @zord = Postzord::Dispatch.new(alice, @sm) + @zord = Postzord::Dispatcher::Private.new(alice, @sm) end describe '#post' do @@ -99,7 +98,7 @@ describe Postzord::Dispatch do end context "local leia's mailman" do before do - @mailman = Postzord::Dispatch.new(@local_leia, @comment) + @mailman = Postzord::Dispatcher::Private.new(@local_leia, @comment) end it 'calls deliver_to_local with local_luke' do @mailman.should_receive(:deliver_to_local).with([@local_luke.person]) @@ -120,7 +119,7 @@ describe Postzord::Dispatch do end context "local luke's mailman" do before do - @mailman = Postzord::Dispatch.new(@local_luke, @comment) + @mailman = Postzord::Dispatcher::Private.new(@local_luke, @comment) end it 'does not call deliver_to_local' do @mailman.should_not_receive(:deliver_to_local) @@ -145,7 +144,7 @@ describe Postzord::Dispatch do before do @comment = Factory.build(:comment, :author => @remote_raphael, :post => @post) @comment.save - @mailman = Postzord::Dispatch.new(@local_luke, @comment) + @mailman = Postzord::Dispatcher::Private.new(@local_luke, @comment) end it 'does not call deliver_to_local' do @mailman.should_not_receive(:deliver_to_local) @@ -168,7 +167,7 @@ describe Postzord::Dispatch do before do @comment = @local_luke.build_comment :text => "yo", :post => @post @comment.save - @mailman = Postzord::Dispatch.new(@local_luke, @comment) + @mailman = Postzord::Dispatcher::Private.new(@local_luke, @comment) end it 'does not call deliver_to_local' do @mailman.should_not_receive(:deliver_to_local) @@ -194,7 +193,7 @@ describe Postzord::Dispatch do @post = Factory(:status_message, :author => @remote_raphael) @comment = @local_luke.build_comment :text => "yo", :post => @post @comment.save - @mailman = Postzord::Dispatch.new(@local_luke, @comment) + @mailman = Postzord::Dispatcher::Private.new(@local_luke, @comment) end it 'calls deliver_to_remote with remote_raphael' do @mailman.should_receive(:deliver_to_remote).with([@remote_raphael]) @@ -219,7 +218,7 @@ describe Postzord::Dispatch do before do @remote_people = [] @remote_people << alice.person - @mailman = Postzord::Dispatch.new(alice, @sm) + @mailman = Postzord::Dispatcher::Private.new(alice, @sm) @hydra = mock() Typhoeus::Hydra.stub!(:new).and_return(@hydra) end @@ -243,7 +242,7 @@ describe Postzord::Dispatch do describe '#deliver_to_local' do before do - @mailman = Postzord::Dispatch.new(alice, @sm) + @mailman = Postzord::Dispatcher::Private.new(alice, @sm) end 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 @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.post(:url => "http://joindiaspora.com/p/123") @@ -291,7 +290,7 @@ describe Postzord::Dispatch do alice.services << @s1 @s2 = Factory.create(:service, :user_id => alice.id) 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::HttpMulti, anything, anything, anything) @@ -300,7 +299,7 @@ describe Postzord::Dispatch do end 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.should_not_receive(:enqueue).with(Job::PostToService, anything, anything, anything) @@ -323,7 +322,7 @@ describe Postzord::Dispatch do f.stub!(:subscribers) f.stub!(:to_diaspora_xml) 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.send(:socket_to_users, users) end diff --git a/spec/lib/postzord/receiver_spec.rb b/spec/lib/postzord/receiver/private_spec.rb similarity index 84% rename from spec/lib/postzord/receiver_spec.rb rename to spec/lib/postzord/receiver/private_spec.rb index bcc5fe204..c6554805c 100644 --- a/spec/lib/postzord/receiver_spec.rb +++ b/spec/lib/postzord/receiver/private_spec.rb @@ -5,9 +5,9 @@ require 'spec_helper' 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 @user = alice @@ -26,7 +26,7 @@ describe Postzord::Receiver do Webfinger.should_not_receive(:new) 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(:@sender).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) 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(:@sender).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 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) end @@ -80,7 +80,7 @@ describe Postzord::Receiver do describe 'receive_object' 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) end @@ -89,7 +89,7 @@ describe Postzord::Receiver do cm.stub!(:receive).and_return(cm) 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 end diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 194c5cd6b..a538ba67c 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -56,7 +56,7 @@ describe 'making sure the spec runner works' do person_status = Factory.create(:status_message, :author => person) m = mock() 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 end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index a8d3dc166..e67d553c8 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -169,7 +169,7 @@ describe Contact do @contact.stub(:user).and_return(@user) m = mock() m.should_receive(:post) - Postzord::Dispatch.should_receive(:new).and_return(m) + Postzord::Dispatcher.should_receive(:new).and_return(m) @contact.dispatch_request end end diff --git a/spec/models/jobs/delete_account_spec.rb b/spec/models/job/delete_account_spec.rb similarity index 100% rename from spec/models/jobs/delete_account_spec.rb rename to spec/models/job/delete_account_spec.rb diff --git a/spec/models/jobs/http_multi_spec.rb b/spec/models/job/http_multi_spec.rb similarity index 100% rename from spec/models/jobs/http_multi_spec.rb rename to spec/models/job/http_multi_spec.rb diff --git a/spec/models/jobs/http_post_spec.rb b/spec/models/job/http_post_spec.rb similarity index 100% rename from spec/models/jobs/http_post_spec.rb rename to spec/models/job/http_post_spec.rb diff --git a/spec/models/jobs/mail/invite_user_by_email_spec.rb b/spec/models/job/mail/invite_user_by_email_spec.rb similarity index 100% rename from spec/models/jobs/mail/invite_user_by_email_spec.rb rename to spec/models/job/mail/invite_user_by_email_spec.rb diff --git a/spec/models/jobs/mail/mail_mentioned_spec.rb b/spec/models/job/mail/mail_mentioned_spec.rb similarity index 100% rename from spec/models/jobs/mail/mail_mentioned_spec.rb rename to spec/models/job/mail/mail_mentioned_spec.rb diff --git a/spec/models/jobs/mail/mail_private_message.rb b/spec/models/job/mail/mail_private_message.rb similarity index 100% rename from spec/models/jobs/mail/mail_private_message.rb rename to spec/models/job/mail/mail_private_message.rb diff --git a/spec/models/jobs/mail/mail_reshared_spec.rb b/spec/models/job/mail/mail_reshared_spec.rb similarity index 100% rename from spec/models/jobs/mail/mail_reshared_spec.rb rename to spec/models/job/mail/mail_reshared_spec.rb diff --git a/spec/models/jobs/notify_local_users_spec.rb b/spec/models/job/notify_local_users_spec.rb similarity index 100% rename from spec/models/jobs/notify_local_users_spec.rb rename to spec/models/job/notify_local_users_spec.rb diff --git a/spec/models/jobs/post_to_service_spec.rb b/spec/models/job/post_to_service_spec.rb similarity index 100% rename from spec/models/jobs/post_to_service_spec.rb rename to spec/models/job/post_to_service_spec.rb diff --git a/spec/models/jobs/process_photo_spec.rb b/spec/models/job/process_photo_spec.rb similarity index 100% rename from spec/models/jobs/process_photo_spec.rb rename to spec/models/job/process_photo_spec.rb diff --git a/spec/models/jobs/publish_to_hub_spec.rb b/spec/models/job/publish_to_hub_spec.rb similarity index 100% rename from spec/models/jobs/publish_to_hub_spec.rb rename to spec/models/job/publish_to_hub_spec.rb diff --git a/spec/models/jobs/receive_local_batch_spec.rb b/spec/models/job/receive_local_batch_spec.rb similarity index 100% rename from spec/models/jobs/receive_local_batch_spec.rb rename to spec/models/job/receive_local_batch_spec.rb diff --git a/spec/models/jobs/receive_salmon_spec.rb b/spec/models/job/receive_salmon_spec.rb similarity index 100% rename from spec/models/jobs/receive_salmon_spec.rb rename to spec/models/job/receive_salmon_spec.rb diff --git a/spec/models/jobs/receive_spec.rb b/spec/models/job/receive_spec.rb similarity index 81% rename from spec/models/jobs/receive_spec.rb rename to spec/models/job/receive_spec.rb index f8f3cf13d..3142262f9 100644 --- a/spec/models/jobs/receive_spec.rb +++ b/spec/models/job/receive_spec.rb @@ -17,7 +17,7 @@ describe Job::Receive do it 'calls receive' do zord_mock = mock() 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) end end diff --git a/spec/models/jobs/resend_invitation_spec.rb b/spec/models/job/resend_invitation_spec.rb similarity index 100% rename from spec/models/jobs/resend_invitation_spec.rb rename to spec/models/job/resend_invitation_spec.rb diff --git a/spec/models/jobs/socket_webfinger_spec.rb b/spec/models/job/socket_webfinger_spec.rb similarity index 100% rename from spec/models/jobs/socket_webfinger_spec.rb rename to spec/models/job/socket_webfinger_spec.rb diff --git a/spec/models/jobs/update_service_users_spec.rb b/spec/models/job/update_service_users_spec.rb similarity index 100% rename from spec/models/jobs/update_service_users_spec.rb rename to spec/models/job/update_service_users_spec.rb diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index c5a5b653e..bc84808f4 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -82,7 +82,7 @@ describe Message do msg_hash = {:author => @local_luke.person, :text => 'yo', :conversation => @local_parent} @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 @object_by_recipient = Message.create(msg_hash.dup) @@ -92,7 +92,7 @@ describe Message do msg_hash[:author] = @local_luke.person msg_hash[:conversation] = @remote_parent @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 it_should_behave_like 'it is relayable' diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index e8d8960ac..3b6c90134 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -119,15 +119,12 @@ describe Notification do end end - - context 'multiple people' do - before do @user3 = bob @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.new(@user3, :person => @user.person, :object => @user.comment("hey", :post => @sm)).receive_object + Postzord::Receiver::Private.new(@user3, :person => @user2.person, :object => @user2.comment("hey", :post => @sm)).receive_object + Postzord::Receiver::Private.new(@user3, :person => @user.person, :object => @user.comment("hey", :post => @sm)).receive_object end it "updates the notification with a more people if one already exists" do @@ -135,10 +132,9 @@ describe Notification do end 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 end - end end end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 86816e7fb..97f1d51a9 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -164,7 +164,7 @@ describe Photo do xml = @photo.to_diaspora_xml @photo.destroy - zord = Postzord::Receiver.new(user2, :person => @photo.author) + zord = Postzord::Receiver::Private.new(user2, :person => @photo.author) zord.parse_and_receive(xml) new_photo = Photo.where(:guid => @photo.guid).first diff --git a/spec/models/relayable_retraction_spec.rb b/spec/models/relayable_retraction_spec.rb index 2c26ba93f..805174b7e 100644 --- a/spec/models/relayable_retraction_spec.rb +++ b/spec/models/relayable_retraction_spec.rb @@ -49,7 +49,7 @@ describe RelayableRetraction do it 'dispatches' do zord = mock() 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) end it 'performs' do @@ -71,7 +71,7 @@ describe RelayableRetraction do @retraction.receive(@recipient, @remote_raphael) end it 'does not dispatch' do - Postzord::Dispatch.should_not_receive(:new) + Postzord::Dispatcher.should_not_receive(:new) @retraction.receive(@recipient, @remote_raphael) end end diff --git a/spec/models/signed_retraction_spec.rb b/spec/models/signed_retraction_spec.rb index cc9e7ef61..32be07c3b 100644 --- a/spec/models/signed_retraction_spec.rb +++ b/spec/models/signed_retraction_spec.rb @@ -14,7 +14,7 @@ describe SignedRetraction do retraction.should_receive(:dup).and_return(onward_retraction) 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) retraction.perform(@resharer) @@ -35,7 +35,7 @@ describe SignedRetraction do Post.exists?(:id => remote_post.id).should be_false dis = mock - Postzord::Dispatch.should_receive(:new){ |sender, retraction| + Postzord::Dispatcher.should_receive(:new){ |sender, retraction| sender.should == alice retraction.sender.should == alice.person dis diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 369fc8141..0f9243675 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -58,7 +58,7 @@ describe Diaspora::UserModules::Connecting do it 'dispatches a retraction' do p = mock() - Postzord::Dispatch.should_receive(:new).and_return(p) + Postzord::Dispatcher.should_receive(:new).and_return(p) p.should_receive(:post) bob.disconnect bob.contact_for(eve.person) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1804c1bf6..890b70ec5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -440,16 +440,14 @@ describe User do it 'dispatches the profile when tags are set' do @params = {:tags => '#what #hey'} - mailman = Postzord::Dispatch.new(alice, Profile.new) - Postzord::Dispatch.should_receive(:new).and_return(mailman) - mailman.should_receive(:deliver_to_local) + mailman = Postzord::Dispatcher.new(alice, Profile.new) + Postzord::Dispatcher.should_receive(:new).and_return(mailman) alice.update_profile(@params).should be_true end it 'sends a profile to their contacts' do - mailman = Postzord::Dispatch.new(alice, Profile.new) - Postzord::Dispatch.should_receive(:new).and_return(mailman) - mailman.should_receive(:deliver_to_local) + mailman = Postzord::Dispatcher.new(alice, Profile.new) + Postzord::Dispatcher.should_receive(:new).and_return(mailman) alice.update_profile(@params).should be_true end @@ -498,7 +496,7 @@ describe User do it 'sends a notification to aspects' do m = mock() 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) alice.update_post(photo, :text => 'hellp') end @@ -950,7 +948,7 @@ describe User do it 'sends a retraction' do 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) bob.retract(@post) @@ -962,7 +960,7 @@ describe User do @post.reshares << reshare 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) bob.retract(@post) diff --git a/spec/shared_behaviors/relayable.rb b/spec/shared_behaviors/relayable.rb index 16e14aade..f5d1989ae 100644 --- a/spec/shared_behaviors/relayable.rb +++ b/spec/shared_behaviors/relayable.rb @@ -60,9 +60,9 @@ describe Diaspora::Relayable do end 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) - Postzord::Dispatch.stub!(:new).and_return(p) + Postzord::Dispatcher.stub!(:new).and_return(p) @object_by_recipient.receive(@local_luke, @local_leia.person) end diff --git a/spec/support/user_methods.rb b/spec/support/user_methods.rb index d240f5e5c..3a8a0c9b4 100644 --- a/spec/support/user_methods.rb +++ b/spec/support/user_methods.rb @@ -36,7 +36,7 @@ class User fantasy_resque do c = build_comment(options.merge(:text => text)) if c.save! - Postzord::Dispatch.new(self, c).post + Postzord::Dispatcher.new(self, c).post end c end @@ -46,7 +46,7 @@ class User fantasy_resque do l = build_like(options.merge(:positive => positive)) if l.save! - Postzord::Dispatch.new(self, l).post + Postzord::Dispatcher.new(self, l).post end l end