websocket-rails 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/CHANGELOG.md +22 -0
  2. data/Gemfile +4 -0
  3. data/README.md +66 -159
  4. data/Rakefile +31 -4
  5. data/bin/thin-socketrails +16 -1
  6. data/lib/assets/javascripts/websocket_rails/channel.js.coffee +23 -8
  7. data/lib/assets/javascripts/websocket_rails/event.js.coffee +40 -0
  8. data/lib/assets/javascripts/websocket_rails/http_connection.js.coffee +18 -10
  9. data/lib/assets/javascripts/websocket_rails/main.js +1 -0
  10. data/lib/assets/javascripts/websocket_rails/websocket_connection.js.coffee +15 -10
  11. data/lib/assets/javascripts/websocket_rails/websocket_rails.js.coffee +41 -23
  12. data/lib/websocket-rails.rb +4 -4
  13. data/lib/websocket_rails/base_controller.rb +61 -29
  14. data/lib/websocket_rails/channel.rb +14 -5
  15. data/lib/websocket_rails/channel_manager.rb +3 -1
  16. data/lib/websocket_rails/connection_adapters.rb +34 -12
  17. data/lib/websocket_rails/connection_manager.rb +4 -0
  18. data/lib/websocket_rails/dispatcher.rb +27 -3
  19. data/lib/websocket_rails/engine.rb +2 -5
  20. data/lib/websocket_rails/event.rb +87 -42
  21. data/lib/websocket_rails/event_map.rb +70 -20
  22. data/lib/websocket_rails/event_queue.rb +4 -0
  23. data/lib/websocket_rails/internal_events.rb +21 -3
  24. data/lib/websocket_rails/logging.rb +18 -0
  25. data/lib/websocket_rails/version.rb +1 -1
  26. data/spec/dummy/log/test.log +0 -429
  27. data/spec/integration/connection_manager_spec.rb +3 -5
  28. data/spec/javascripts/generated/assets/channel.js +98 -0
  29. data/spec/javascripts/generated/assets/event.js +78 -0
  30. data/spec/javascripts/generated/assets/http_connection.js +108 -0
  31. data/spec/javascripts/generated/assets/websocket_connection.js +66 -0
  32. data/spec/javascripts/generated/assets/websocket_rails.js +180 -0
  33. data/spec/javascripts/generated/specs/channel_spec.js +66 -0
  34. data/spec/javascripts/generated/specs/event_spec.js +107 -0
  35. data/spec/javascripts/generated/specs/websocket_connection_spec.js +117 -0
  36. data/spec/javascripts/generated/specs/websocket_rails_spec.js +232 -0
  37. data/spec/javascripts/support/jasmine.yml +44 -0
  38. data/spec/javascripts/support/jasmine_config.rb +63 -0
  39. data/spec/javascripts/support/vendor/sinon-1.3.4.js +3555 -0
  40. data/spec/javascripts/websocket_rails/channel_spec.coffee +51 -0
  41. data/spec/javascripts/websocket_rails/event_spec.coffee +69 -0
  42. data/spec/javascripts/websocket_rails/websocket_connection_spec.coffee +86 -0
  43. data/spec/javascripts/websocket_rails/websocket_rails_spec.coffee +166 -0
  44. data/spec/support/helper_methods.rb +10 -1
  45. data/spec/unit/channel_spec.rb +28 -4
  46. data/spec/unit/connection_adapters_spec.rb +17 -0
  47. data/spec/unit/connection_manager_spec.rb +1 -1
  48. data/spec/unit/dispatcher_spec.rb +1 -1
  49. data/spec/unit/event_spec.rb +15 -11
  50. metadata +22 -4
