websocket-rails 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +4 -0
- data/lib/websocket_rails/events.rb +1 -1
- data/lib/websocket_rails/version.rb +1 -1
- data/spec/integration/connection_manager_spec.rb +38 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/connection_manager_spec.rb +15 -15
- data/websocket-rails.gemspec +1 -1
- metadata +6 -5
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/DanKnox/websocket-rails.png)](https://secure.travis-ci.org/DanKnox/websocket-rails)
|
4
4
|
|
5
|
+
If you haven't done so yet, check out the [Project Page](http://danknox.github.com/websocket-rails/) to get a feel for the project direction. Feedback is very much appreciated. Post an issue on the issue tracker or [shoot us an email](mailto://support@threedotloft.com) to give us your thoughts.
|
6
|
+
|
7
|
+
## Overview
|
8
|
+
|
5
9
|
Plug and play WebSocket support for ruby on rails. Includes event router for mapping javascript events to controller actions. There is no need for a separate WebSocket server process. Requests to `/websocket` will be passed through to the `ConnectionManager` class which is a simple Rack based WebSocket server developed using the `Faye::WebSocket` library.
|
6
10
|
|
7
11
|
*Important Note*
|
@@ -3,7 +3,7 @@ module WebsocketRails
|
|
3
3
|
# number of controllers and actions. You can define your event routes by creating an +events.rb+ file in
|
4
4
|
# your application's +initializers+ directory. The DSL currently consists of a single method, {#subscribe},
|
5
5
|
# which takes a symbolized event name as the first argument, and a Hash with the controller and method
|
6
|
-
# name as the second
|
6
|
+
# name as the second argument.
|
7
7
|
#
|
8
8
|
# == Example events.rb file
|
9
9
|
# # located in config/initializers/events.rb
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module WebsocketRails
|
4
|
+
describe ConnectionManager do
|
5
|
+
|
6
|
+
def define_test_events
|
7
|
+
WebsocketRails.route_block = nil
|
8
|
+
WebsocketRails::Events.describe_events do
|
9
|
+
subscribe :client_connected, to: ChatController, with_method: :new_user
|
10
|
+
subscribe :change_username, to: ChatController, with_method: :change_username
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before(:all) { define_test_events }
|
15
|
+
|
16
|
+
let(:env) { Hash.new }
|
17
|
+
let(:socket) { MockWebSocket.new }
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
Faye::WebSocket.stub(:new).and_return(MockWebSocket.new)
|
21
|
+
@server = ConnectionManager.new
|
22
|
+
end
|
23
|
+
|
24
|
+
context "new connections" do
|
25
|
+
it "should execute the controller action associated with the 'client_connected' event" do
|
26
|
+
ChatController.any_instance.should_receive(:new_user)
|
27
|
+
define_test_events
|
28
|
+
@server.call( env )
|
29
|
+
#ChatController.new.send(:new_user)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have a ChatController present" do
|
33
|
+
ChatController.new.should be_present
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -40,21 +40,7 @@ module WebsocketRails
|
|
40
40
|
it "should return an Async Rack response" do
|
41
41
|
open_connection.should == [ -1, {}, [] ]
|
42
42
|
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "new event on an open connection" do
|
46
|
-
before(:all) { MockEvent = Struct.new(:data) }
|
47
|
-
before(:each) { open_connection }
|
48
|
-
|
49
|
-
it "should dispatch the appropriate event through the Dispatcher" do
|
50
|
-
mock_event = MockEvent.new(:new_message)
|
51
|
-
@dispatcher.should_receive(:receive) do |event,connection|
|
52
|
-
event.should == :new_message
|
53
|
-
connection.should == @mock_socket
|
54
|
-
end
|
55
|
-
@mock_socket.onmessage(mock_event)
|
56
|
-
end
|
57
|
-
end
|
43
|
+
end
|
58
44
|
|
59
45
|
context "open connections" do
|
60
46
|
before(:each) do
|
@@ -62,6 +48,20 @@ module WebsocketRails
|
|
62
48
|
4.times { open_connection }
|
63
49
|
end
|
64
50
|
|
51
|
+
context "when receiving a new event" do
|
52
|
+
before(:all) { MockEvent = Struct.new(:data) }
|
53
|
+
before(:each) { open_connection }
|
54
|
+
|
55
|
+
it "should dispatch the appropriate event through the Dispatcher" do
|
56
|
+
mock_event = MockEvent.new(:new_message)
|
57
|
+
@dispatcher.should_receive(:receive) do |event,connection|
|
58
|
+
event.should == :new_message
|
59
|
+
connection.should == @mock_socket
|
60
|
+
end
|
61
|
+
@mock_socket.onmessage(mock_event)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
65
|
context "when closing" do
|
66
66
|
it "should remove the connection object from the @connections array" do
|
67
67
|
@mock_socket.onclose
|
data/websocket-rails.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = "websocket-rails"
|
6
6
|
s.summary = "Plug and play websocket support for ruby on rails. Includes event router for mapping javascript events to controller actions."
|
7
7
|
s.description = "Seamless Ruby on Rails websocket integration."
|
8
|
-
s.homepage = "
|
8
|
+
s.homepage = "http://danknox.github.com/websocket-rails/"
|
9
9
|
s.files = Dir["{lib,config}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.rdoc"]
|
10
10
|
s.version = WebsocketRails::VERSION
|
11
11
|
s.platform = Gem::Platform::RUBY
|
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.
|
4
|
+
version: 0.1.1
|
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-
|
14
|
+
date: 2012-06-02 00:00:00.000000000Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rack
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- spec/dummy/public/javascripts/rails.js
|
190
190
|
- spec/dummy/public/stylesheets/.gitkeep
|
191
191
|
- spec/dummy/script/rails
|
192
|
+
- spec/integration/connection_manager_spec.rb
|
192
193
|
- spec/spec_helper.rb
|
193
194
|
- spec/support/mock_web_socket.rb
|
194
195
|
- spec/unit/connection_manager_spec.rb
|
@@ -196,7 +197,7 @@ files:
|
|
196
197
|
- spec/unit/dispatcher_spec.rb
|
197
198
|
- spec/unit/events_spec.rb
|
198
199
|
- websocket-rails.gemspec
|
199
|
-
homepage:
|
200
|
+
homepage: http://danknox.github.com/websocket-rails/
|
200
201
|
licenses: []
|
201
202
|
post_install_message:
|
202
203
|
rdoc_options: []
|
@@ -210,7 +211,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
210
211
|
version: '0'
|
211
212
|
segments:
|
212
213
|
- 0
|
213
|
-
hash: -
|
214
|
+
hash: -481953751813438507
|
214
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
215
216
|
none: false
|
216
217
|
requirements:
|
@@ -219,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
220
|
version: '0'
|
220
221
|
segments:
|
221
222
|
- 0
|
222
|
-
hash: -
|
223
|
+
hash: -481953751813438507
|
223
224
|
requirements: []
|
224
225
|
rubyforge_project:
|
225
226
|
rubygems_version: 1.8.19
|