From ba8e50e34c820c07481280be13d7c5681c1a6979 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Thu, 15 Sep 2011 15:16:34 -0700 Subject: [PATCH] DG MS; renamed a file; fixed the build --- app/models/conversation.rb | 1 + app/models/jobs/receive_local_batch.rb | 4 ++-- features/support/poor_mans_webmock.rb | 2 +- lib/postzord/dispatcher.rb | 2 +- .../{local_post_batch.rb => local_batch.rb} | 10 ++++----- lib/postzord/receiver/private.rb | 1 - lib/postzord/receiver/public.rb | 2 +- ...post_batch_spec.rb => local_batch_spec.rb} | 22 +++++++++---------- spec/lib/postzord/receiver/public_spec.rb | 6 ++--- spec/models/jobs/receive_local_batch_spec.rb | 2 +- 10 files changed, 26 insertions(+), 26 deletions(-) rename lib/postzord/receiver/{local_post_batch.rb => local_batch.rb} (88%) rename spec/lib/postzord/receiver/{local_post_batch_spec.rb => local_batch_spec.rb} (82%) diff --git a/app/models/conversation.rb b/app/models/conversation.rb index e10b27030..13dae328d 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -55,6 +55,7 @@ class Conversation < ActiveRecord::Base self.participants.each do |participant| ConversationVisibility.find_or_create_by_conversation_id_and_person_id(cnv.id, participant.id) end + self.messages.each do |msg| msg.conversation_id = cnv.id received_msg = msg.receive(user, person) diff --git a/app/models/jobs/receive_local_batch.rb b/app/models/jobs/receive_local_batch.rb index fb0a1481a..ec8b781a6 100644 --- a/app/models/jobs/receive_local_batch.rb +++ b/app/models/jobs/receive_local_batch.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. 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_batch') module Jobs class ReceiveLocalBatch < Base @@ -12,7 +12,7 @@ module Jobs def self.perform(object_class_string, object_id, recipient_user_ids) object = object_class_string.constantize.find(object_id) - receiver = Postzord::Receiver::LocalPostBatch.new(object, recipient_user_ids) + receiver = Postzord::Receiver::LocalBatch.new(object, recipient_user_ids) receiver.perform! end end diff --git a/features/support/poor_mans_webmock.rb b/features/support/poor_mans_webmock.rb index 5b8835b75..bb5d1312e 100644 --- a/features/support/poor_mans_webmock.rb +++ b/features/support/poor_mans_webmock.rb @@ -2,7 +2,7 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -module Job +module Jobs class PublishToHub < Base @queue = :http_service def self.perform(sender_public_url) diff --git a/lib/postzord/dispatcher.rb b/lib/postzord/dispatcher.rb index e568fdb20..7cd8ddc04 100644 --- a/lib/postzord/dispatcher.rb +++ b/lib/postzord/dispatcher.rb @@ -91,7 +91,7 @@ class Postzord::Dispatcher # @param people [Array] Recipients of the post def deliver_to_local(people) return if people.blank? || @object.is_a?(Profile) - if @object.respond_to?(:persisted?) + if @object.respond_to?(:persisted?) && !@object.is_a?(Conversation) batch_deliver_to_local(people) else people.each do |person| diff --git a/lib/postzord/receiver/local_post_batch.rb b/lib/postzord/receiver/local_batch.rb similarity index 88% rename from lib/postzord/receiver/local_post_batch.rb rename to lib/postzord/receiver/local_batch.rb index 604312a7a..6ac12eb44 100644 --- a/lib/postzord/receiver/local_post_batch.rb +++ b/lib/postzord/receiver/local_batch.rb @@ -1,6 +1,6 @@ module Postzord module Receiver - class LocalPostBatch + class LocalBatch attr_reader :object, :recipient_user_ids, :users def initialize(object, recipient_user_ids) @@ -13,7 +13,7 @@ module Postzord if @object.respond_to?(:relayable?) receive_relayable else - create_visibilities + create_post_visibilities end notify_mentioned_users if @object.respond_to?(:mentions) @@ -31,10 +31,10 @@ module Postzord @object end - # Batch import visibilities for the recipients of the given @object + # Batch import post visibilities for the recipients of the given @object # @note performs a bulk insert into mySQL # @return [void] - def create_visibilities + def create_post_visibilities contacts = Contact.where(:user_id => @recipient_user_ids, :person_id => @object.author_id) PostVisibility.batch_import(contacts, object) end @@ -60,7 +60,7 @@ module Postzord # Notify users of the new object # return [void] def notify_users - return unless @object.respond_to?(:notification_type) + return unless @object.respond_to?(:notification_type) @users.each do |user| Notification.notify(user, @object, @object.author) end diff --git a/lib/postzord/receiver/private.rb b/lib/postzord/receiver/private.rb index 03b0f4a7a..21d0f872e 100644 --- a/lib/postzord/receiver/private.rb +++ b/lib/postzord/receiver/private.rb @@ -49,7 +49,6 @@ module Postzord obj end - protected def salmon @salmon ||= Salmon::EncryptedSlap.from_xml(@salmon_xml, @user) diff --git a/lib/postzord/receiver/public.rb b/lib/postzord/receiver/public.rb index f03c55f8b..59c8e18a4 100644 --- a/lib/postzord/receiver/public.rb +++ b/lib/postzord/receiver/public.rb @@ -36,7 +36,7 @@ module Postzord @object.receive(@object.parent.author.owner, @author) end # notify everyone who can see the parent object - receiver = Postzord::Receiver::LocalPostBatch.new(@object, self.recipient_user_ids) + receiver = Postzord::Receiver::LocalBatch.new(@object, self.recipient_user_ids) receiver.notify_users @object end diff --git a/spec/lib/postzord/receiver/local_post_batch_spec.rb b/spec/lib/postzord/receiver/local_batch_spec.rb similarity index 82% rename from spec/lib/postzord/receiver/local_post_batch_spec.rb rename to spec/lib/postzord/receiver/local_batch_spec.rb index ae5825027..8dbc8e500 100644 --- a/spec/lib/postzord/receiver/local_post_batch_spec.rb +++ b/spec/lib/postzord/receiver/local_batch_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -require File.join(Rails.root, 'lib','postzord', 'receiver', 'local_post_batch') +require File.join(Rails.root, 'lib','postzord', 'receiver', 'local_batch') -describe Postzord::Receiver::LocalPostBatch do +describe Postzord::Receiver::LocalBatch do before do @object = Factory(:status_message, :author => alice.person) @ids = [bob.id] end - let(:receiver) { Postzord::Receiver::LocalPostBatch.new(@object, @ids) } + let(:receiver) { Postzord::Receiver::LocalBatch.new(@object, @ids) } describe '.initialize' do it 'sets @post, @recipient_user_ids, and @user' do @@ -18,8 +18,8 @@ describe Postzord::Receiver::LocalPostBatch do end describe '#perform!' do - it 'calls .create_visibilities' do - receiver.should_receive(:create_visibilities) + it 'calls .create_post_visibilities' do + receiver.should_receive(:create_post_visibilities) receiver.perform! end @@ -39,10 +39,10 @@ describe Postzord::Receiver::LocalPostBatch do end end - describe '#create_visibilities' do + describe '#create_post_visibilities' do it 'calls Postvisibility.batch_import' do PostVisibility.should_receive(:batch_import) - receiver.create_visibilities + receiver.create_post_visibilities end end @@ -61,7 +61,7 @@ describe Postzord::Receiver::LocalPostBatch do :author => alice.person, :text => "Hey @{Bob; #{bob.diaspora_handle}}") - receiver2 = Postzord::Receiver::LocalPostBatch.new(sm, @ids) + receiver2 = Postzord::Receiver::LocalBatch.new(sm, @ids) Notification.should_receive(:notify).with(bob, anything, alice.person) receiver2.notify_mentioned_users end @@ -76,13 +76,13 @@ describe Postzord::Receiver::LocalPostBatch do it 'calls notify for posts with notification type' do reshare = Factory.create(:reshare) Notification.should_receive(:notify) - receiver = Postzord::Receiver::LocalPostBatch.new(reshare, @ids) + receiver = Postzord::Receiver::LocalBatch.new(reshare, @ids) receiver.notify_users end it 'calls notify for posts with notification type' do sm = Factory.create(:status_message, :author => alice.person) - receiver = Postzord::Receiver::LocalPostBatch.new(sm, @ids) + receiver = Postzord::Receiver::LocalBatch.new(sm, @ids) Notification.should_not_receive(:notify) receiver.notify_users end @@ -102,7 +102,7 @@ describe Postzord::Receiver::LocalPostBatch do it 'does not call create_visibilities and notify_mentioned_users' do receiver.should_not_receive(:notify_mentioned_users) - receiver.should_not_receive(:create_visibilities) + receiver.should_not_receive(:create_post_visibilities) receiver.perform! end end diff --git a/spec/lib/postzord/receiver/public_spec.rb b/spec/lib/postzord/receiver/public_spec.rb index a4906f21f..777941d81 100644 --- a/spec/lib/postzord/receiver/public_spec.rb +++ b/spec/lib/postzord/receiver/public_spec.rb @@ -102,9 +102,9 @@ describe Postzord::Receiver::Public do comment = stub.as_null_object @receiver.instance_variable_set(:@object, comment) - local_post_batch_receiver = stub.as_null_object - Postzord::Receiver::LocalPostBatch.stub(:new).and_return(local_post_batch_receiver) - local_post_batch_receiver.should_receive(:notify_users) + local_batch_receiver = stub.as_null_object + Postzord::Receiver::LocalBatch.stub(:new).and_return(local_batch_receiver) + local_batch_receiver.should_receive(:notify_users) @receiver.receive_relayable end end diff --git a/spec/models/jobs/receive_local_batch_spec.rb b/spec/models/jobs/receive_local_batch_spec.rb index 81e75b031..6fb4fde46 100644 --- a/spec/models/jobs/receive_local_batch_spec.rb +++ b/spec/models/jobs/receive_local_batch_spec.rb @@ -11,7 +11,7 @@ describe Jobs::ReceiveLocalBatch do end describe '.perform' do - it 'calls Postzord::Receiver::LocalPostBatch' do + it 'calls Postzord::Receiver::LocalBatch' do pending end end