@@ -0,0 +1,51 @@
1
+ describe 'WebSocketRails.Channel:', ->
2
+ beforeEach ->
3
+ @dispatcher =
4
+ new_message: -> true
5
+ dispatch: -> true
6
+ trigger_event: (event) -> true
7
+ state: 'connected'
8
+ connection_id: 12345
9
+ @channel = new WebSocketRails.Channel('public',@dispatcher)
10
+ sinon.spy @dispatcher, 'trigger_event'
11
+
12
+ afterEach ->
13
+ @dispatcher.trigger_event.restore()
14
+
15
+ describe 'public channels', ->
16
+ beforeEach ->
17
+ @channel = new WebSocketRails.Channel('forchan',@dispatcher,false)
18
+ @event = @dispatcher.trigger_event.lastCall.args[0]
19
+
20
+ it 'should trigger an event containing the channel name', ->
21
+ expect(@event.data.channel).toEqual 'forchan'
22
+
23
+ it 'should trigger an event containing the correct connection_id', ->
24
+ expect(@event.connection_id).toEqual 12345
25
+
26
+ it 'should initialize an empty callbacks property', ->
27
+ expect(@channel._callbacks).toBeDefined()
28
+ expect(@channel._callbacks).toEqual {}
29
+
30
+ it 'should be public', ->
31
+ expect(@channel.is_private).toBeFalsy
32
+
33
+ describe '.bind', ->
34
+ it 'should add a function to the callbacks collection', ->
35
+ test_func = ->
36
+ @channel.bind 'event_name', test_func
37
+ expect(@channel._callbacks['event_name'].length).toBe 1
38
+ expect(@channel._callbacks['event_name']).toContain test_func
39
+
40
+ describe 'private channels', ->
41
+ beforeEach ->
42
+ @channel = new WebSocketRails.Channel('forchan',@dispatcher,true)
43
+ @event = @dispatcher.trigger_event.lastCall.args[0]
44
+
45
+ it 'should trigger a subscribe_private event when created', ->
46
+ expect(@event.name).toEqual 'websocket_rails.subscribe_private'
47
+
48
+ it 'should be private', ->
49
+ expect(@channel.is_private).toBe true
50
+
51
+
@@ -0,0 +1,69 @@
1
+ describe 'WebSocketRails.Event', ->
2
+
3
+ describe 'standard events', ->
4
+ beforeEach ->
5
+ @data = ['event',{data: { message: 'test'} },12345]
6
+ @event = new WebSocketRails.Event(@data)
7
+
8
+ it 'should generate an ID', ->
9
+ expect(@event.id).not.toBeNull
10
+
11
+ it 'should have a connection ID', ->
12
+ expect(@event.connection_id).toEqual 12345
13
+
14
+ it 'should assign the correct properties when passed a data array', ->
15
+ expect(@event.name).toEqual 'event'
16
+ expect(@event.data.message).toEqual 'test'
17
+
18
+ describe '.serialize()', ->
19
+ it 'should serialize the event as JSON', ->
20
+ @event.id = 1
21
+ serialized = "[\"event\",{\"id\":1,\"data\":{\"message\":\"test\"}}]"
22
+ expect(@event.serialize()).toEqual serialized
23
+
24
+ describe '.is_channel()', ->
25
+ it 'should be false', ->
26
+ expect(@event.is_channel()).toEqual false
27
+
28
+ describe 'channel events', ->
29
+ beforeEach ->
30
+ @data = ['event',{channel:'channel',data:{message: 'test'}}]
31
+ @event = new WebSocketRails.Event(@data)
32
+
33
+ it 'should assign the channel property', ->
34
+ expect(@event.channel).toEqual 'channel'
35
+ expect(@event.name).toEqual 'event'
36
+ expect(@event.data.message).toEqual 'test'
37
+
38
+ describe '.is_channel()', ->
39
+ it 'should be true', ->
40
+ expect(@event.is_channel()).toEqual true
41
+
42
+ describe '.serialize()', ->
43
+ it 'should serialize the event as JSON', ->
44
+ @event.id = 1
45
+ serialized = "[\"event\",{\"id\":1,\"channel\":\"channel\",\"data\":{\"message\":\"test\"}}]"
46
+ expect(@event.serialize()).toEqual serialized
47
+
48
+ describe '.run_callbacks()', ->
49
+ beforeEach ->
50
+ success_func = (data) ->
51
+ data
52
+ failure_func = (data) ->
53
+ data
54
+ @data = ['event',{data: { message: 'test'} },12345]
55
+ @event = new WebSocketRails.Event(@data,success_func,failure_func)
56
+
57
+ describe 'when successful', ->
58
+ it 'should run the success callback when passed true', ->
59
+ expect(@event.run_callbacks(true,'success')).toEqual 'success'
60
+
61
+ it 'should not run the failure callback', ->
62
+ expect(@event.run_callbacks(true,'success')).toBeUndefined
63
+
64
+ describe 'when failure', ->
65
+ it 'should run the failure callback when passed true', ->
66
+ expect(@event.run_callbacks(false,'failure')).toEqual 'failure'
67
+
68
+ it 'should not run the failure callback', ->
69
+ expect(@event.run_callbacks(false,'failure')).toBeUndefined
@@ -0,0 +1,86 @@
1
+ describe 'WebsocketRails.WebSocketConnection:', ->
2
+ beforeEach ->
3
+ dispatcher =
4
+ new_message: -> true
5
+ dispatch: -> true
6
+ state: 'connected'
7
+ # Have to stub the WebSocket object due to Firefox error during jasmine:ci
8
+ window.WebSocket = (url) ->
9
+ @url = url
10
+ @send = -> true
11
+ @connection = new WebSocketRails.WebSocketConnection('localhost:3000/websocket',dispatcher)
12
+
13
+ describe 'constructor', ->
14
+
15
+ it 'should set the onmessage event on the WebSocket object to this.on_message', ->
16
+ expect(@connection._conn.onmessage).toEqual @connection.on_message
17
+
18
+ it 'should set the onclose event on the WebSocket object to this.on_close', ->
19
+ expect(@connection._conn.onclose).toEqual @connection.on_close
20
+
21
+ describe 'with ssl', ->
22
+ it 'should not add the ws:// prefix to the URL', ->
23
+ connection = new WebSocketRails.WebSocketConnection('wss://localhost.com')
24
+ expect(connection.url).toEqual 'wss://localhost.com'
25
+
26
+ describe 'without ssl', ->
27
+ it 'should add the ws:// prefix to the URL', ->
28
+ expect(@connection.url).toEqual 'ws://localhost:3000/websocket'
29
+
30
+ describe '.trigger', ->
31
+
32
+ describe 'before the connection has been fully established', ->
33
+ it 'should queue up the events', ->
34
+ @connection.dispatcher.state = 'connecting'
35
+ event = new WebSocketRails.Event ['event','message']
36
+ mock_queue = sinon.mock @connection.message_queue
37
+ mock_queue.expects('push').once().withArgs event
38
+
39
+ describe 'after the connection has been fully established', ->
40
+ it 'should encode the data and send it through the WebSocket object', ->
41
+ @connection.dispatcher.state = 'connected'
42
+ event = new WebSocketRails.Event ['event','message']
43
+ @connection._conn =
44
+ send: -> true
45
+ mock_connection = sinon.mock @connection._conn
46
+ mock_connection.expects('send').once().withArgs event.serialize()
47
+ @connection.trigger event
48
+ mock_connection.verify()
49
+
50
+ describe '.on_message', ->
51
+
52
+ it 'should decode the message and pass it to the dispatcher', ->
53
+ encoded_data = JSON.stringify ['event','message']
54
+ event =
55
+ data: encoded_data
56
+ mock_dispatcher = sinon.mock @connection.dispatcher
57
+ mock_dispatcher.expects('new_message').once().withArgs JSON.parse encoded_data
58
+ @connection.on_message event
59
+ mock_dispatcher.verify()
60
+
61
+ describe '.on_close', ->
62
+
63
+ it 'should dispatch the connection_closed event', ->
64
+ mock_dispatcher = sinon.mock @connection.dispatcher
65
+ mock_dispatcher.expects('dispatch').once()
66
+ @connection.on_close()
67
+ mock_dispatcher.verify()
68
+
69
+ describe '.flush_queue', ->
70
+ beforeEach ->
71
+ @event = new WebSocketRails.Event ['event','message']
72
+ @connection.message_queue.push @event
73
+ @connection._conn =
74
+ send: -> true
75
+
76
+ it 'should send out all of the messages in the queue', ->
77
+ mock_connection = sinon.mock @connection._conn
78
+ mock_connection.expects('send').once().withArgs @event.serialize()
79
+ @connection.flush_queue()
80
+ mock_connection.verify()
81
+
82
+ it 'should empty the queue after sending', ->
83
+ expect( @connection.message_queue.length ).toEqual 1
84
+ @connection.flush_queue()
85
+ expect( @connection.message_queue.length ).toEqual 0
86
+
@@ -0,0 +1,166 @@
1
+ describe 'WebSocketRails:', ->
2
+ beforeEach ->
3
+ @url = 'localhost:3000/websocket'
4
+ WebSocketRails.WebSocketConnection = ->
5
+ connection_type: 'websocket'
6
+ flush_queue: -> true
7
+ WebSocketRails.HttpConnection = ->
8
+ connection_type: 'http'
9
+ flush_queue: -> true
10
+ @dispatcher = new WebSocketRails @url
11
+
12
+ describe 'constructor', ->
13
+
14
+ it 'should set the new_message method on connection to this.new_message', ->
15
+ expect(@dispatcher._conn.new_message).toEqual @dispatcher.new_message
16
+
17
+ it 'should set the initial state to connecting', ->
18
+ expect(@dispatcher.state).toEqual 'connecting'
19
+
20
+ describe 'when use_websockets is true', ->
21
+ it 'should use the WebSocket Connection', ->
22
+ dispatcher = new WebSocketRails @url, true
23
+ expect(dispatcher._conn.connection_type).toEqual 'websocket'
24
+
25
+ describe 'when use_webosckets is false', ->
26
+ it 'should use the Http Connection', ->
27
+ dispatcher = new WebSocketRails @url, false
28
+ expect(dispatcher._conn.connection_type).toEqual 'http'
29
+
30
+ describe 'when the browser does not support WebSockets', ->
31
+ it 'should use the Http Connection', ->
32
+ window.WebSocket = 'undefined'
33
+ dispatcher = new WebSocketRails @url, true
34
+ expect(dispatcher._conn.connection_type).toEqual 'http'
35
+
36
+ describe '.new_message', ->
37
+
38
+ describe 'when this.state is "connecting"', ->
39
+ beforeEach ->
40
+ @message =
41
+ data:
42
+ connection_id: 123
43
+ @data = [['client_connected', @message]]
44
+
45
+ it 'should call this.connection_established on the "client_connected" event', ->
46
+ mock_dispatcher = sinon.mock @dispatcher
47
+ mock_dispatcher.expects('connection_established').once().withArgs @message.data
48
+ @dispatcher.new_message @data
49
+ mock_dispatcher.verify()
50
+
51
+ it 'should set the state to connected', ->
52
+ @dispatcher.new_message @data
53
+ expect(@dispatcher.state).toEqual 'connected'
54
+
55
+ it 'should flush any messages queued before the connection was established', ->
56
+ mock_con = sinon.mock @dispatcher._conn
57
+ mock_con.expects('flush_queue').once()
58
+ @dispatcher.new_message @data
59
+ mock_con.verify()
60
+
61
+ it 'should set the correct connection_id', ->
62
+ @dispatcher.new_message @data
63
+ expect(@dispatcher.connection_id).toEqual 123
64
+
65
+ it 'should call the user defined on_open callback', ->
66
+ spy = sinon.spy()
67
+ @dispatcher.on_open = spy
68
+ @dispatcher.new_message @data
69
+ expect(spy.calledOnce).toEqual true
70
+
71
+ describe 'after the connection has been established', ->
72
+ beforeEach ->
73
+ @dispatcher.state = 'connected'
74
+ @attributes =
75
+ data: 'message'
76
+ channel: 'channel'
77
+
78
+ it 'should dispatch channel messages', ->
79
+ data = [['event',@attributes]]
80
+ mock_dispatcher = sinon.mock @dispatcher
81
+ mock_dispatcher.expects('dispatch_channel').once()
82
+ @dispatcher.new_message data
83
+ mock_dispatcher.verify()
84
+
85
+ it 'should dispatch standard events', ->
86
+ data = [['event','message']]
87
+ mock_dispatcher = sinon.mock @dispatcher
88
+ mock_dispatcher.expects('dispatch').once()
89
+ @dispatcher.new_message data
90
+ mock_dispatcher.verify()
91
+
92
+ describe 'result events', ->
93
+ beforeEach ->
94
+ @attributes['success'] = true
95
+ @attributes['id'] = 1
96
+ @event = { run_callbacks: (data) -> }
97
+ @event_mock = sinon.mock @event
98
+ @dispatcher.queue[1] = @event
99
+
100
+ it 'should run callbacks for result events', ->
101
+ data = [['event',@attributes]]
102
+ @event_mock.expects('run_callbacks').once()
103
+ @dispatcher.new_message data
104
+ @event_mock.verify()
105
+
106
+ describe '.bind', ->
107
+
108
+ it 'should store the callback on the correct event', ->
109
+ callback = ->
110
+ @dispatcher.bind 'event', callback
111
+ expect(@dispatcher.callbacks['event']).toContain callback
112
+
113
+ describe '.dispatch', ->
114
+
115
+ it 'should execute the callback for the correct event', ->
116
+ callback = sinon.spy()
117
+ event = new WebSocketRails.Event(['event',{data: 'message'}])
118
+ @dispatcher.bind 'event', callback
119
+ @dispatcher.dispatch event
120
+ expect(callback.calledWith('message')).toEqual true
121
+
122
+ describe 'triggering events with', ->
123
+ beforeEach ->
124
+ @dispatcher.connection_id = 123
125
+ @dispatcher._conn =
126
+ trigger: ->
127
+ trigger_channel: ->
128
+
129
+ describe '.trigger', ->
130
+
131
+ it 'should delegate to the connection object', ->
132
+ con_trigger = sinon.spy @dispatcher._conn, 'trigger'
133
+ @dispatcher.trigger 'event', 'message'
134
+ event = new WebSocketRails.Event ['websocket_rails.subscribe', {channel: 'awesome'}, 123]
135
+ expect(con_trigger.called).toEqual true
136
+
137
+ describe 'working with channels', ->
138
+ beforeEach ->
139
+ WebSocketRails.Channel = (@name,@dispatcher,@is_private) ->
140
+
141
+ describe '.subscribe', ->
142
+ describe 'for new channels', ->
143
+ it 'should create and store a new Channel object', ->
144
+ channel = @dispatcher.subscribe 'test_channel'
145
+ expect(channel.name).toEqual 'test_channel'
146
+
147
+ describe 'for existing channels', ->
148
+ it 'should return the same Channel object', ->
149
+ channel = @dispatcher.subscribe 'test_channel'
150
+ expect(@dispatcher.subscribe('test_channel')).toEqual channel
151
+
152
+ describe '.subscribe_private', ->
153
+ it 'should create private channels', ->
154
+ private_channel = @dispatcher.subscribe_private 'private_something'
155
+ expect(private_channel.is_private).toBe true
156
+
157
+ describe '.dispatch_channel', ->
158
+
159
+ it 'should delegate to the Channel object', ->
160
+ channel = @dispatcher.subscribe 'test'
161
+ channel.dispatch = ->
162
+ spy = sinon.spy channel, 'dispatch'
163
+ event = new WebSocketRails.Event(['event',{channel: 'test', data: 'awesome'}])
164
+ @dispatcher.dispatch_channel event
165
+ expect(spy.calledWith('event', 'awesome')).toEqual true
166
+
@@ -15,7 +15,11 @@ module WebsocketRails
15
15
  end
