websocket-rails 0.5.0 → 0.6.0
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.
- data/CHANGELOG.md +11 -2
- data/lib/generators/websocket_rails/install/templates/websocket_rails.rb +7 -0
- data/lib/websocket_rails/configuration.rb +8 -0
- data/lib/websocket_rails/connection_adapters.rb +34 -29
- data/lib/websocket_rails/connection_manager.rb +35 -9
- data/lib/websocket_rails/event.rb +6 -2
- data/lib/websocket_rails/synchronization.rb +48 -3
- data/lib/websocket_rails/user_manager.rb +210 -19
- data/lib/websocket_rails/version.rb +1 -1
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/config/environments/test.rb +1 -2
- data/spec/dummy/config/{initializers/events.rb → events.rb} +0 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20130902222552_create_users.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +17 -0
- data/spec/integration/connection_manager_spec.rb +2 -2
- data/spec/unit/connection_adapters_spec.rb +77 -41
- data/spec/unit/connection_manager_spec.rb +45 -9
- data/spec/unit/synchronization_spec.rb +47 -18
- data/spec/unit/user_manager_spec.rb +115 -11
- metadata +12 -7
@@ -3,6 +3,12 @@ require "spec_helper"
|
|
3
3
|
module WebsocketRails
|
4
4
|
|
5
5
|
describe ".users" do
|
6
|
+
before do
|
7
|
+
Synchronization.stub(:find_user)
|
8
|
+
Synchronization.stub(:register_user)
|
9
|
+
Synchronization.stub(:destroy_user)
|
10
|
+
end
|
11
|
+
|
6
12
|
it "returns the global instance of UserManager" do
|
7
13
|
WebsocketRails.users.should be_a UserManager
|
8
14
|
end
|
@@ -12,13 +18,27 @@ module WebsocketRails
|
|
12
18
|
WebsocketRails.stub(:synchronize?).and_return(true)
|
13
19
|
end
|
14
20
|
|
15
|
-
context "and the user is
|
21
|
+
context "and the user is connected to a different worker" do
|
22
|
+
before do
|
23
|
+
user_attr = {name: 'test', email: 'test@test.com'}
|
24
|
+
Synchronization.stub(:find_user).and_return(user_attr)
|
25
|
+
end
|
26
|
+
|
16
27
|
it "publishes the event to redis" do
|
17
28
|
Synchronization.should_receive(:publish) do |event|
|
18
|
-
event.user_id.should ==
|
29
|
+
event.user_id.should == "remote"
|
19
30
|
end
|
20
31
|
|
21
|
-
WebsocketRails.users[
|
32
|
+
WebsocketRails.users["remote"].send_message :test, :data
|
33
|
+
end
|
34
|
+
|
35
|
+
it "instantiates a user object pulled from redis" do
|
36
|
+
remote = WebsocketRails.users["remote"]
|
37
|
+
|
38
|
+
remote.class.should == UserManager::RemoteConnection
|
39
|
+
remote.user.class.should == User
|
40
|
+
remote.user.name.should == 'test'
|
41
|
+
remote.user.persisted?.should == true
|
22
42
|
end
|
23
43
|
end
|
24
44
|
end
|
@@ -26,35 +46,119 @@ module WebsocketRails
|
|
26
46
|
|
27
47
|
describe UserManager do
|
28
48
|
|
29
|
-
|
49
|
+
before do
|
50
|
+
Synchronization.stub(:find_user)
|
51
|
+
Synchronization.stub(:register_user)
|
52
|
+
Synchronization.stub(:destroy_user)
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:connection) do
|
56
|
+
connection = double('Connection')
|
57
|
+
connection.stub(:id).and_return(1)
|
58
|
+
connection.stub(:user_identifier).and_return('Juanita')
|
59
|
+
connection
|
60
|
+
end
|
30
61
|
|
31
62
|
describe "#[]=" do
|
32
63
|
it "store's a reference to a connection in the user's hash" do
|
33
|
-
subject[
|
34
|
-
subject.users[
|
64
|
+
subject["username"] = connection
|
65
|
+
subject.users["username"].connections.first.should == connection
|
35
66
|
end
|
36
67
|
end
|
37
68
|
|
38
69
|
describe "#[]" do
|
39
70
|
before do
|
40
|
-
subject[
|
71
|
+
subject["username"] = connection
|
41
72
|
end
|
42
73
|
|
43
74
|
context "when passed a known user identifier" do
|
44
75
|
it "returns that user's connection" do
|
45
|
-
subject[
|
76
|
+
subject["username"].connections.first.should == connection
|
46
77
|
end
|
47
78
|
end
|
48
79
|
end
|
49
80
|
|
50
81
|
describe "#delete" do
|
51
82
|
before do
|
52
|
-
subject[
|
83
|
+
subject["Juanita"] = connection
|
53
84
|
end
|
54
85
|
|
55
86
|
it "deletes the connection from the users hash" do
|
56
|
-
subject.delete(
|
57
|
-
subject[
|
87
|
+
subject.delete(connection)
|
88
|
+
subject["Juanita"].should be_a UserManager::MissingConnection
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#each" do
|
93
|
+
before do
|
94
|
+
subject['Juanita'] = connection
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when synchronization is disabled" do
|
98
|
+
before do
|
99
|
+
WebsocketRails.stub(:synchronize?).and_return false
|
100
|
+
end
|
101
|
+
|
102
|
+
it "passes each local connection to the given block" do
|
103
|
+
subject.each do |conn|
|
104
|
+
connection.should == conn.connections.first
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when synchronization is enabled" do
|
110
|
+
before do
|
111
|
+
WebsocketRails.stub(:synchronize?).and_return true
|
112
|
+
|
113
|
+
user_attr = {name: 'test', email: 'test@test.com'}.to_json
|
114
|
+
Synchronization.stub(:all_users).and_return 'test' => user_attr
|
115
|
+
end
|
116
|
+
|
117
|
+
it "passes each remote connection to the given block" do
|
118
|
+
subject.each do |conn|
|
119
|
+
conn.class.should == UserManager::RemoteConnection
|
120
|
+
conn.user.class.should == User
|
121
|
+
conn.user.name.should == 'test'
|
122
|
+
conn.user.email.should == 'test@test.com'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "#map" do
|
129
|
+
before do
|
130
|
+
subject['Juanita'] = connection
|
131
|
+
end
|
132
|
+
|
133
|
+
context "when synchronization is disabled" do
|
134
|
+
before do
|
135
|
+
WebsocketRails.stub(:synchronize?).and_return false
|
136
|
+
end
|
137
|
+
|
138
|
+
it "passes each local connection to the given block and collects the results" do
|
139
|
+
results = subject.map do |conn|
|
140
|
+
[conn, true]
|
141
|
+
end
|
142
|
+
results.count.should == 1
|
143
|
+
results[0][0].connections.count.should == 1
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context "when synchronization is enabled" do
|
148
|
+
before do
|
149
|
+
WebsocketRails.stub(:synchronize?).and_return true
|
150
|
+
|
151
|
+
user_attr = {name: 'test', email: 'test@test.com'}.to_json
|
152
|
+
Synchronization.stub(:all_users).and_return 'test' => user_attr
|
153
|
+
end
|
154
|
+
|
155
|
+
it "passes each remote connection to the given block and collects the results" do
|
156
|
+
results = subject.map do |conn|
|
157
|
+
[conn, true]
|
158
|
+
end
|
159
|
+
results.count.should == 1
|
160
|
+
results[0].first.class.should == UserManager::RemoteConnection
|
161
|
+
end
|
58
162
|
end
|
59
163
|
end
|
60
164
|
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.
|
4
|
+
version: 0.6.0
|
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: 2013-09-
|
14
|
+
date: 2013-09-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -223,6 +223,7 @@ files:
|
|
223
223
|
- spec/dummy/app/controllers/application_controller.rb
|
224
224
|
- spec/dummy/app/controllers/chat_controller.rb
|
225
225
|
- spec/dummy/app/helpers/application_helper.rb
|
226
|
+
- spec/dummy/app/models/user.rb
|
226
227
|
- spec/dummy/app/views/layouts/application.html.erb
|
227
228
|
- spec/dummy/config/application.rb
|
228
229
|
- spec/dummy/config/boot.rb
|
@@ -231,8 +232,8 @@ files:
|
|
231
232
|
- spec/dummy/config/environments/development.rb
|
232
233
|
- spec/dummy/config/environments/production.rb
|
233
234
|
- spec/dummy/config/environments/test.rb
|
235
|
+
- spec/dummy/config/events.rb
|
234
236
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
235
|
-
- spec/dummy/config/initializers/events.rb
|
236
237
|
- spec/dummy/config/initializers/inflections.rb
|
237
238
|
- spec/dummy/config/initializers/mime_types.rb
|
238
239
|
- spec/dummy/config/initializers/secret_token.rb
|
@@ -240,6 +241,9 @@ files:
|
|
240
241
|
- spec/dummy/config/locales/en.yml
|
241
242
|
- spec/dummy/config/routes.rb
|
242
243
|
- spec/dummy/config.ru
|
244
|
+
- spec/dummy/db/development.sqlite3
|
245
|
+
- spec/dummy/db/migrate/20130902222552_create_users.rb
|
246
|
+
- spec/dummy/db/schema.rb
|
243
247
|
- spec/dummy/db/test.sqlite3
|
244
248
|
- spec/dummy/log/development.log
|
245
249
|
- spec/dummy/log/production.log
|
@@ -303,8 +307,9 @@ files:
|
|
303
307
|
- README.md
|
304
308
|
- CHANGELOG.md
|
305
309
|
homepage: http://danknox.github.com/websocket-rails/
|
306
|
-
licenses:
|
307
|
-
|
310
|
+
licenses:
|
311
|
+
- MIT
|
312
|
+
post_install_message: Welcome to WebsocketRails v0.6.0!
|
308
313
|
rdoc_options: []
|
309
314
|
require_paths:
|
310
315
|
- lib
|
@@ -316,7 +321,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
316
321
|
version: '0'
|
317
322
|
segments:
|
318
323
|
- 0
|
319
|
-
hash: -
|
324
|
+
hash: -1613820515143330234
|
320
325
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
321
326
|
none: false
|
322
327
|
requirements:
|
@@ -325,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
330
|
version: '0'
|
326
331
|
segments:
|
327
332
|
- 0
|
328
|
-
hash: -
|
333
|
+
hash: -1613820515143330234
|
329
334
|
requirements: []
|
330
335
|
rubyforge_project: websocket-rails
|
331
336
|
rubygems_version: 1.8.25
|