bushido-faye 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/History.txt +247 -0
  2. data/README.rdoc +92 -0
  3. data/lib/faye-browser-min.js +1 -0
  4. data/lib/faye.rb +121 -0
  5. data/lib/faye/adapters/rack_adapter.rb +209 -0
  6. data/lib/faye/engines/connection.rb +60 -0
  7. data/lib/faye/engines/memory.rb +112 -0
  8. data/lib/faye/engines/proxy.rb +111 -0
  9. data/lib/faye/error.rb +49 -0
  10. data/lib/faye/mixins/logging.rb +47 -0
  11. data/lib/faye/mixins/publisher.rb +30 -0
  12. data/lib/faye/mixins/timeouts.rb +22 -0
  13. data/lib/faye/protocol/channel.rb +124 -0
  14. data/lib/faye/protocol/client.rb +378 -0
  15. data/lib/faye/protocol/extensible.rb +43 -0
  16. data/lib/faye/protocol/grammar.rb +58 -0
  17. data/lib/faye/protocol/publication.rb +5 -0
  18. data/lib/faye/protocol/server.rb +282 -0
  19. data/lib/faye/protocol/subscription.rb +24 -0
  20. data/lib/faye/transport/http.rb +76 -0
  21. data/lib/faye/transport/local.rb +22 -0
  22. data/lib/faye/transport/transport.rb +115 -0
  23. data/lib/faye/transport/web_socket.rb +99 -0
  24. data/lib/faye/util/namespace.rb +20 -0
  25. data/spec/browser.html +45 -0
  26. data/spec/encoding_helper.rb +7 -0
  27. data/spec/install.sh +78 -0
  28. data/spec/javascript/channel_spec.js +15 -0
  29. data/spec/javascript/client_spec.js +714 -0
  30. data/spec/javascript/engine/memory_spec.js +7 -0
  31. data/spec/javascript/engine_spec.js +417 -0
  32. data/spec/javascript/faye_spec.js +15 -0
  33. data/spec/javascript/grammar_spec.js +66 -0
  34. data/spec/javascript/node_adapter_spec.js +307 -0
  35. data/spec/javascript/publisher_spec.js +27 -0
  36. data/spec/javascript/server/connect_spec.js +168 -0
  37. data/spec/javascript/server/disconnect_spec.js +121 -0
  38. data/spec/javascript/server/extensions_spec.js +60 -0
  39. data/spec/javascript/server/handshake_spec.js +145 -0
  40. data/spec/javascript/server/integration_spec.js +124 -0
  41. data/spec/javascript/server/publish_spec.js +85 -0
  42. data/spec/javascript/server/subscribe_spec.js +247 -0
  43. data/spec/javascript/server/unsubscribe_spec.js +245 -0
  44. data/spec/javascript/server_spec.js +110 -0
  45. data/spec/javascript/transport_spec.js +130 -0
  46. data/spec/node.js +55 -0
  47. data/spec/phantom.js +17 -0
  48. data/spec/ruby/channel_spec.rb +17 -0
  49. data/spec/ruby/client_spec.rb +724 -0
  50. data/spec/ruby/engine/memory_spec.rb +7 -0
  51. data/spec/ruby/engine_examples.rb +427 -0
  52. data/spec/ruby/faye_spec.rb +14 -0
  53. data/spec/ruby/grammar_spec.rb +68 -0
  54. data/spec/ruby/publisher_spec.rb +27 -0
  55. data/spec/ruby/rack_adapter_spec.rb +236 -0
  56. data/spec/ruby/server/connect_spec.rb +170 -0
  57. data/spec/ruby/server/disconnect_spec.rb +120 -0
  58. data/spec/ruby/server/extensions_spec.rb +68 -0
  59. data/spec/ruby/server/handshake_spec.rb +143 -0
  60. data/spec/ruby/server/integration_spec.rb +126 -0
  61. data/spec/ruby/server/publish_spec.rb +81 -0
  62. data/spec/ruby/server/subscribe_spec.rb +247 -0
  63. data/spec/ruby/server/unsubscribe_spec.rb +247 -0
  64. data/spec/ruby/server_spec.rb +110 -0
  65. data/spec/ruby/transport_spec.rb +134 -0
  66. data/spec/spec_helper.rb +11 -0
  67. data/spec/testswarm +29 -0
  68. data/spec/thin_proxy.rb +37 -0
  69. metadata +302 -0
@@ -0,0 +1,85 @@
1
+ JS.ENV.Server.PublishSpec = JS.Test.describe("Server publish", 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
+ this.message = {channel: "/some/channel", data: "publish"}
8
+ }})
9
+
10
+ describe("publishing a message", function() { with(this) {
11
+ it("tells the engine to publish the message", function() { with(this) {
12
+ expect(engine, "publish").given(message)
13
+ server.process(message, false, function() {})
14
+ }})
15
+
16
+ it("returns a successful response", function() { with(this) {
17
+ stub(engine, "publish")
18
+ server.process(message, false, function(response) {
19
+ assertEqual([
20
+ { channel: "/some/channel",
21
+ successful: true
22
+ }
23
+ ], response)
24
+ })
25
+ }})
26
+
27
+ describe("with an invalid channel", function() { with(this) {
28
+ before(function() { with(this) {
29
+ message.channel = "channel"
30
+ }})
31
+
32
+ it("does not tell the engine to publish the message", function() { with(this) {
33
+ expect(engine, "publish").exactly(0)
34
+ server.process(message, false, function() {})
35
+ }})
36
+
37
+ it("returns an unsuccessful response", function() { with(this) {
38
+ stub(engine, "publish")
39
+ server.process(message, false, function(response) {
40
+ assertEqual([
41
+ { channel: "channel",
42
+ successful: false,
43
+ error: "405:channel:Invalid channel"
44
+ }
45
+ ], response)
46
+ })
47
+ }})
48
+ }})
49
+
50
+ describe("with an error", function() { with(this) {
51
+ before(function() { with(this) {
52
+ message.error = "invalid"
53
+ }})
54
+
55
+ it("does not tell the engine to publish the message", function() { with(this) {
56
+ expect(engine, "publish").exactly(0)
57
+ server.process(message, false, function() {})
58
+ }})
59
+
60
+ it("returns an unsuccessful response", function() { with(this) {
61
+ stub(engine, "publish")
62
+ server.process(message, false, function(response) {
63
+ assertEqual([
64
+ { channel: "/some/channel",
65
+ successful: false,
66
+ error: "invalid"
67
+ }
68
+ ], response)
69
+ })
70
+ }})
71
+ }})
72
+
73
+ describe("to an invalid channel", function() { with(this) {
74
+ before(function() { with(this) {
75
+ message.channel = "/invalid/*"
76
+ }})
77
+
78
+ it("does not tell the engine to publish the message", function() { with(this) {
79
+ expect(engine, "publish").exactly(0)
80
+ server.process(message, false, function() {})
81
+ }})
82
+ }})
83
+ }})
84
+ }})
85
+
@@ -0,0 +1,247 @@
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(resume) { with(this) {
233
+ server.subscribe(message, false, function(response) {
234
+ resume(function() {
235
+ assertEqual({
236
+ channel: "/meta/subscribe",
237
+ successful: false,
238
+ error: "invalid",
239
+ clientId: clientId,
240
+ subscription: "/foo"
241
+ }, response)
242
+ })
243
+ })
244
+ }})
245
+ }})
246
+ }})
247
+ }})
@@ -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
+ }})