16
16
 
17
17
  def encoded_message
18
- ['test_event',{:user_name => 'Joe User'}].to_json
18
+ ['test_event',{:data => {:user_name => 'Joe User'}}].to_json
19
+ end
20
+
21
+ def subscribe_encoded_message
22
+ ['websocket_rails.subscribe',:data => nil, :channel => :awesome_channel].to_json
19
23
  end
20
24
 
21
25
  def received_encoded_message(connection_id)
@@ -30,4 +34,9 @@ module EM
30
34
  def self.next_tick(&block)
31
35
  block.call if block.respond_to?(:call)
32
36
  end
37
+ class PeriodicTimer
38
+ def initialize(interval)
39
+ @interval = interval
40
+ end
41
+ end
33
42
  end
@@ -24,15 +24,14 @@ module WebsocketRails
24
24
  describe "#trigger" do
25
25
  it "should create a new event and trigger it on all subscribers" do
26
26
  event = double('event').as_null_object
27
- Event.should_receive(:new) do |name,data,options|
27
+ Event.should_receive(:new) do |name,data|
28
28
  name.should == 'event'
29
- data.should == 'data'
30
- options.should be_a Hash
29
+ data[:data].should == 'data'
31
30
  event
32
31
  end
33
32
  connection.should_receive(:trigger).with(event)
