websocket-rails 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/CHANGELOG.md +34 -0
  2. data/Gemfile +1 -0
  3. data/README.md +34 -34
  4. data/assets/javascripts/http_dispatcher.js +6 -5
  5. data/assets/javascripts/websocket_dispatcher.js +7 -6
  6. data/lib/websocket-rails.rb +22 -2
  7. data/lib/websocket_rails/base_controller.rb +24 -8
  8. data/lib/websocket_rails/connection_adapters.rb +43 -16
  9. data/lib/websocket_rails/connection_adapters/http.rb +14 -10
  10. data/lib/websocket_rails/connection_adapters/web_socket.rb +13 -12
  11. data/lib/websocket_rails/connection_manager.rb +19 -47
  12. data/lib/websocket_rails/dispatcher.rb +39 -33
  13. data/lib/websocket_rails/event.rb +71 -0
  14. data/lib/websocket_rails/event_map.rb +120 -0
  15. data/lib/websocket_rails/version.rb +1 -1
  16. data/spec/dummy/config/initializers/events.rb +2 -2
  17. data/spec/dummy/{public/stylesheets/.gitkeep → log/development.log} +0 -0
  18. data/spec/dummy/log/production.log +0 -0
  19. data/spec/dummy/log/server.log +0 -0
  20. data/spec/dummy/log/test.log +454 -0
  21. data/spec/integration/connection_manager_spec.rb +29 -13
  22. data/spec/spec_helper.rb +3 -3
  23. data/spec/support/helper_methods.rb +29 -0
  24. data/spec/support/mock_web_socket.rb +6 -2
  25. data/spec/unit/connection_adapters/http_spec.rb +1 -3
  26. data/spec/unit/connection_adapters/web_socket_spec.rb +1 -11
  27. data/spec/unit/connection_adapters_spec.rb +51 -19
  28. data/spec/unit/connection_manager_spec.rb +22 -46
  29. data/spec/unit/dispatcher_spec.rb +56 -25
  30. data/spec/unit/event_map_spec.rb +96 -0
  31. data/spec/unit/event_spec.rb +99 -0
  32. metadata +23 -25
  33. data/.gitignore +0 -11
  34. data/.rspec +0 -2
  35. data/.travis.yml +0 -3
  36. data/Gemfile.lock +0 -144
  37. data/Guardfile +0 -9
  38. data/lib/websocket_rails/events.rb +0 -53
  39. data/spec/unit/events_spec.rb +0 -70
  40. data/websocket-rails.gemspec +0 -26
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ module WebsocketRails
4
+ describe EventMap do
5
+
6
+ class ProductController < WebsocketRails::BaseController
7
+ def update_product
8
+ true
9
+ end
10
+ end
11
+
12
+ def define_test_events
13
+ WebsocketRails.route_block = nil
14
+ WebsocketRails::EventMap.describe do
15
+ subscribe :client_connected, to: ChatController, with_method: :new_user
16
+
17
+ namespace :product do
18
+ subscribe :update, to: ProductController, with_method: :update_product
19
+ end
20
+ end
21
+ end
22
+
23
+ let(:dispatcher) { double('dispatcher').as_null_object }
24
+ subject { EventMap.new(dispatcher) }
25
+ before { define_test_events }
26
+
27
+ context "EventMap.describe" do
28
+ it "should store the event route block in the global configuration" do
29
+ WebsocketRails.route_block.should be_present
30
+ end
31
+ end
32
+
33
+ context "Events in the global namespace" do
34
+
35
+ it "should store the event in the correct namespace" do
36
+ subject.namespace.actions[:client_connected].should be_present
37
+ subject.namespace.name.should == :global
38
+ end
39
+
40
+ it "should store the instantiated controller in the classes hash" do
41
+ subject.namespace.controllers[ChatController].class.should == ChatController
42
+ end
43
+
44
+ it "should set the dispatcher on the instantiated controller" do
45
+ subject.namespace.controllers[ChatController].instance_variable_get(:@_dispatcher).should == dispatcher
46
+ end
47
+
48
+ it "should store the class constant and method name in the events hash" do
49
+ subject.namespace.actions[:client_connected].should == [[ChatController,:new_user]]
50
+ end
51
+
52
+ end
53
+
54
+ context "Events in a child namespace" do
55
+
56
+ before { @namespace = subject.namespace }
57
+
58
+ it "should store the event in the correct namespace" do
59
+ @namespace.namespaces[:product].actions[:update].should be_present
60
+ end
61
+
62
+ end
63
+
64
+ context "#routes_for" do
65
+
66
+ let(:event) { double('event') }
67
+
68
+ context "with events in the global namespace" do
69
+ it "should yield the controller and action name for each route defined for an event" do
70
+ event.stub(:name).and_return(:client_connected)
71
+ event.stub(:namespace).and_return([:global])
72
+
73
+ subject.routes_for(event) do |controller,method|
74
+ controller.class.should == ChatController
75
+ method.should == :new_user
76
+ end
77
+ end
78
+ end
79
+
80
+ context "with events in a child namespace" do
81
+ it "should yield the controller and action name for each route defined for an event" do
82
+ ProductController.any_instance.should_receive(:action_executed)
83
+ event = HelperMethods::MockEvent.new :update, [:global,:product]
84
+
85
+ subject.routes_for(event) do |controller,method|
86
+ controller.action_executed
87
+ controller.class.should == ProductController
88
+ method.should == :update_product
89
+ end
90
+ end
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ module WebsocketRails
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(:connection) { double('connection') }
10
+
11
+ before { connection.stub!(:id).and_return(1) }
12
+
13
+ describe ".new_from_json" do
14
+ context "messages in the global namespace" do
15
+ it "should decode a new message and store it" do
16
+ event = Event.new_from_json( encoded_message, connection )
17
+ event.connection.should == connection
18
+ event.name.should == :new_message
19
+ event.namespace.should == [:global]
20
+ event.data[:message].should == 'this is a message'
21
+ end
22
+ end
23
+
24
+ context "messages in a child namespace" do
25
+ it "should store the event with the correct namesapce" do
26
+ event = Event.new_from_json( namespace_encoded_message, connection )
27
+ event.namespace.should == [:global,:product]
28
+ event.name.should == :new_message
29
+ event.data[:message].should == 'this is a message'
30
+ end
31
+ end
32
+ end
33
+
34
+ describe ".new_on_open" do
35
+ before { @event = Event.new_on_open connection, {message: 'connected'} }
36
+
37
+ it "should create an event named :client_connected" do
38
+ @event.name.should == :client_connected
39
+ end
40
+
41
+ it "should send the connection id to the client" do
42
+ @event.data[:connection_id].should == 1
43
+ end
44
+
45
+ it "should merge the optional data with the connection id" do
46
+ @event.data[:message].should == 'connected'
47
+ end
48
+ end
49
+
50
+ describe ".new_on_close" do
51
+ it "should create an event named :client_disconnected" do
52
+ event = Event.new_on_close( connection, "optional_data" )
53
+ event.name.should == :client_disconnected
54
+ event.data.should == "optional_data"
55
+ event.connection.should == connection
56
+ end
57
+ end
58
+
59
+ describe ".new_on_error" do
60
+ it "should create an event named :client_error" do
61
+ event = Event.new_on_error( connection, "optional_data" )
62
+ event.name.should == :client_error
63
+ event.data.should == "optional_data"
64
+ event.connection.should == connection
65
+ end
66
+ end
67
+
68
+ context "new namespaced events" do
69
+ it "should store the namespace in the namespace attribute" do
70
+ event = Event.new "event", {}, connection, :namespace => :product
71
+ event.namespace.should == [:global,:product]
72
+ event.name.should == :event
73
+ end
74
+
75
+ it "should store nested namespaces in the namespace attribute" do
76
+ event = Event.new "event", {}, connection, :namespace => [:product,:x_ray_vision]
77
+ event.namespace.should == [:global,:product,:x_ray_vision]
78
+ event.name.should == :event
79
+ end
80
+ end
81
+
82
+ describe "#serialize" do
83
+ context "messages in the global namespace" do
84
+ it "should not add the global namespace to the event name" do
85
+ event = Event.new_from_json encoded_message_string, connection
86
+ event.serialize.should == encoded_message_string
87
+ end
88
+ end
89
+
90
+ context "messages in a child namespace" do
91
+ it "should add the namespace to the front of the event name" do
92
+ event = Event.new_from_json namespace_encoded_message_string, connection
93
+ event.serialize.should == namespace_encoded_message_string
94
+ end
95
+ end
96
+ end
97
+
98
+ end
99
+ end
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.2
4
+ version: 0.1.3
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-06-10 00:00:00.000000000Z
14
+ date: 2012-06-22 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rack
@@ -133,36 +133,26 @@ executables:
133
133
  extensions: []
