Fix websocket specs

This commit is contained in:
Raphael 2010-09-17 12:49:05 -07:00
parent a96a52def7
commit 71ac61c01d
2 changed files with 23 additions and 5 deletions

View file

@ -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

View file

@ -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)