34
33
  subject.subscribe connection
35
- subject.trigger 'event', 'data'
34
+ subject.trigger 'event', :data => 'data'
36
35
  end
37
36
  end
38
37
 
@@ -42,5 +41,30 @@ module WebsocketRails
42
41
  subject.trigger_event 'event'
43
42
  end
44
43
  end
44
+
45
+ context "private channels" do
46
+ it "should be public by default" do
47
+ subject.instance_variable_get(:@private).should_not be_true
48
+ end
49
+
50
+ describe "#make_private" do
51
+ it "should set the @private instance variable to true" do
52
+ subject.make_private
53
+ subject.instance_variable_get(:@private).should be_true
54
+ end
55
+ end
56
+
57
+ describe "#is_private?" do
58
+ it "should return true if the channel is private" do
59
+ subject.instance_variable_set(:@private,true)
60
+ subject.is_private?.should be_true
61
+ end
62
+
63
+ it "should return false if the channel is public" do
64
+ subject.instance_variable_set(:@private,false)
65
+ subject.is_private?.should_not be_true
66
+ end
67
+ end
68
+ end
45
69
  end
46
70
  end
@@ -97,7 +97,9 @@ module WebsocketRails
97
97
  end
98
98
 
99
99
  describe "#trigger" do
100
+ =begin
100
101
  it "should add the event to the queue" do