134
134
  extra_rdoc_files: []
135
135
  files:
136
- - .gitignore
137
- - .rspec
138
- - .travis.yml
139
- - Gemfile
140
- - Gemfile.lock
141
- - Guardfile
142
- - MIT-LICENSE
143
- - README.md
144
- - Rakefile
145
- - assets/javascripts/http_dispatcher.js
146
- - assets/javascripts/websocket_dispatcher.js
147
- - bin/thin-socketrails
148
- - config/routes.rb
149
136
  - lib/websocket-rails.rb
150
137
  - lib/websocket_rails/base_controller.rb
151
- - lib/websocket_rails/connection_adapters.rb
152
138
  - lib/websocket_rails/connection_adapters/http.rb
153
139
  - lib/websocket_rails/connection_adapters/web_socket.rb
140
+ - lib/websocket_rails/connection_adapters.rb
154
141
  - lib/websocket_rails/connection_manager.rb
155
142
  - lib/websocket_rails/data_store.rb
156
143
  - lib/websocket_rails/dispatcher.rb
157
144
  - lib/websocket_rails/engine.rb
158
- - lib/websocket_rails/events.rb
145
+ - lib/websocket_rails/event.rb
146
+ - lib/websocket_rails/event_map.rb
159
147
  - lib/websocket_rails/version.rb
