faye 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of faye might be problematic. Click here for more details.

Files changed (62) hide show
  1. data/History.txt +14 -0
  2. data/README.rdoc +98 -0
  3. data/Rakefile +17 -15
  4. data/lib/faye-browser-min.js +1 -1
  5. data/lib/faye.rb +14 -5
  6. data/lib/faye/adapters/rack_adapter.rb +12 -5
  7. data/lib/faye/engines/base.rb +62 -0
  8. data/lib/faye/engines/connection.rb +63 -0
  9. data/lib/faye/engines/memory.rb +89 -0
  10. data/lib/faye/engines/redis.rb +141 -0
  11. data/lib/faye/error.rb +16 -4
  12. data/lib/faye/mixins/publisher.rb +6 -0
  13. data/lib/faye/protocol/channel.rb +34 -86
  14. data/lib/faye/protocol/client.rb +36 -52
  15. data/lib/faye/protocol/extensible.rb +3 -0
  16. data/lib/faye/protocol/server.rb +119 -169
  17. data/lib/faye/transport/http.rb +45 -0
  18. data/lib/faye/transport/local.rb +15 -0
  19. data/lib/faye/{network → transport}/transport.rb +36 -49
  20. data/spec/browser.html +35 -0
  21. data/spec/install.sh +48 -0
  22. data/spec/javascript/channel_spec.js +15 -0
  23. data/spec/javascript/client_spec.js +610 -0
  24. data/spec/javascript/engine_spec.js +319 -0
  25. data/spec/javascript/faye_spec.js +15 -0
  26. data/spec/javascript/grammar_spec.js +66 -0
  27. data/spec/javascript/node_adapter_spec.js +276 -0
  28. data/spec/javascript/server/connect_spec.js +168 -0
  29. data/spec/javascript/server/disconnect_spec.js +121 -0
  30. data/spec/javascript/server/extensions_spec.js +60 -0
  31. data/spec/javascript/server/handshake_spec.js +153 -0
  32. data/spec/javascript/server/subscribe_spec.js +245 -0
  33. data/spec/javascript/server/unsubscribe_spec.js +245 -0
  34. data/spec/javascript/server_spec.js +146 -0
  35. data/spec/javascript/transport_spec.js +130 -0
  36. data/spec/node.js +34 -0
  37. data/spec/ruby/channel_spec.rb +17 -0
  38. data/spec/ruby/client_spec.rb +615 -0
  39. data/spec/ruby/engine_spec.rb +312 -0
  40. data/spec/ruby/faye_spec.rb +14 -0
  41. data/spec/ruby/grammar_spec.rb +68 -0
  42. data/spec/ruby/rack_adapter_spec.rb +209 -0
  43. data/spec/ruby/server/connect_spec.rb +170 -0
  44. data/spec/ruby/server/disconnect_spec.rb +120 -0
  45. data/spec/ruby/server/extensions_spec.rb +69 -0
  46. data/spec/ruby/server/handshake_spec.rb +151 -0
  47. data/spec/ruby/server/subscribe_spec.rb +247 -0
  48. data/spec/ruby/server/unsubscribe_spec.rb +247 -0
  49. data/spec/ruby/server_spec.rb +138 -0
  50. data/spec/ruby/transport_spec.rb +128 -0
  51. data/spec/spec_helper.rb +5 -0
  52. data/spec/testswarm.pl +200 -0
  53. data/spec/thin_proxy.rb +36 -0
  54. metadata +119 -84
  55. data/Manifest.txt +0 -27
  56. data/README.txt +0 -98
  57. data/lib/faye/protocol/connection.rb +0 -111
  58. data/test/scenario.rb +0 -172
  59. data/test/test_channel.rb +0 -54
  60. data/test/test_clients.rb +0 -381
  61. data/test/test_grammar.rb +0 -86
  62. data/test/test_server.rb +0 -488