102
+ pending
101
103
  subject.stub(:flush)
102
104
  subject.should_receive(:enqueue).with('event')
103
105
  subject.trigger 'event'
@@ -107,6 +109,21 @@ module WebsocketRails
107
109
  subject.should_receive(:flush)
108
110
  subject.trigger 'event'
109
111
  end
112
+ =end
113
+ end
114
+
115
+ describe "#flush" do
116
+ before do
117
+ event = double('event')
118
+ event.stub!(:serialize).and_return("['event']")
119
+ 3.times { subject.enqueue event }
120
+ end
121
+
122
+ it "should serialize all events into one array" do
123
+ serialized_array = "[['event'],['event'],['event']]"
124
+ subject.should_receive(:send).with(serialized_array)
125
+ subject.flush
126
+ end
110
127
  end
111
128
  end
112
129
  end
@@ -58,7 +58,7 @@ module WebsocketRails
58
58
  before(:each) { open_connection }
59
59
 
60
60
  it "should dispatch the appropriate event through the Dispatcher" do
61
- mock_event = ["new_message","data"].to_json
61
+ mock_event = ["new_message",{:data =>"data"}].to_json
62
62
  dispatcher.should_receive(:dispatch) do |event|
63
63
  event.name.should == :new_message
64
64
  event.data.should == "data"