160
- - spec/dummy/Rakefile
148
+ - config/routes.rb
149
+ - bin/thin-socketrails
150
+ - assets/javascripts/http_dispatcher.js
151
+ - assets/javascripts/websocket_dispatcher.js
161
152
  - spec/dummy/app/controllers/application_controller.rb
162
153
  - spec/dummy/app/controllers/chat_controller.rb
163
154
  - spec/dummy/app/helpers/application_helper.rb
164
155
  - spec/dummy/app/views/layouts/application.html.erb
165
- - spec/dummy/config.ru
166
156
  - spec/dummy/config/application.rb
167
157
  - spec/dummy/config/boot.rb
168
158
  - spec/dummy/config/database.yml
@@ -178,10 +168,12 @@ files:
178
168
  - spec/dummy/config/initializers/session_store.rb
179
169
  - spec/dummy/config/locales/en.yml
180
170
  - spec/dummy/config/routes.rb
171
+ - spec/dummy/config.ru
181
172
  - spec/dummy/db/test.sqlite3
182
173
  - spec/dummy/log/development.log
183
174
  - spec/dummy/log/production.log
184
175
  - spec/dummy/log/server.log
176
+ - spec/dummy/log/test.log
185
177
  - spec/dummy/public/404.html
186
178
  - spec/dummy/public/422.html
187
179
  - spec/dummy/public/500.html
