diff --git a/app/models/comment.rb b/app/models/comment.rb index 39d43d19d939d2e5863ee68befad984460077da3..83765d4c9859cb329cca9cb757ff428377b83b1c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -50,6 +50,17 @@ class Comment end end + def subscribers(user) + if user.owns?(self.post) + p = user.people_in_aspects(user.aspects_with_post(self.post_id)) + elsif user.owns?(self) +:A + + p = [self.post.person] + end + p + end + #ENCRYPTION xml_reader :creator_signature diff --git a/app/models/contact.rb b/app/models/contact.rb index b330811e3b16843b3ba01cc12eb640251ac7b921..acf31ed18e368c0ba1b83700a184a2b5989658eb 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -23,7 +23,7 @@ class Contact def dispatch_request request = self.generate_request - self.user.push_to_people(request, [self.person]) + Postzord::Dispatch.new(self.user, request).post request end diff --git a/app/models/post.rb b/app/models/post.rb index dc3cc201a1cd86f46100c7ec5d1530c8ff8a8aa3..ea177398bef68cb2c0a43d884ccb9f67b705a9ed 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -60,6 +60,10 @@ class Post false end + def subscribers(user) + user.people_in_aspects(user.aspects_with_post(self.id)) + end + protected def destroy_comments comments.each{|c| c.destroy} diff --git a/app/models/profile.rb b/app/models/profile.rb index 64a177f883cd7eb71b843d7fa5f368c77e69853f..47e1448c3bb319db4fbd6c2e4e4a71c40f49e498 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -44,6 +44,10 @@ class Profile self._parent_document end + def subscribers(user) + user.person_objects(user.contacts.where(:pending => false)) + end + def diaspora_handle #get the parent diaspora handle, unless we want to access a profile without a person (self._parent_document) ? self.person.diaspora_handle : self[:diaspora_handle] diff --git a/app/models/request.rb b/app/models/request.rb index 4a2f8b4421f98b503ac06965f222c54f5e914468..402b9a481ac3cb465e7fcb961af98ac679d82e94 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -5,6 +5,7 @@ class Request require File.join(Rails.root, 'lib/diaspora/webhooks') +require File.join(Rails.root, 'lib/postzord/dispatch') include MongoMapper::Document include Diaspora::Webhooks include ROXML @@ -81,6 +82,10 @@ class Request "new_request" end end + + def subscribers(user) + [self.to] + end private diff --git a/app/models/retraction.rb b/app/models/retraction.rb index 3aa3cf875a70978aa65b8fad518d0a5594cd8cdf..a9be633ab72f8de6708f0a8cd16838043e19d583 100644 --- a/app/models/retraction.rb +++ b/app/models/retraction.rb @@ -9,9 +9,13 @@ class Retraction xml_accessor :post_id xml_accessor :diaspora_handle xml_accessor :type + + attr_accessor :person, :object, :subscribers - attr_accessor :person - + def subscribers(user) + @subscribers ||= self.object.subscribers(user) + end + def self.for(object) retraction = self.new if object.is_a? User @@ -20,6 +24,7 @@ class Retraction else retraction.post_id = object.id retraction.type = object.class.to_s + retraction.object = object end retraction.diaspora_handle = object.diaspora_handle retraction diff --git a/app/models/user.rb b/app/models/user.rb index b9f2acb096b28e799fa07d6e762c3397329ddee0..ea6da134dc15f620cf7902935d71c1818535419e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +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 'rest-client' class User @@ -106,6 +107,11 @@ class User end end + def salmon(post) + created_salmon = Salmon::SalmonSlap.create(self, post.to_diaspora_xml) + created_salmon + end + def add_contact_to_aspect(contact, aspect) return true if contact.aspect_ids.include?(aspect.id) contact.aspects << aspect @@ -136,31 +142,14 @@ class User end def dispatch_post(post, opts = {}) - aspect_ids = opts.delete(:to) - - Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}") - push_to_aspects(post, aspects_from_ids(aspect_ids)) - Resque.enqueue(Jobs::PostToServices, self.id, post.id, opts[:url]) if post.public - end - - def post_to_services(post, url) - if post.respond_to?(:message) - self.services.each do |service| - service.post(post, url) - end - end - end - - def post_to_hub(post) - Rails.logger.debug("event=post_to_service type=pubsub sender_handle=#{self.diaspora_handle}") - EventMachine::PubSubHubbub.new(AppConfig[:pubsub_server]).publish self.public_url + mailman = Postzord::Dispatch.new(self, post) + mailman.post end def update_post(post, post_hash = {}) if self.owns? post post.update_attributes(post_hash) - aspects = aspects_with_post(post.id) - self.push_to_aspects(post, aspects) + Postzord::Dispatch.new(self, post).post end end @@ -188,47 +177,6 @@ class User end end - def push_to_aspects(post, aspects) - #send to the aspects - target_aspect_ids = aspects.map {|a| a.id} - - target_contacts = Contact.all(:aspect_ids.in => target_aspect_ids, :pending => false) - - post_to_hub(post) if post.respond_to?(:public) && post.public - push_to_people(post, self.person_objects(target_contacts)) - end - - def push_to_people(post, people) - salmon = salmon(post) - people.each do |person| - push_to_person(salmon, post, person) - end - end - - def push_to_person(salmon, post, person) - person.reload # Sadly, we need this for Ruby 1.9. - # person.owner will always return a ProxyObject. - # calling nil? performs a necessary evaluation. - if person.owner_id - Rails.logger.info("event=push_to_person route=local sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}") - - if post.is_a?(Post) || post.is_a?(Comment) - Resque.enqueue(Jobs::ReceiveLocal, person.owner_id, self.person.id, post.class.to_s, post.id) - else - Resque.enqueue(Jobs::Receive, person.owner_id, post.to_diaspora_xml, self.person.id) - end - else - xml = salmon.xml_for person - Rails.logger.info("event=push_to_person route=remote sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}") - MessageHandler.add_post_request(person.receive_url, xml) - end - end - - def salmon(post) - created_salmon = Salmon::SalmonSlap.create(self, post.to_diaspora_xml) - created_salmon - end - ######## Commenting ######## def build_comment(text, options = {}) comment = Comment.new(:person_id => self.person.id, @@ -248,28 +196,30 @@ class User end def dispatch_comment(comment) - if owns? comment.post - #push DOWNSTREAM (to original audience) - Rails.logger.info "event=dispatch_comment direction=downstream user=#{self.diaspora_handle} comment=#{comment.id}" - aspects = aspects_with_post(comment.post_id) - - #just socket to local users, as the comment has already - #been associated and saved by post owner - # (we'll push to all of their aspects for now, the comment won't - # show up via js where corresponding posts are not present) - - people_in_aspects(aspects, :type => 'local').each do |person| - comment.socket_to_uid(person.owner_id, :aspect_ids => 'all') - end + mailman = Postzord::Dispatch.new(self, comment) + mailman.post + #if owns? comment.post + ##push DOWNSTREAM (to original audience) + #Rails.logger.info "event=dispatch_comment direction=downstream user=#{self.diaspora_handle} comment=#{comment.id}" + #aspects = aspects_with_post(comment.post_id) - #push to remote people - push_to_people(comment, people_in_aspects(aspects, :type => 'remote')) + ##just socket to local users, as the comment has already + ##been associated and saved by post owner + ## (we'll push to all of their aspects for now, the comment won't + ## show up via js where corresponding posts are not present) - elsif owns? comment - #push UPSTREAM (to poster) - Rails.logger.info "event=dispatch_comment direction=upstream user=#{self.diaspora_handle} comment=#{comment.id}" - push_to_people comment, [comment.post.person] - end + #people_in_aspects(aspects, :type => 'local').each do |person| + #comment.socket_to_uid(person.owner_id, :aspect_ids => 'all') + #end + + ##push to remote people + #push_to_people(comment, people_in_aspects(aspects, :type => 'remote')) + + #elsif owns? comment + ##push UPSTREAM (to poster) + #Rails.logger.info "event=dispatch_comment direction=upstream user=#{self.diaspora_handle} comment=#{comment.id}" + #push_to_people comment, [comment.post.person] + #end end ######### Mailer ####################### @@ -286,7 +236,9 @@ class User post.unsocket_from_uid(self.id, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid retraction = Retraction.for(post) - push_to_people retraction, people_in_aspects(aspects_with_post(post.id)) + mailman = Postzord::Dispatch.new(self, retraction) + mailman.post + retraction end @@ -299,7 +251,7 @@ class User params[:image_url_small] = params[:photo].url(:thumb_small) end if self.person.profile.update_attributes(params) - push_to_people profile, self.person_objects(contacts.where(:pending => false)) + Postzord::Dispatch.new(self, profile).post true else false diff --git a/lib/diaspora/user/connecting.rb b/lib/diaspora/user/connecting.rb index 88396ffa7437b6bb317a576e807530f868f8ade3..f16e2f8b27513161097c7d5156a780c465c0b802 100644 --- a/lib/diaspora/user/connecting.rb +++ b/lib/diaspora/user/connecting.rb @@ -26,7 +26,8 @@ module Diaspora end def dispatch_contact_acceptance(request, requester) - push_to_people request, [requester] + Postzord::Dispatch.new(self, request).post + request.destroy unless request.from.owner end @@ -47,7 +48,6 @@ module Diaspora #response from a contact request you sent if original_contact = self.contact_for(contact_request.from) receive_request_acceptance(contact_request, original_contact) - #this is a new contact request elsif contact_request.from != self.person if contact_request.save! @@ -72,7 +72,8 @@ module Diaspora def disconnect(bad_contact) Rails.logger.info("event=disconnect user=#{diaspora_handle} target=#{bad_contact.diaspora_handle}") retraction = Retraction.for(self) - push_to_people retraction, [bad_contact] + retraction.subscribers = [bad_contact]#HAX + Postzord::Dispatch.new(self, retraction).post remove_contact(bad_contact) end diff --git a/lib/diaspora/webhooks.rb b/lib/diaspora/webhooks.rb index 7ea93d712668dbffac9c27c744eebb89bb2b767e..8804d8a61718c67089a4603ef02f5a889cbe3825 100644 --- a/lib/diaspora/webhooks.rb +++ b/lib/diaspora/webhooks.rb @@ -15,5 +15,9 @@ module Diaspora def x(input) input.to_s.to_xs end + + def subscribers(user) + raise 'you must override subscribers in order to enable federation on this model' + end end end diff --git a/lib/postzord/dispatch.rb b/lib/postzord/dispatch.rb index f74c365dafcb995a4b535988898d849c3ccdc305..39c76fdc58dfe10373f327fd149ca8b4175664a3 100644 --- a/lib/postzord/dispatch.rb +++ b/lib/postzord/dispatch.rb @@ -11,25 +11,27 @@ class Postzord::Dispatch @sender_person = @sender.person @object = object @xml = @object.to_diaspora_xml - @subscribers = @object.subscribers + @subscribers = @object.subscribers(@sender) @salmon_factory = Salmon::SalmonSlap.create(@sender, @xml) end def post(opts = {}) - remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? } - user_ids = [*local_people].map{|x| x.owner_id } - local_users = User.all(:id.in => user_ids) - self.socket_to_users(local_users) - self.deliver_to_remote(remote_people) - self.deliver_to_local(local_people) - self.deliver_to_services(opts[:url]) + unless @subscribers == nil + remote_people, local_people = @subscribers.partition{ |person| person.owner_id.nil? } + user_ids = [*local_people].map{|x| x.owner_id } + local_users = User.all(:id.in => user_ids) + self.socket_to_users(local_users) + self.deliver_to_remote(remote_people) + self.deliver_to_local(local_people) + end + self.deliver_to_services(opts[:url]) end protected def deliver_to_remote(people) people.each do |person| enc_xml = @salmon_factory.xml_for(person) - Rails.logger.info("event=push_to_person route=remote sender=#{@sender.person.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{@object.class}") + Rails.logger.info("event=deliver_to_remote route=remote sender=#{@sender.person.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{@object.class}") Resque.enqueue(Jobs::HttpPost, person.receive_url, enc_xml) end end @@ -60,7 +62,7 @@ class Postzord::Dispatch def socket_to_users(users) if @object.respond_to?(:socket_to_uid) users.each do |user| - @object.socket_to_uid(user) + @object.socket_to_uid(user.id) end end end diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 2bd304914bacf3f26841a11cd45ff4fcf9ae9eed..75d7797320b0506e6e19457272552dd79b6656d3 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -18,6 +18,7 @@ describe StatusMessagesController do request.env["HTTP_REFERER"] = "" sign_in :user, user1 @controller.stub!(:current_user).and_return(user1) + user1.reload end describe '#show' do diff --git a/spec/lib/postzord/dispatch_spec.rb b/spec/lib/postzord/dispatch_spec.rb index 011940f7132e798db522de3ed3e364df5d2ca1f5..6fe7627f9788692f3cb2d4655c18d8a460ebbb5b 100644 --- a/spec/lib/postzord/dispatch_spec.rb +++ b/spec/lib/postzord/dispatch_spec.rb @@ -133,7 +133,7 @@ describe Postzord::Dispatch do mailman = Postzord::Dispatch.new(@user, Factory(:status_message)) mailman.should_not_receive(:deliver_to_hub) - mailman.instance_variable_get(:@user).should_not_receive(:services) + mailman.instance_variable_get(:@sender).should_not_receive(:services) end end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 04174b29deab422dfbd41e295138764cd3e8d120..3ca7bc750a32294b3a81bb7fa2343b1eb4dab066 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -22,6 +22,7 @@ describe Comment do describe '.hash_from_post_ids' do before do + user.reload @hello = user.post(:status_message, :message => "Hello.", :to => aspect.id) @hi = user.post(:status_message, :message => "hi", :to => aspect.id) @lonely = user.post(:status_message, :message => "Hello?", :to => aspect.id) @@ -97,12 +98,6 @@ describe Comment do end end - it 'should not send out comments when we have no people' do - status = Factory.create(:status_message, :person => user.person) - MessageHandler.should_not_receive(:add_post_request) - user.comment "sup dog", :on => status - end - describe 'comment propagation' do before do @person = Factory.create(:person) @@ -118,56 +113,55 @@ describe Comment do user.reload end - - it "should send a user's comment on a person's post to that person" do - MessageHandler.should_receive(:add_post_request).once + it 'should send the comment to the postman' do + m = mock() + m.stub!(:post) + Postzord::Dispatch.should_receive(:new).and_return(m) user.comment "yo", :on => @person_status end + + - it 'should send a user comment on his own post to lots of people' do - MessageHandler.should_receive(:add_post_request).once - - user2.raw_visible_posts.count.should == 0 - - user.comment "yo", :on => @user_status + describe '#subscribers' do + it 'returns the posts original audience, if the post is owned by the user' do + end - user2.reload - user2.raw_visible_posts.count.should == 1 + it 'returns the owner of the original post, if the user owns the comment' do + end end - it 'should send a comment a person made on your post to all people' do - comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @user_status) - MessageHandler.should_receive(:add_post_request).once - user.receive comment.to_diaspora_xml, @person - end + it "should send a user's comment on a person's post to that person" do + m = mock() + m.stub!(:post) + Postzord::Dispatch.should_receive(:new).and_return(m) - it 'should send a comment a user made on your post to all people' do - comment = user2.comment( "balls", :on => @user_status) - MessageHandler.should_receive(:add_post_request).once - user.receive comment.to_diaspora_xml, user2.person + user.comment "yo", :on => @person_status end - context 'posts from a remote person' do - before(:all) do - stub_comment_signature_verification - end + #context 'posts from a remote person' do + #before(:all) do + #stub_comment_signature_verification + #end + #before do + #@mailman = Postzord::Dipatch.new(user, @person_status) + #end - it 'should not send a comment a person made on his own post to anyone' do - MessageHandler.should_not_receive(:add_post_request) - comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status) - user.receive comment.to_diaspora_xml, @person - end - - it 'should not send a comment a person made on a person post to anyone' do - MessageHandler.should_not_receive(:add_post_request) - comment = Comment.new(:person_id => @person2.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status) - user.receive comment.to_diaspora_xml, @person - end - - after(:all) do - unstub_mocha_stubs - end - end + #it 'should not send a comment a person made on his own post to anyone' do + #@mailman.should_not_receive(:deliver_to_local) + #comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status) + #user.receive comment.to_diaspora_xml, @person + #end + + #it 'should not send a comment a person made on a person post to anyone' do + #@mailman.should_not_receive(:deliver_to_local) + #comment = Comment.new(:person_id => @person2.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status) + #user.receive comment.to_diaspora_xml, @person + #end + + #after(:all) do + #unstub_mocha_stubs + #end + #end it 'should not clear the aspect post array on receiving a comment' do aspect.post_ids.include?(@user_status.id).should be true diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index fa12b9fc5637b8f0728f43659f888a84753148e0..f9b6c6aea93c9154eea6653109f7b1128d94b64f 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -71,7 +71,9 @@ describe Contact do describe '#dispatch_request' do it 'pushes to people' do @contact.stub(:user).and_return(@user) - @user.should_receive(:push_to_people).with(anything, [@contact.person]) + m = mock() + m.should_receive(:post) + Postzord::Dispatch.should_receive(:new).and_return(m) @contact.dispatch_request end it 'persists no request' do diff --git a/spec/models/jobs/http_post_spec.rb b/spec/models/jobs/http_post_spec.rb index f5301d6cf940191f020dce00463b8833d29d22df..b73f170d23221bc55994136a4962320a4dbdc489 100644 --- a/spec/models/jobs/http_post_spec.rb +++ b/spec/models/jobs/http_post_spec.rb @@ -12,7 +12,7 @@ describe Jobs::HttpPost do end it 'retries' do RestClient.should_receive(:post).with(@url, {:xml=>@escaped_body}).and_raise(SocketError) - Resque.should_receive(:enqueue).with(Jobs::HttpPost, @url, @body, 1).once + Resque.should_receive(:enqueue).with(Jobs::HttpPost, @url, @escaped_body, 1).once Jobs::HttpPost.perform(@url, @body, 2) end end diff --git a/spec/models/retraction_spec.rb b/spec/models/retraction_spec.rb index 265fd258e3916efd60b3951bb17a09fe85354ac4..78e21d05d211d2877fb98c2f9e198b2c7775b80f 100644 --- a/spec/models/retraction_spec.rb +++ b/spec/models/retraction_spec.rb @@ -23,7 +23,9 @@ describe Retraction do describe 'dispatching' do it 'should dispatch a message on delete' do Factory.create(:person) - MessageHandler.should_receive :add_post_request + m = mock() + m.should_receive(:post) + Postzord::Dispatch.should_receive(:new).and_return(m) post.destroy end end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 7aaa0d9ce9b5adc347f24aba56728c0da55bb002..515446cd513257779c8de50fa3f048c504d758f8 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -71,46 +71,6 @@ describe User do end - describe '#post_to_services' do - it 'only iterates through services if the post is public' do - user.should_receive(:services).and_return([]) - post = user.build_post(:status_message, :message => "foo", :public => true, :to => user.aspects.first.id) - user.post_to_services(post, "dfds") - end - end - - describe '#dispatch_post' do - let(:status) {user.build_post(:status_message, @status_opts)} - - before do - @message = "hello, world!" - @status_opts = {:to => "all", :message => @message} - end - - it "posts to a pubsub hub if enabled" do - EventMachine::PubSubHubbub.should_receive(:new).and_return(FakeHttpRequest.new(:success)) - - destination = "http://identi.ca/hub/" - feed_location = "http://google.com/" - - EventMachine.run { - user.post_to_hub(feed_location) - EventMachine.stop - } - end - - it "calls post_to_services if status is public" do - Resque.should_receive(:enqueue).with(Jobs::PostToServices, anything, anything, anything) - status.public = true - user.dispatch_post(status, :to => "all") - end - - it 'pushes to aspects' do - user.should_receive(:push_to_aspects) - user.dispatch_post(status, :to => "all") - end - end - describe '#update_post' do it 'should update fields' do photo = user.post(:photo, :user_file => uploaded_photo, :caption => "Old caption", :to => aspect.id) @@ -122,73 +82,5 @@ describe User do end context 'dispatching' do - let!(:user3) { make_user } - let!(:user4) { make_user } - - let!(:aspect3) { user3.aspects.create(:name => 'heroes') } - let!(:aspect4) { user4.aspects.create(:name => 'heroes') } - - let!(:post) { user.build_post :status_message, :message => "hey" } - let!(:request) { Request.instantiate(:from => user3.person, :to => user4.person) } - - before do - connect_users(user, aspect, user2, aspect2) - connect_users(user, aspect, user3, aspect3) - connect_users(user, aspect1, user4, aspect4) - contact = user.contact_for(user2.person) - user.add_contact_to_aspect(contact, aspect1) - user.reload - end - - describe '#push_to_aspects' do - it 'should push a post to a aspect' do - user.should_receive(:push_to_person).twice - user.push_to_aspects(post, [aspect]) - end - - it 'should push a post to contacts in all aspects' do - user.should_receive(:push_to_person).exactly(3).times - user.push_to_aspects(post, user.aspects) - end - end - - describe '#push_to_people' do - it 'should push to people' do - user.should_receive(:push_to_person).twice - user.push_to_people(post, [user2.person, user3.person]) - end - - it 'does not use the queue for local transfer' do - MessageHandler.should_receive(:add_post_request).once - - remote_person = user4.person - remote_person.owner_id = nil - remote_person.save - remote_person.reload - - user.push_to_people(post, [user2.person, user3.person, remote_person]) - end - end - - describe '#push_to_person' do - before do - @salmon = user.salmon(post) - @xml = post.to_diaspora_xml - end - it 'enqueues receive for requests and retractions for local contacts' do - xml = request.to_diaspora_xml - Resque.should_receive(:enqueue).with(Jobs::Receive, user2.id, xml, user.person.id) - user.push_to_person(@salmon, request, user2.person) - end - it 'enqueues receive for requests and retractions for local contacts' do - Resque.should_receive(:enqueue).with(Jobs::ReceiveLocal, user2.id, user.person.id, post.class.to_s, post.id) - user.push_to_person(@salmon, post, user2.person) - end - it 'calls the MessageHandler for remote contacts' do - person = Factory.create(:person) - MessageHandler.should_receive(:add_post_request).once - user.push_to_person(@salmon, post, person) - end - end end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 8d72c8f9bdd3c5c987d8d89e4cbcaee7b6975466..d14c8750dee32b0a7f723de855fbba43eac86903 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -249,7 +249,9 @@ describe User do end it 'sends a profile to their contacts' do connect_users(user, aspect, user2, aspect2) - user.should_receive(:push_to_person).once + mailman = Postzord::Dispatch.new(user, Profile.new) + Postzord::Dispatch.should_receive(:new).and_return(mailman) + mailman.should_receive(:deliver_to_local) user.update_profile(@params).should be_true end it 'updates names' do @@ -268,7 +270,9 @@ describe User do user.send_contact_request_to(make_user.person, aspect) user.contacts.count.should == 2 - user.should_receive(:push_to_person).once + m = mock() + m.should_receive(:post) + Postzord::Dispatch.should_receive(:new).and_return(m) user.update_profile(@params).should be_true end context 'passing in a photo' do @@ -313,9 +317,10 @@ describe User do describe '#update_post' do it 'sends a notification to aspects' do - user.should_receive(:push_to_aspects).twice - photo = user.post(:photo, :user_file => uploaded_photo, :caption => "hello", :to => aspect.id) - + m = mock() + m.should_receive(:post) + Postzord::Dispatch.should_receive(:new).and_return(m) + photo = user.build_post(:photo, :user_file => uploaded_photo, :caption => "hello", :to => aspect.id) user.update_post(photo, :caption => 'hellp') end end