@@ -65,7 +65,7 @@ module WebsocketRails
65
65
 
66
66
  context "channel events" do
67
67
  it "should forward the data to the correct channel" do
68
- event = Event.new 'test', 'data', :channel => :awesome_channel
68
+ event = Event.new 'test', :data => 'data', :channel => :awesome_channel
69
69
  channel = double('channel')
70
70
  channel.should_receive(:trigger_event).with(event)
71
71
  WebsocketRails.should_receive(:[]).with(:awesome_channel).and_return(channel)
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  module WebsocketRails
4
4
  describe Event do
5
- let(:encoded_message) { '["new_message",{"message":"this is a message"}]' }
6
- let(:encoded_message_string) { '["new_message","this is a message"]' }
7
- let(:namespace_encoded_message_string) { '["product.new_message","this is a message"]' }
8
- let(:namespace_encoded_message) { '["product.new_message",{"message":"this is a message"}]' }
9
- let(:channel_encoded_message_string) { '["awesome_channel","new_message","this is a message"]' }
5
+ let(:encoded_message) { '["new_message",{"id":"1234","data":{"message":"this is a message"}}]' }
6
+ let(:encoded_message_string) { '["new_message",{"id":"1234","data":"this is a message"}]' }
7
+ let(:namespace_encoded_message_string) { '["product.new_message",{"id":"1234","data":"this is a message"}]' }
8
+ let(:namespace_encoded_message) { '["product.new_message",{"id":"1234","data":{"message":"this is a message"}}]' }
9
+ let(:channel_encoded_message_string) { '["new_message",{"id":"1234","channel":"awesome_channel","data":"this is a message","success":null,"result":null}]' }
10
10
  let(:connection) { double('connection') }