@@ -192,10 +184,11 @@ files:
192
184
  - spec/dummy/public/javascripts/effects.js
193
185
  - spec/dummy/public/javascripts/prototype.js
194
186
  - spec/dummy/public/javascripts/rails.js
195
- - spec/dummy/public/stylesheets/.gitkeep
187
+ - spec/dummy/Rakefile
196
188
  - spec/dummy/script/rails
197
189
  - spec/integration/connection_manager_spec.rb
198
190
  - spec/spec_helper.rb
191
+ - spec/support/helper_methods.rb
199
192
  - spec/support/mock_web_socket.rb
200
193
  - spec/unit/connection_adapters/http_spec.rb
201
194
  - spec/unit/connection_adapters/web_socket_spec.rb
@@ -203,8 +196,13 @@ files:
203
196
  - spec/unit/connection_manager_spec.rb
204
197
  - spec/unit/data_store_spec.rb
205
198
  - spec/unit/dispatcher_spec.rb
206
- - spec/unit/events_spec.rb
207
- - websocket-rails.gemspec
199
+ - spec/unit/event_map_spec.rb
200
+ - spec/unit/event_spec.rb
201
+ - MIT-LICENSE
202
+ - Rakefile
203
+ - Gemfile
204
+ - README.md
205
+ - CHANGELOG.md
208
206
  homepage: http://danknox.github.com/websocket-rails/
209
207
  licenses: []
210
208
  post_install_message:
@@ -219,7 +217,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
217
  version: '0'
220
218
  segments:
221
219
  - 0
222
- hash: 2040378908172396900
220
+ hash: 1310952573146011562
223
221
  required_rubygems_version: !ruby/object:Gem::Requirement
224
222
  none: false
225
223
  requirements:
@@ -228,9 +226,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
226
  version: '0'
229
227
  segments:
230
228
  - 0
231
- hash: 2040378908172396900
229
+ hash: 1310952573146011562
232
230
  requirements: []
233
- rubyforge_project:
231
+ rubyforge_project: websocket-rails
234
232
  rubygems_version: 1.8.19
235
233
  signing_key:
