From f259f281f66571c0e61495a6800c169d54ec811a Mon Sep 17 00:00:00 2001 From: Mark Burns Date: Sat, 7 Apr 2012 11:45:16 +0100 Subject: [PATCH] further spec DRYed up with em_stream method call --- spec/integration/integration_spec.rb | 48 ++++++++++++---------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/spec/integration/integration_spec.rb b/spec/integration/integration_spec.rb index 8781f593..4ac362e0 100644 --- a/spec/integration/integration_spec.rb +++ b/spec/integration/integration_spec.rb @@ -313,42 +313,36 @@ def stream websocket, messages context 'with more than one subscriber subscribed to the channel' do it 'sends a member added message to the existing subscribers' do - messages = [] + messages = em_stream do |user1, messages| + if messages.one? + attributes = { user_id: '0f177369a3b71275d25ab1b44db9f95f', + user_info: { name: 'SG' } } - em_thread do - user1 = new_websocket + id = messages.first['data']['socket_id'] - stream(user1, messages) do |message| - if messages.length == 1 - auth = Pusher['presence-channel'].authenticate(messages.first['data']['socket_id'], { - user_id: '0f177369a3b71275d25ab1b44db9f95f', + auth = Pusher['presence-channel'].authenticate(id, attributes) + + user1.send({ event: 'pusher:subscribe', + data: { channel: 'presence-channel'}.merge(auth)}. + to_json) + + elsif messages.length == 2 + user2 = new_websocket + user2.stream do |message| + auth2 = Pusher['presence-channel'].authenticate(JSON.parse(message)['data']['socket_id'], { + user_id: '37960509766262569d504f02a0ee986d', user_info: { - name: 'SG' + name: 'CHROME' } }) - user1.send({ + user2.send({ event: 'pusher:subscribe', data: { channel: 'presence-channel' - }.merge(auth) + }.merge(auth2) }.to_json) - elsif messages.length == 2 - user2 = new_websocket - user2.stream do |message| - auth2 = Pusher['presence-channel'].authenticate(JSON.parse(message)['data']['socket_id'], { - user_id: '37960509766262569d504f02a0ee986d', - user_info: { - name: 'CHROME' - } - }) - user2.send({ - event: 'pusher:subscribe', data: { - channel: 'presence-channel' - }.merge(auth2) - }.to_json) - end - elsif messages.length == 3 - EM.stop end + elsif messages.length == 3 + EM.stop end end