11
11
 
12
12
  before { connection.stub!(:id).and_return(1) }
@@ -68,13 +68,13 @@ module WebsocketRails
68
68
 
69
69
  context "new namespaced events" do
70
70
  it "should store the namespace in the namespace attribute" do
71
- event = Event.new "event", {}, :connection => connection, :namespace => :product
71
+ event = Event.new "event", :data => {}, :connection => connection, :namespace => :product
72
72
  event.namespace.should == [:global,:product]
73
73
  event.name.should == :event
74
74
  end
75
75
 
76
76
  it "should store nested namespaces in the namespace attribute" do
77
- event = Event.new "event", {}, :connection => connection, :namespace => [:product,:x_ray_vision]
77
+ event = Event.new "event", :data => {}, :connection => connection, :namespace => [:product,:x_ray_vision]
78
78
  event.namespace.should == [:global,:product,:x_ray_vision]
79
79
  event.name.should == :event
80
80
  end
@@ -82,7 +82,7 @@ module WebsocketRails
82
82
 
83
83
  context "new channel events" do
84
84
  it "should store the channel name in the channel attribute" do
85
- event = Event.new "event", {}, :connection => connection, :channel => :awesome_channel
85
+ event = Event.new "event", :data => {}, :connection => connection, :channel => :awesome_channel
86
86
  event.channel.should == :awesome_channel
87
87
  event.name.should == :event
88
88
  end
@@ -90,7 +90,7 @@ module WebsocketRails
90
90
 
91
91
  describe "#is_channel?" do
92
92
  it "should return true if an event belongs to a channel" do
93
- event = Event.new "event", "data", :channel => :awesome_channel
93
+ event = Event.new "event", :data => "data", :channel => :awesome_channel
94
94
  event.is_channel?.should be_true