@@ -0,0 +1,245 @@
1
+ JS.ENV.Server.SubscribeSpec = JS.Test.describe("Server subscribe", function() { with(this) {
2
+ before(function() { with(this) {
3
+ this.engine = {}
4
+ stub(Faye.Engine, "get").returns(engine)
5
+ this.server = new Faye.Server()
6
+ }})
7
+
8
+ describe("#subscribe", function() { with(this) {
9
+ before(function() { with(this) {
10
+ this.clientId = "fakeclientid"
11
+ this.message = {channel: "/meta/subscribe",
12
+ clientId: "fakeclientid",
13
+ subscription: "/foo"}
14
+ }})
15
+
16
+ describe("with valid parameters", function() { with(this) {
17
+ before(function() { with(this) {
18
+ expect(engine, "clientExists").given(clientId).yielding([true])
19
+ }})
20
+
21
+ it("subscribes the client to the channel", function() { with(this) {
22
+ expect(engine, "subscribe").given(clientId, "/foo")
23
+ server.subscribe(message, false, function() {})
24
+ }})
25
+
26
+ it("returns a successful response", function() { with(this) {
27
+ stub(engine, "subscribe")
28
+ server.subscribe(message, false, function(response) {
29
+ assertEqual({
30
+ channel: "/meta/subscribe",
31
+ successful: true,
32
+ clientId: clientId,
33
+ subscription: "/foo"
34
+ }, response)
35
+ })
36
+ }})
37
+
38
+ describe("with a list of subscriptions", function() { with(this) {
39
+ before(function() { with(this) {
40
+ message.subscription = ["/foo", "/bar"]
41
+ }})
42
+
43
+ it("creates multiple subscriptions", function() { with(this) {
44
+ expect(engine, "subscribe").given(clientId, "/foo")
45
+ expect(engine, "subscribe").given(clientId, "/bar")
46
+ server.subscribe(message, false, function() {})
47
+ }})
48
+
49
+ it("returns a successful response", function() { with(this) {
50
+ stub(engine, "subscribe")
51
+ server.subscribe(message, false, function(response) {
52
+ assertEqual({
53
+ channel: "/meta/subscribe",
54
+ successful: true,
55
+ clientId: clientId,
56
+ subscription: ["/foo", "/bar"]
57
+ }, response)
58
+ })
59
+ }})
60
+ }})
61
+
62
+ describe("with a subscription pattern", function() { with(this) {
63
+ before(function() { with(this) {
64
+ message.subscription = "/foo/**"
65
+ }})
66
+
67
+ it("subscribes the client to the channel pattern", function() { with(this) {
68
+ expect(engine, "subscribe").given(clientId, "/foo/**")
69
+ server.subscribe(message, false, function() {})
70
+ }})
71
+
72
+ it("returns a successful response", function() { with(this) {
73
+ stub(engine, "subscribe")
74
+ server.subscribe(message, false, function(response) {
75
+ assertEqual({
76
+ channel: "/meta/subscribe",
77
+ successful: true,
78
+ clientId: clientId,
79
+ subscription: "/foo/**"
80
+ }, response)
81
+ })
82
+ }})
83
+ }})
84
+ }})
85
+
86
+ describe("with an unknown client", function() { with(this) {
87
+ before(function() { with(this) {
88
+ expect(engine, "clientExists").given(clientId).yielding([false])
89
+ }})
90
+
91
+ it("does not subscribe the client to the channel", function() { with(this) {
92
+ expect(engine, "subscribe").exactly(0)
93
+ server.subscribe(message, false, function() {})
94
+ }})
95
+
96
+ it("returns an unsuccessful response", function() { with(this) {
97
+ server.subscribe(message, false, function(response) {
98
+ assertEqual({
99
+ channel: "/meta/subscribe",
100
+ successful: false,
101
+ error: "401:fakeclientid:Unknown client",
102
+ clientId: clientId,
103
+ subscription: "/foo"
104
+ }, response)
105
+ })
106
+ }})
107
+ }})
108
+
109
+ describe("missing clientId", function() { with(this) {
110
+ before(function() { with(this) {
111
+ delete message.clientId
112
+ expect(engine, "clientExists").given(undefined).yielding([false])
113
+ }})
114
+
115
+ it("does not subscribe the client to the channel", function() { with(this) {
116
+ expect(engine, "subscribe").exactly(0)
117
+ server.subscribe(message, false, function() {})
118
+ }})
119
+
120
+ it("returns an unsuccessful response", function() { with(this) {
121
+ server.subscribe(message, false, function(response) {
122
+ assertEqual({
123
+ channel: "/meta/subscribe",
124
+ successful: false,
125
+ error: "402:clientId:Missing required parameter",
126
+ subscription: "/foo"
127
+ }, response)
128
+ })
129
+ }})
130
+ }})
131
+
132
+ describe("missing subscription", function() { with(this) {
133
+ before(function() { with(this) {
134
+ delete message.subscription
135
+ expect(engine, "clientExists").given(clientId).yielding([true])
136
+ }})
137
+
138
+ it("does not subscribe the client to the channel", function() { with(this) {
139
+ expect(engine, "subscribe").exactly(0)
140
+ server.subscribe(message, false, function() {})
141
+ }})
142
+
143
+ it("returns an unsuccessful response", function() { with(this) {
144
+ server.subscribe(message, false, function(response) {
145
+ assertEqual({
146
+ channel: "/meta/subscribe",
147
+ successful: false,
148
+ error: "402:subscription:Missing required parameter",
149
+ clientId: clientId,
150
+ subscription: []
151
+ }, response)
152
+ })
153
+ }})
154
+ }})
155
+
156
+ describe("with an invalid channel", function() { with(this) {
157
+ before(function() { with(this) {
158
+ message.subscription = "foo"
159
+ expect(engine, "clientExists").given(clientId).yielding([true])
160
+ }})
161
+
162
+ it("does not subscribe the client to the channel", function() { with(this) {
163
+ expect(engine, "subscribe").exactly(0)
164
+ server.subscribe(message, false, function() {})
165
+ }})
166
+
167
+ it("returns an unsuccessful response", function() { with(this) {
168
+ server.subscribe(message, false, function(response) {
169
+ assertEqual({
170
+ channel: "/meta/subscribe",
171
+ successful: false,
172
+ error: "405:foo:Invalid channel",
173
+ clientId: clientId,
174
+ subscription: "foo"
175
+ }, response)
176
+ })
177
+ }})
178
+ }})
179
+
180
+ describe("with a /meta/* channel", function() { with(this) {
181
+ before(function() { with(this) {
182
+ message.subscription = "/meta/foo"
183
+ expect(engine, "clientExists").given(clientId).yielding([true])
184
+ }})
185
+
186
+ it("does not subscribe the client to the channel", function() { with(this) {
187
+ expect(engine, "subscribe").exactly(0)
188
+ server.subscribe(message, false, function() {})
189
+ }})
190
+
191
+ it("returns an unsuccessful response", function() { with(this) {
192
+ server.subscribe(message, false, function(response) {
193
+ assertEqual({
194
+ channel: "/meta/subscribe",
195
+ successful: false,
196
+ error: "403:/meta/foo:Forbidden channel",
197
+ clientId: clientId,
198
+ subscription: "/meta/foo"
199
+ }, response)
200
+ })
201
+ }})
202
+
203
+ it("subscribes local clients to the channel", function() { with(this) {
204
+ expect(engine, "subscribe").given(clientId, "/meta/foo")
205
+ server.subscribe(message, true, function() {})
206
+ }})
207
+
208
+ it("returns a successful response for local clients", function() { with(this) {
209
+ stub(engine, "subscribe")
210
+ server.subscribe(message, true, function(response) {
211
+ assertEqual({
212
+ channel: "/meta/subscribe",
213
+ successful: true,
214
+ clientId: clientId,
215
+ subscription: "/meta/foo"
216
+ }, response)
217
+ })
218
+ }})
219
+ }})
220
+
221
+ describe("with an error", function() { with(this) {
222
+ before(function() { with(this) {
223
+ message.error = "invalid"
224
+ expect(engine, "clientExists").given(clientId).yielding([true])
225
+ }})
226
+
227
+ it("does not subscribe the client to the channel", function() { with(this) {
228
+ expect(engine, "subscribe").exactly(0)
229
+ server.subscribe(message, false, function() {})
230
+ }})
231
+
232
+ it("returns an unsuccessful response", function() { with(this) {
233
+ server.subscribe(message, false, function(response) {
234
+ assertEqual({
235
+ channel: "/meta/subscribe",
236
+ successful: false,
237
+ error: "invalid",
238
+ clientId: clientId,
239
+ subscription: "/foo"
240
+ }, response)
241
+ })
242
+ }})
243
+ }})
244
+ }})
245
+ }})
@@ -0,0 +1,245 @@
1
+ JS.ENV.Server.UnsubscribeSpec = JS.Test.describe("Server unsubscribe", function() { with(this) {
2
+ before(function() { with(this) {
3
+ this.engine = {}
4
+ stub(Faye.Engine, "get").returns(engine)
5
+ this.server = new Faye.Server()
6
+ }})
7
+
8
+ describe("#unsubscribe", function() { with(this) {
9
+ before(function() { with(this) {
10
+ this.clientId = "fakeclientid"
11
+ this.message = {channel: "/meta/unsubscribe",
12
+ clientId: "fakeclientid",
13
+ subscription: "/foo"}
14
+ }})
15
+
16
+ describe("with valid parameters", function() { with(this) {
17
+ before(function() { with(this) {
18
+ expect(engine, "clientExists").given(clientId).yielding([true])
19
+ }})
20
+
21
+ it("unsubscribes the client from the channel", function() { with(this) {
22
+ expect(engine, "unsubscribe").given(clientId, "/foo")
23
+ server.unsubscribe(message, false, function() {})
24
+ }})
25
+
26
+ it("returns a successful response", function() { with(this) {
27
+ stub(engine, "unsubscribe")
28
+ server.unsubscribe(message, false, function(response) {
29
+ assertEqual({
30
+ channel: "/meta/unsubscribe",
31
+ successful: true,
32
+ clientId: clientId,
33
+ subscription: "/foo"
34
+ }, response)
35
+ })
36
+ }})
37
+
38
+ describe("with a list of subscriptions", function() { with(this) {
39
+ before(function() { with(this) {
40
+ message.subscription = ["/foo", "/bar"]
41
+ }})
42
+
43
+ it("destroys multiple subscriptions", function() { with(this) {
44
+ expect(engine, "unsubscribe").given(clientId, "/foo")
45
+ expect(engine, "unsubscribe").given(clientId, "/bar")
46
+ server.unsubscribe(message, false, function() {})
47
+ }})
48
+
49
+ it("returns a successful response", function() { with(this) {
50
+ stub(engine, "unsubscribe")
51
+ server.unsubscribe(message, false, function(response) {
52
+ assertEqual({
53
+ channel: "/meta/unsubscribe",
54
+ successful: true,
55
+ clientId: clientId,
56
+ subscription: ["/foo", "/bar"]
57
+ }, response)
58
+ })
59
+ }})
60
+ }})
61
+
62
+ describe("with a subscription pattern", function() { with(this) {
63
+ before(function() { with(this) {
64
+ message.subscription = "/foo/**"
65
+ }})
66
+
67
+ it("destroys the subscription to the channel pattern", function() { with(this) {
68
+ expect(engine, "unsubscribe").given(clientId, "/foo/**")
69
+ server.unsubscribe(message, false, function() {})
70
+ }})
71
+
72
+ it("returns a successful response", function() { with(this) {
73
+ stub(engine, "unsubscribe")
74
+ server.unsubscribe(message, false, function(response) {
75
+ assertEqual({
76
+ channel: "/meta/unsubscribe",
77
+ successful: true,
78
+ clientId: clientId,
79
+ subscription: "/foo/**"
80
+ }, response)
81
+ })
82
+ }})
83
+ }})
84
+ }})
85
+
86
+ describe("with an unknown client", function() { with(this) {
87
+ before(function() { with(this) {
88
+ expect(engine, "clientExists").given(clientId).yielding([false])
89
+ }})
90
+
91
+ it("does not unsubscribe the client from the channel", function() { with(this) {
92
+ expect(engine, "unsubscribe").exactly(0)
93
+ server.unsubscribe(message, false, function() {})
94
+ }})
95
+
96
+ it("returns an unsuccessful response", function() { with(this) {
97
+ server.unsubscribe(message, false, function(response) {
98
+ assertEqual({
99
+ channel: "/meta/unsubscribe",
100
+ successful: false,
101
+ error: "401:fakeclientid:Unknown client",
102
+ clientId: clientId,
103
+ subscription: "/foo"
104
+ }, response)
105
+ })
106
+ }})
107
+ }})
108
+
109
+ describe("missing clientId", function() { with(this) {
110
+ before(function() { with(this) {
111
+ delete message.clientId
112
+ expect(engine, "clientExists").given(undefined).yielding([false])
113
+ }})
114
+
115
+ it("does not unsubscribe the client from the channel", function() { with(this) {
116
+ expect(engine, "unsubscribe").exactly(0)
117
+ server.unsubscribe(message, false, function() {})
118
+ }})
119
+
120
+ it("returns an unsuccessful response", function() { with(this) {
121
+ server.unsubscribe(message, false, function(response) {
122
+ assertEqual({
123
+ channel: "/meta/unsubscribe",
124
+ successful: false,
125
+ error: "402:clientId:Missing required parameter",
126
+ subscription: "/foo"
127
+ }, response)
128
+ })
129
+ }})
130
+ }})
131
+
132
+ describe("missing subscription", function() { with(this) {
133
+ before(function() { with(this) {
134
+ delete message.subscription
135
+ expect(engine, "clientExists").given(clientId).yielding([true])
136
+ }})
137
+
138
+ it("does not unsubscribe the client from the channel", function() { with(this) {
139
+ expect(engine, "unsubscribe").exactly(0)
140
+ server.unsubscribe(message, false, function() {})
141
+ }})
142
+
143
+ it("returns an unsuccessful response", function() { with(this) {
144
+ server.unsubscribe(message, false, function(response) {
145
+ assertEqual({
146
+ channel: "/meta/unsubscribe",
147
+ successful: false,
148
+ error: "402:subscription:Missing required parameter",
149
+ clientId: clientId,
150
+ subscription: []
151
+ }, response)
152
+ })
153
+ }})
154
+ }})
155
+
156
+ describe("with an invalid channel", function() { with(this) {
157
+ before(function() { with(this) {
158
+ message.subscription = "foo"
159
+ expect(engine, "clientExists").given(clientId).yielding([true])
160
+ }})
161
+
162
+ it("does not unsubscribe the client from the channel", function() { with(this) {
163
+ expect(engine, "unsubscribe").exactly(0)
164
+ server.unsubscribe(message, false, function() {})
165
+ }})
166
+
167
+ it("returns an unsuccessful response", function() { with(this) {
168
+ server.unsubscribe(message, false, function(response) {
169
+ assertEqual({
170
+ channel: "/meta/unsubscribe",
171
+ successful: false,
172
+ error: "405:foo:Invalid channel",
173
+ clientId: clientId,
174
+ subscription: "foo"
175
+ }, response)
176
+ })
177
+ }})
178
+ }})
179
+
180
+ describe("with a /meta/* channel", function() { with(this) {
181
+ before(function() { with(this) {
182
+ message.subscription = "/meta/foo"
183
+ expect(engine, "clientExists").given(clientId).yielding([true])
184
+ }})
185
+
186
+ it("does not unsubscribe the client from the channel", function() { with(this) {
187
+ expect(engine, "unsubscribe").exactly(0)
188
+ server.unsubscribe(message, false, function() {})
189
+ }})
190
+
191
+ it("returns an unsuccessful response", function() { with(this) {
192
+ server.unsubscribe(message, false, function(response) {
193
+ assertEqual({
194
+ channel: "/meta/unsubscribe",
195
+ successful: false,
196
+ error: "403:/meta/foo:Forbidden channel",
197
+ clientId: clientId,
198
+ subscription: "/meta/foo"
199
+ }, response)
200
+ })
201
+ }})
202
+
203
+ it("unsubscribes local clients from the channel", function() { with(this) {
204
+ expect(engine, "unsubscribe").given(clientId, "/meta/foo")
205
+ server.unsubscribe(message, true, function() {})
206
+ }})
207
+
208
+ it("returns a successful response for local clients", function() { with(this) {
209
+ stub(engine, "unsubscribe")
210
+ server.unsubscribe(message, true, function(response) {
211
+ assertEqual({
212
+ channel: "/meta/unsubscribe",
213
+ successful: true,
214
+ clientId: clientId,
215
+ subscription: "/meta/foo"
216
+ }, response)
217
+ })
218
+ }})
219
+ }})
220
+
221
+ describe("with an error", function() { with(this) {
222
+ before(function() { with(this) {
223
+ message.error = "invalid"
224
+ expect(engine, "clientExists").given(clientId).yielding([true])
225
+ }})
226
+
227
+ it("does not unsubscribe the client from the channel", function() { with(this) {
228
+ expect(engine, "unsubscribe").exactly(0)
229
+ server.unsubscribe(message, false, function() {})
230
+ }})
231
+
232
+ it("returns an unsuccessful response", function() { with(this) {
233
+ server.unsubscribe(message, false, function(response) {
234
+ assertEqual({
235
+ channel: "/meta/unsubscribe",
236
+ successful: false,
237
+ error: "invalid",
238
+ clientId: clientId,
239
+ subscription: "/foo"
240
+ }, response)
241
+ })
242
+ }})
243
+ }})
244
+ }})
245
+ }})