236
234
  specification_version: 3
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- .yardoc/
2
- coverage/
3
- .DS_Store
4
- .bundle/
5
- log/*.log
6
- *.log
7
- pkg/
8
- doc/
9
- test/dummy/db/*.sqlite3
10
- test/dummy/log/*.log
11
- test/dummy/tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format documentation
data/.travis.yml DELETED
@@ -1,3 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
data/Gemfile.lock DELETED
@@ -1,144 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- websocket-rails (0.1.2)
5
- faye-websocket
6
- rack
7
- thin
8
-
9
- GEM
10
- remote: http://rubygems.org/
11
- specs:
12
- actionmailer (3.2.5)
13
- actionpack (= 3.2.5)
14
- mail (~> 2.4.4)
15
- actionpack (3.2.5)
16
- activemodel (= 3.2.5)
17
- activesupport (= 3.2.5)
18
- builder (~> 3.0.0)
19
- erubis (~> 2.7.0)
20
- journey (~> 1.0.1)
21
- rack (~> 1.4.0)
22
- rack-cache (~> 1.2)
23
- rack-test (~> 0.6.1)
24
- sprockets (~> 2.1.3)
25
- activemodel (3.2.5)
26
- activesupport (= 3.2.5)
27
- builder (~> 3.0.0)
28
- activerecord (3.2.5)
29
- activemodel (= 3.2.5)
30
- activesupport (= 3.2.5)
31
- arel (~> 3.0.2)
32
- tzinfo (~> 0.3.29)
33
- activeresource (3.2.5)
34
- activemodel (= 3.2.5)
35
- activesupport (= 3.2.5)
36
- activesupport (3.2.5)
37
- i18n (~> 0.6)
38
- multi_json (~> 1.0)
39
- arel (3.0.2)
40
- builder (3.0.0)
41
- daemons (1.1.8)
42
- diff-lcs (1.1.3)
43
- erubis (2.7.0)
44
- eventmachine (1.0.0.beta.4)
45
- faye-websocket (0.4.5)
46
- eventmachine (>= 0.12.0)
47
- ffi (1.0.11)
48
- guard (1.1.1)
49
- listen (>= 0.4.2)
50
- thor (>= 0.14.6)
51
- guard-rspec (1.0.0)
52
- guard (>= 1.1)
53
- hike (1.2.1)
54
- i18n (0.6.0)
55
- journey (1.0.3)
56
- json (1.7.3)
57
- listen (0.4.3)
58
- rb-fchange (~> 0.0.5)
59
- rb-fsevent (~> 0.9.1)
60
- rb-inotify (~> 0.8.8)
61
- mail (2.4.4)
62
- i18n (>= 0.4.0)
63
- mime-types (~> 1.16)
64
- treetop (~> 1.4.8)
65
- mime-types (1.18)
66
- multi_json (1.3.6)
67
- polyglot (0.3.3)
68
- rack (1.4.1)
69
- rack-cache (1.2)
70
- rack (>= 0.4)
71
- rack-ssl (1.3.2)
72
- rack
73
- rack-test (0.6.1)
74
- rack (>= 1.0)
75
- rails (3.2.5)
76
- actionmailer (= 3.2.5)
77
- actionpack (= 3.2.5)
78
- activerecord (= 3.2.5)
79
- activeresource (= 3.2.5)
80
- activesupport (= 3.2.5)
81
- bundler (~> 1.0)
82
- railties (= 3.2.5)
83
- railties (3.2.5)
84
- actionpack (= 3.2.5)
85
- activesupport (= 3.2.5)
86
- rack-ssl (~> 1.3.2)
87
- rake (>= 0.8.7)
88
- rdoc (~> 3.4)
89
- thor (>= 0.14.6, < 2.0)
90
- rake (0.9.2.2)
91
- rb-fchange (0.0.5)
92
- ffi
93
- rb-fsevent (0.9.1)
94
- rb-inotify (0.8.8)
95
- ffi (>= 0.5.0)
96
- rdoc (3.12)
97
- json (~> 1.4)
98
- rspec (2.10.0)
99
- rspec-core (~> 2.10.0)
100
- rspec-expectations (~> 2.10.0)
101
- rspec-mocks (~> 2.10.0)
102
- rspec-core (2.10.1)
103
- rspec-expectations (2.10.0)
104
- diff-lcs (~> 1.1.3)
105
- rspec-mocks (2.10.1)
106
- rspec-rails (2.10.1)
107
- actionpack (>= 3.0)
108
- activesupport (>= 3.0)
109
- railties (>= 3.0)
110
- rspec (~> 2.10.0)
111
- simplecov (0.6.4)
112
- multi_json (~> 1.0)
113
- simplecov-html (~> 0.5.3)
114
- simplecov-html (0.5.3)
115
- sprockets (2.1.3)
116
- hike (~> 1.2)
117
- rack (~> 1.0)
118
- tilt (~> 1.1, != 1.3.0)
119
- sqlite3 (1.3.6)
120
- thin (1.3.1)
121
- daemons (>= 1.0.9)
122
- eventmachine (>= 0.12.6)
123
- rack (>= 1.0.0)
124
- thor (0.15.2)
125
- tilt (1.3.3)
126
- treetop (1.4.10)
127
- polyglot
128
- polyglot (>= 0.3.1)
129
- tzinfo (0.3.33)
130
-
131
- PLATFORMS
132
- ruby
133
-
134
- DEPENDENCIES
135
- eventmachine (>= 1.0.0.beta.3)
136
- faye-websocket
137
- guard
138
- guard-rspec
139
- rails
140
- rake
141
- rspec-rails
142
- simplecov
143
- sqlite3
144
- websocket-rails!