95
95
  end
96
96
  end
@@ -99,14 +99,18 @@ module WebsocketRails
99
99
  context "messages in the global namespace" do
100
100
  it "should not add the global namespace to the event name" do
101
101
  event = Event.new_from_json encoded_message_string, connection
102
- event.serialize.should == encoded_message_string
102
+ raw_data = event.serialize
103
+ data = JSON.parse raw_data
104
+ data[0].should == "new_message"
103
105
  end
104
106
  end
105
107
 
106
108
  context "messages in a child namespace" do
107
109
  it "should add the namespace to the front of the event name" do
108
110
  event = Event.new_from_json namespace_encoded_message_string, connection
109
- event.serialize.should == namespace_encoded_message_string
111
+ raw_data = event.serialize
112
+ data = JSON.parse raw_data
113
+ data[0].should == "product.new_message"
110
114
  end
111
115
  end
112
116
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-07-04 00:00:00.000000000Z
14
+ date: 2012-07-17 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -118,6 +118,7 @@ extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
120
  - lib/assets/javascripts/websocket_rails/channel.js.coffee
121
+ - lib/assets/javascripts/websocket_rails/event.js.coffee
121
122
  - lib/assets/javascripts/websocket_rails/http_connection.js.coffee
122
123
  - lib/assets/javascripts/websocket_rails/main.js
123
124
  - lib/assets/javascripts/websocket_rails/websocket_connection.js.coffee
@@ -139,6 +140,7 @@ files:
139
140
  - lib/websocket_rails/event_map.rb
140
141
  - lib/websocket_rails/event_queue.rb
141
142
  - lib/websocket_rails/internal_events.rb
143
+ - lib/websocket_rails/logging.rb
142
144
  - lib/websocket_rails/version.rb
143
145
  - config/routes.rb
144
146
  - bin/thin-socketrails
@@ -180,6 +182,22 @@ files:
180
182
  - spec/dummy/Rakefile
181
183
  - spec/dummy/script/rails
182
184
  - spec/integration/connection_manager_spec.rb
185
+ - spec/javascripts/generated/assets/channel.js
186
+ - spec/javascripts/generated/assets/event.js
187
+ - spec/javascripts/generated/assets/http_connection.js
188
+ - spec/javascripts/generated/assets/websocket_connection.js
189
+ - spec/javascripts/generated/assets/websocket_rails.js
190
+ - spec/javascripts/generated/specs/channel_spec.js
191
+ - spec/javascripts/generated/specs/event_spec.js
192
+ - spec/javascripts/generated/specs/websocket_connection_spec.js
193
+ - spec/javascripts/generated/specs/websocket_rails_spec.js
194
+ - spec/javascripts/support/jasmine.yml
195
+ - spec/javascripts/support/jasmine_config.rb
196
+ - spec/javascripts/support/vendor/sinon-1.3.4.js
197
+ - spec/javascripts/websocket_rails/channel_spec.coffee
198
+ - spec/javascripts/websocket_rails/event_spec.coffee
199
+ - spec/javascripts/websocket_rails/websocket_connection_spec.coffee
200
+ - spec/javascripts/websocket_rails/websocket_rails_spec.coffee
183
201
  - spec/spec_helper.rb
184
202
  - spec/support/helper_methods.rb
185
203
  - spec/support/mock_web_socket.rb
@@ -213,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
231
  version: '0'
214
232
  segments:
215
233
  - 0
216
- hash: -3272086084276613534
234
+ hash: 3412477524173453969
217
235
  required_rubygems_version: !ruby/object:Gem::Requirement
218
236
  none: false
219
237
  requirements:
@@ -222,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
240
  version: '0'
223
241
  segments:
224
242
  - 0
225
- hash: -3272086084276613534
243
+ hash: 3412477524173453969
226
244
  requirements: []
227
245
  rubyforge_project: websocket-rails
228
246
  rubygems_version: 1.8.19