From 0f596af5c4c2e3a43ba00cdf5b128f2a1205b7db Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 6 Aug 2010 13:13:00 -0700 Subject: [PATCH] Refactored message_queue getting, fixed retraction spec --- app/models/person.rb | 1 + app/models/post.rb | 1 + app/models/retraction.rb | 2 ++ lib/diaspora/webhooks.rb | 3 ++- spec/controllers/sockets_controller_spec.rb | 5 +++-- spec/lib/web_hooks_spec.rb | 4 +--- spec/models/comments_spec.rb | 13 ++++++------- spec/models/photo_spec.rb | 4 ++-- spec/models/retraction_spec.rb | 8 ++++++-- spec/models/user_spec.rb | 3 +-- spec/spec_helper.rb | 4 ++++ spec/user_encryption_spec.rb | 4 ++-- 12 files changed, 31 insertions(+), 21 deletions(-) diff --git a/app/models/person.rb b/app/models/person.rb index 612f12a84..adc7addaa 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -61,6 +61,7 @@ class Person if owns?(post) post.notify_people end + post end ######## Commenting ######## diff --git a/app/models/post.rb b/app/models/post.rb index 74fce8881..6fc92d1ae 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -72,6 +72,7 @@ protected end def propagate_retraction + puts 'propagating retraction' Retraction.for(self).notify_people end diff --git a/app/models/retraction.rb b/app/models/retraction.rb index 05a207a8a..a49282a0b 100644 --- a/app/models/retraction.rb +++ b/app/models/retraction.rb @@ -8,7 +8,9 @@ class Retraction retraction.post_id= object.id retraction.person_id = person_id_from(object) retraction.type = object.class.to_s + puts retraction.inspect retraction + end xml_accessor :post_id diff --git a/lib/diaspora/webhooks.rb b/lib/diaspora/webhooks.rb index 972a98cb2..de9a46900 100644 --- a/lib/diaspora/webhooks.rb +++ b/lib/diaspora/webhooks.rb @@ -7,7 +7,7 @@ module Diaspora @@queue = MessageHandler.new def notify_people - if self.person_id == User.owner.person.id + unless self.person.owner.nil? push_to(people_with_permissions) end end @@ -17,6 +17,7 @@ module Diaspora end def push_to(recipients) + puts "recipients are #{recipients.inspect}" unless recipients.empty? recipients.map!{|x| x = x.url + "receive/"} xml = Post.build_xml_for(self) diff --git a/spec/controllers/sockets_controller_spec.rb b/spec/controllers/sockets_controller_spec.rb index aba8d9f52..6c4dac866 100644 --- a/spec/controllers/sockets_controller_spec.rb +++ b/spec/controllers/sockets_controller_spec.rb @@ -4,10 +4,11 @@ describe 'SocketsController' do render_views before do @user = Factory.create(:user) - @user.person.save SocketsController.unstub!(:new) #EventMachine::WebSocket.stub!(:start) @controller = SocketsController.new + @controller.request = mock_model(Request, :env => + {'warden' => mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user)}) stub_sockets_controller end @@ -22,7 +23,7 @@ describe 'SocketsController' do end describe 'actionhash' do before do - @message = Factory.create(:status_message, :person => @user) + @message = @user.post :status_message, :message => "post through user for victory" end it 'should actionhash posts' do diff --git a/spec/lib/web_hooks_spec.rb b/spec/lib/web_hooks_spec.rb index 71e3ed71f..32a8d4cb0 100644 --- a/spec/lib/web_hooks_spec.rb +++ b/spec/lib/web_hooks_spec.rb @@ -38,10 +38,8 @@ describe Diaspora do end it "should send an owners post to their people" do - q = Post.send(:class_variable_get, :@@queue) - q.should_receive :process + message_queue.should_receive :process @user.post :status_message, :message => "hi" - @post.save end it "should check that it does not send a person's post to an owners people" do diff --git a/spec/models/comments_spec.rb b/spec/models/comments_spec.rb index 3f0d03659..5dc7ca2c2 100644 --- a/spec/models/comments_spec.rb +++ b/spec/models/comments_spec.rb @@ -25,7 +25,7 @@ describe Comment do it 'should not send out comments when we have no people' do status = Factory.create(:status_message, :person => @user.person) - Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request) + message_queue.should_not_receive(:add_post_request) @user.comment "sup dog", :on => status end @@ -40,29 +40,28 @@ describe Comment do end it "should send a user's comment on a person's post to that person" do - Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request) + message_queue.should_receive(:add_post_request) @user.comment "yo", :on => @person_status end it 'should send a user comment on his own post to lots of people' do allowed_urls = @user_status.people_with_permissions.map!{|x| x = x.url + "receive/"} puts allowed_urls - queue = Comment.send(:class_variable_get, :@@queue) - queue.should_receive(:add_post_request).with(allowed_urls, anything) + message_queue.should_receive(:add_post_request).with(allowed_urls, anything) @user.comment "yo", :on => @user_status end it 'should send a comment a person made on your post to all people' do - Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request) + message_queue.should_receive(:add_post_request) @person.comment "balls", :on => @user_status end it 'should not send a comment a person made on his own post to anyone' do - Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request) + message_queue.should_not_receive(:add_post_request) @person.comment "balls", :on => @person_status end it 'should not send a comment a person made on a person post to anyone' do - Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request) + message_queue.should_not_receive(:add_post_request) @person2.comment "balls", :on => @person_status end end diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 403dc463b..6b57913d4 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -19,7 +19,7 @@ describe Photo do photo.image.read.nil?.should be false end - it 'should save a @photo to GridFS' do + it 'should save a photo to GridFS' do @photo.image.store! File.open(@fixture_name) @photo.save.should == true binary = @photo.image.read @@ -92,7 +92,7 @@ describe Photo do stub_signature_verification end - it 'should save a signed @photo to GridFS' do + it 'should save a signed photo to GridFS' do photo = Photo.create(:person => @user.person, :album => @album, :image => File.open(@fixture_name)) photo.save.should == true photo.verify_creator_signature.should be true diff --git a/spec/models/retraction_spec.rb b/spec/models/retraction_spec.rb index f33557eda..9ccaa1c5e 100644 --- a/spec/models/retraction_spec.rb +++ b/spec/models/retraction_spec.rb @@ -3,7 +3,11 @@ require File.dirname(__FILE__) + '/../spec_helper' describe Retraction do before do @user = Factory.create(:user) - @post = Factory.create(:status_message, :person => @user) + @user.person.save + @post = @user.post(:status_message, :message => "Destroy!") + @person = Factory.create(:person) + @user.friends << @person + @user.save end describe 'serialization' do it 'should have a post id after serialization' do @@ -15,7 +19,7 @@ describe Retraction do describe 'dispatching' do it 'should dispatch a message on delete' do Factory.create(:person) - Post.send(:class_variable_get, :@@queue).should_receive(:add_post_request) + message_queue.should_receive(:add_post_request) @post.destroy end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0356a06ee..ea24f1bd7 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -55,8 +55,7 @@ describe User do updated_profile = {:profile => {:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com"}} - queue = Profile.send :class_variable_get, :@@queue - queue.should_receive(:process) + message_queue.should_receive(:process) @user.person.update_profile(updated_profile).should == true @user.profile.image_url.should == "http://clown.com" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9eba3000c..fb730c6db 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -71,3 +71,7 @@ end end models end + + def message_queue + Post.send(:class_variable_get, :@@queue) + end diff --git a/spec/user_encryption_spec.rb b/spec/user_encryption_spec.rb index 729920af2..1506a123d 100644 --- a/spec/user_encryption_spec.rb +++ b/spec/user_encryption_spec.rb @@ -36,8 +36,8 @@ describe 'user encryption' do @user.key.should_not be nil end describe 'key exchange on friending' do - it 'should send over a public key' do - Comment.send(:class_variable_get, :@@queue).stub!(:add_post_request) + it 'should send over a public key' do + message_queue.stub!(:add_post_request) request = @user.send_friend_request_to("http://example.com/") Request.build_xml_for([request]).include?( @user.export_key).should be true end