From 71ac61c01d8166b8f6354f65bb8c166d293d6c5b Mon Sep 17 00:00:00 2001 From: Raphael Date: Fri, 17 Sep 2010 12:49:05 -0700 Subject: [PATCH] Fix websocket specs --- spec/lib/websocket_spec.rb | 20 ++++++++++++++++---- spec/spec_helper.rb | 8 +++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/spec/lib/websocket_spec.rb b/spec/lib/websocket_spec.rb index 762a725b5..018f5020d 100644 --- a/spec/lib/websocket_spec.rb +++ b/spec/lib/websocket_spec.rb @@ -9,6 +9,7 @@ describe Diaspora::WebSocket do @user = Factory.create(:user) @aspect = @user.aspect(:name => "losers") @post = @user.build_post(:status_message, :message => "hey", :to => @aspect.id) + unstub_sockets end it 'should queue a job' do @@ -16,10 +17,21 @@ describe Diaspora::WebSocket do @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) end - it 'The queued job should reach Magent' do - @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) - channel = Magent::GenericChannel.new('websocket') - channel.message_count.should == 1 + describe 'queuing and dequeuing ' do + before do + @post.socket_to_uid(@user.id, :aspect_ids => @aspect.id) + @channel = Magent::GenericChannel.new('websocket') + end + + it 'should send the queued job to Magent' do + @channel.message_count.should == 1 + end + + it 'should dequeue the job successfully' do + messages = @channel.message_count + @channel.dequeue + @channel.message_count.should == messages -1 + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c3995846e..3fdac9810 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -46,11 +46,17 @@ RSpec.configure do |config| end end def stub_sockets - Diaspora::WebSocket.stub!(:push_to_user).and_return(true) + Diaspora::WebSocket.stub!(:queue_to_user).and_return(true) Diaspora::WebSocket.stub!(:subscribe).and_return(true) Diaspora::WebSocket.stub!(:unsubscribe).and_return(true) end + def unstub_sockets + Diaspora::WebSocket.unstub!(:queue_to_user) + Diaspora::WebSocket.unstub!(:subscribe) + Diaspora::WebSocket.unstub!(:unsubscribe) + end + def stub_signature_verification (get_models.map{|model| model.camelize.constantize} - [User]).each do |model| model.any_instance.stubs(:verify_signature).returns(true)