faye 0.8.8 → 0.8.9

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 (67) hide show
  1. data/History.txt +16 -10
  2. data/README.rdoc +1 -1
  3. data/lib/faye-browser-min.js +1 -1
  4. data/lib/faye-browser-min.js.map +2 -2
  5. data/lib/faye-browser.js +302 -287
  6. data/lib/faye.rb +21 -21
  7. data/lib/faye/adapters/rack_adapter.rb +50 -48
  8. data/lib/faye/adapters/static_server.rb +22 -22
  9. data/lib/faye/engines/connection.rb +13 -13
  10. data/lib/faye/engines/memory.rb +21 -21
  11. data/lib/faye/engines/proxy.rb +23 -23
  12. data/lib/faye/error.rb +6 -6
  13. data/lib/faye/mixins/logging.rb +12 -12
  14. data/lib/faye/mixins/publisher.rb +6 -6
  15. data/lib/faye/mixins/timeouts.rb +1 -1
  16. data/lib/faye/protocol/channel.rb +24 -24
  17. data/lib/faye/protocol/client.rb +71 -73
  18. data/lib/faye/protocol/extensible.rb +7 -7
  19. data/lib/faye/protocol/grammar.rb +13 -13
  20. data/lib/faye/protocol/server.rb +57 -57
  21. data/lib/faye/protocol/socket.rb +4 -4
  22. data/lib/faye/protocol/subscription.rb +4 -4
  23. data/lib/faye/transport/http.rb +13 -13
  24. data/lib/faye/transport/local.rb +5 -5
  25. data/lib/faye/transport/transport.rb +25 -25
  26. data/lib/faye/transport/web_socket.rb +34 -30
  27. data/lib/faye/util/namespace.rb +4 -4
  28. data/spec/browser.html +5 -5
  29. data/spec/javascript/channel_spec.js +3 -3
  30. data/spec/javascript/client_spec.js +104 -98
  31. data/spec/javascript/engine/memory_spec.js +1 -1
  32. data/spec/javascript/engine_spec.js +70 -70
  33. data/spec/javascript/faye_spec.js +6 -6
  34. data/spec/javascript/grammar_spec.js +12 -12
  35. data/spec/javascript/node_adapter_spec.js +46 -46
  36. data/spec/javascript/publisher_spec.js +4 -4
  37. data/spec/javascript/server/connect_spec.js +21 -21
  38. data/spec/javascript/server/disconnect_spec.js +15 -15
  39. data/spec/javascript/server/extensions_spec.js +6 -6
  40. data/spec/javascript/server/handshake_spec.js +18 -18
  41. data/spec/javascript/server/integration_spec.js +23 -23
  42. data/spec/javascript/server/publish_spec.js +9 -9
  43. data/spec/javascript/server/subscribe_spec.js +30 -30
  44. data/spec/javascript/server/unsubscribe_spec.js +30 -30
  45. data/spec/javascript/server_spec.js +15 -15
  46. data/spec/javascript/transport_spec.js +32 -27
  47. data/spec/node.js +2 -2
  48. data/spec/ruby/channel_spec.rb +2 -2
  49. data/spec/ruby/client_spec.rb +100 -92
  50. data/spec/ruby/engine_examples.rb +51 -51
  51. data/spec/ruby/faye_spec.rb +5 -5
  52. data/spec/ruby/grammar_spec.rb +12 -12
  53. data/spec/ruby/publisher_spec.rb +4 -4
  54. data/spec/ruby/rack_adapter_spec.rb +34 -34
  55. data/spec/ruby/server/connect_spec.rb +22 -22
  56. data/spec/ruby/server/disconnect_spec.rb +16 -16
  57. data/spec/ruby/server/extensions_spec.rb +8 -8
  58. data/spec/ruby/server/handshake_spec.rb +20 -20
  59. data/spec/ruby/server/integration_spec.rb +22 -24
  60. data/spec/ruby/server/publish_spec.rb +9 -9
  61. data/spec/ruby/server/subscribe_spec.rb +31 -31
  62. data/spec/ruby/server/unsubscribe_spec.rb +31 -31
  63. data/spec/ruby/server_spec.rb +17 -17
  64. data/spec/ruby/transport_spec.rb +23 -23
  65. data/spec/testswarm +23 -10
  66. data/spec/thin_proxy.rb +5 -5
  67. metadata +90 -59
@@ -1,32 +1,32 @@
1
1
  JS.ENV.FayeSpec = JS.Test.describe("Faye", function() { with(this) {
2
2
  include(JS.Test.Helpers)
3
-
3
+
4
4
  describe("random", function() { with(this) {
5
5
  it("returns a 128-bit random number in base 36", function() { with(this) {
6
6
  assertMatch( /^[a-z0-9]+$/, Faye.random() )
7
7
  }})
8
-
8
+
9
9
  it("always produces the same length of string", function() { with(this) {
10
10
  var ids = $R(1,100).map(function() { return Faye.random().length })
11
11
  var expected = $R(1,100).map(function() { return 35 })
12
12
  assertEqual( expected, ids )
13
13
  }})
14
14
  }})
15
-
15
+
16
16
  describe("copyObject", function() { with(this) {
17
17
  before(function() { with(this) {
18
18
  this.object = {foo: "bar", qux: 42, hey: null, obj: {bar: 67}}
19
19
  }})
20
-
20
+
21
21
  it("returns an equal object", function() { with(this) {
22
22
  assertEqual( {foo: "bar", qux: 42, hey: null, obj: {bar: 67}},
23
23
  Faye.copyObject(object) )
24
24
  }})
25
-
25
+
26
26
  it("does not return the same object", function() { with(this) {
27
27
  assertNotSame( object, Faye.copyObject(object) )
28
28
  }})
29
-
29
+
30
30
  it("performs a deep clone", function() { with(this) {
31
31
  assertNotSame( object.obj, Faye.copyObject(object).obj )
32
32
  }})
@@ -3,61 +3,61 @@ JS.ENV.GrammarSpec = JS.Test.describe("Grammar", function() { with(this) {
3
3
  it("matches valid channel names", function() { with(this) {
4
4
  assertMatch( Faye.Grammar.CHANNEL_NAME, "/fo_o/$@()bar" )
5
5
  }})
6
-
6
+
7
7
  it("does not match channel patterns", function() { with(this) {
8
8
  assertNoMatch( Faye.Grammar.CHANNEL_NAME, "/foo/**" )
9
9
  }})
10
-
10
+
11
11
  it("does not match invalid channel names", function() { with(this) {
12
12
  assertNoMatch( Faye.Grammar.CHANNEL_NAME, "foo/$@()bar" )
13
13
  assertNoMatch( Faye.Grammar.CHANNEL_NAME, "/foo/$@()bar/" )
14
14
  assertNoMatch( Faye.Grammar.CHANNEL_NAME, "/fo o/$@()bar" )
15
15
  }})
16
16
  }})
17
-
17
+
18
18
  describe("CHANNEL_PATTERN", function() { with(this) {
19
19
  it("does not match channel names", function() { with(this) {
20
20
  assertNoMatch( Faye.Grammar.CHANNEL_PATTERN, "/fo_o/$@()bar" )
21
21
  }})
22
-
22
+
23
23
  it("matches valid channel patterns", function() { with(this) {
24
24
  assertMatch( Faye.Grammar.CHANNEL_PATTERN, "/foo/**" )
25
25
  assertMatch( Faye.Grammar.CHANNEL_PATTERN, "/foo/*" )
26
26
  }})
27
-
27
+
28
28
  it("does not match invalid channel patterns", function() { with(this) {
29
29
  assertNoMatch( Faye.Grammar.CHANNEL_PATTERN, "/foo/**/*" )
30
30
  }})
31
31
  }})
32
-
32
+
33
33
  describe("ERROR", function() { with(this) {
34
34
  it("matches an error with an argument", function() { with(this) {
35
35
  assertMatch( Faye.Grammar.ERROR, "402:xj3sjdsjdsjad:Unknown Client ID" )
36
36
  }})
37
-
37
+
38
38
  it("matches an error with many arguments", function() { with(this) {
39
39
  assertMatch( Faye.Grammar.ERROR, "403:xj3sjdsjdsjad,/foo/bar:Subscription denied" )
40
40
  }})
41
-
41
+
42
42
  it("matches an error with no arguments", function() { with(this) {
43
43
  assertMatch( Faye.Grammar.ERROR, "402::Unknown Client ID" )
44
44
  }})
45
-
45
+
46
46
  it("does not match an error with no code", function() { with(this) {
47
47
  assertNoMatch( Faye.Grammar.ERROR, ":xj3sjdsjdsjad:Unknown Client ID" )
48
48
  }})
49
-
49
+
50
50
  it("does not match an error with an invalid code", function() { with(this) {
51
51
  assertNoMatch( Faye.Grammar.ERROR, "40:xj3sjdsjdsjad:Unknown Client ID" )
52
52
  }})
53
53
  }})
54
-
54
+
55
55
  describe("VERSION", function() { with(this) {
56
56
  it("matches a version number", function() { with(this) {
57
57
  assertMatch( Faye.Grammar.VERSION, "9" )
58
58
  assertMatch( Faye.Grammar.VERSION, "9.0.a-delta1" )
59
59
  }})
60
-
60
+
61
61
  it("does not match invalid version numbers", function() { with(this) {
62
62
  assertNoMatch( Faye.Grammar.VERSION, "9.0.a-delta1." )
63
63
  assertNoMatch( Faye.Grammar.VERSION, "" )
@@ -7,23 +7,23 @@ JS.ENV.NodeAdapterSteps = JS.Test.asyncSteps({
7
7
  this._app = new Faye.NodeAdapter(this.options())
8
8
  this._app.listen(port, {}, resume)
9
9
  },
10
-
10
+
11
11
  stop_server: function(resume) {
12
12
  this._app.stop(resume)
13
13
  },
14
-
14
+
15
15
  header: function(key, value, resume) {
16
16
  this._headers = this._headers || {}
17
17
  this._headers[key] = value
18
18
  resume()
19
19
  },
20
-
20
+
21
21
  get: function(path, params, resume) {
22
22
  var client = http.createClient(this._port, "localhost"),
23
23
  body = querystring.stringify(params),
24
24
  request = client.request("GET", path + (body ? "?" + body : "")),
25
25
  self = this
26
-
26
+
27
27
  request.addListener("response", function(response) {
28
28
  self._response = response
29
29
  var data = ""
@@ -35,22 +35,22 @@ JS.ENV.NodeAdapterSteps = JS.Test.asyncSteps({
35
35
  })
36
36
  request.end()
37
37
  },
38
-
38
+
39
39
  post: function(path, body, resume) {
40
40
  var client = http.createClient(this._port, "localhost"),
41
-
41
+
42
42
  body = (typeof body === "string")
43
43
  ? body
44
44
  : querystring.stringify(body),
45
-
45
+
46
46
  headers = Faye.extend({
47
47
  "Host": "localhost",
48
48
  "Content-Length": body.length
49
49
  }, this._headers || {}),
50
-
50
+
51
51
  request = client.request("POST", path, headers),
52
52
  self = this
53
-
53
+
54
54
  request.addListener("response", function(response) {
55
55
  self._response = response
56
56
  var data = ""
@@ -63,32 +63,32 @@ JS.ENV.NodeAdapterSteps = JS.Test.asyncSteps({
63
63
  request.write(body)
64
64
  request.end()
65
65
  },
66
-
66
+
67
67
  check_status: function(code, resume) {
68
68
  this.assertEqual(code, this._response.statusCode)
69
69
  resume()
70
70
  },
71
-
71
+
72
72
  check_access_control_origin: function(origin, resume) {
73
73
  this.assertEqual(origin, this._response.headers["access-control-allow-origin"])
74
74
  resume()
75
75
  },
76
-
76
+
77
77
  check_cache_control: function(value, resume) {
78
78
  this.assertEqual(value, this._response.headers["cache-control"])
79
79
  resume()
80
80
  },
81
-
81
+
82
82
  check_content_type: function(type, resume) {
83
83
  this.assertEqual(type + "; charset=utf-8", this._response.headers["content-type"])
84
84
  resume()
85
85
  },
86
-
86
+
87
87
  check_content_length: function(length, resume) {
88
88
  this.assertEqual(length, this._response.headers["content-length"])
89
89
  resume()
90
90
  },
91
-
91
+
92
92
  check_body: function(body, resume) {
93
93
  if (typeof body === "string")
94
94
  this.assertEqual(body, this._responseBody)
@@ -96,7 +96,7 @@ JS.ENV.NodeAdapterSteps = JS.Test.asyncSteps({
96
96
  this.assertMatch(body, this._responseBody)
97
97
  resume()
98
98
  },
99
-
99
+
100
100
  check_json: function(object, resume) {
101
101
  this.assertEqual(object, JSON.parse(this._responseBody))
102
102
  resume()
@@ -105,37 +105,37 @@ JS.ENV.NodeAdapterSteps = JS.Test.asyncSteps({
105
105
 
106
106
  JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this) {
107
107
  include(NodeAdapterSteps)
108
-
108
+
109
109
  define("options", function() {
110
110
  return {mount: "/bayeux", timeout: 30}
111
111
  })
112
-
112
+
113
113
  before(function() { with(this) {
114
114
  this.server = {}
115
115
  expect(Faye, "Server").given(options()).returning(server)
116
116
  start_server(8282)
117
117
  }})
118
-
118
+
119
119
  after(function() { this.stop_server() })
120
-
120
+
121
121
  describe("POST requests", function() { with(this) {
122
122
  describe("with cross-origin access control", function() { with(this) {
123
123
  sharedBehavior("cross-origin request", function() { with(this) {
124
124
  before(function() { with(this) {
125
125
  header("Origin", "http://example.com")
126
126
  }})
127
-
127
+
128
128
  it("returns a matching cross-origin access control header", function() { with(this) {
129
129
  stub(server, "process").yields([[]])
130
130
  post("/bayeux", {message: "[]"})
131
131
  check_access_control_origin("http://example.com")
132
132
  }})
133
-
133
+
134
134
  it("forwards the message param onto the server", function() { with(this) {
135
135
  expect(server, "process").given({channel: "/plain"}, false).yielding([[]])
136
136
  post("/bayeux", "message=%7B%22channel%22%3A%22%2Fplain%22%7D")
137
137
  }})
138
-
138
+
139
139
  it("returns the server's response as JSON", function() { with(this) {
140
140
  stub(server, "process").yields([[{channel: "/meta/handshake"}]])
141
141
  post("/bayeux", "message=%5B%5D")
@@ -144,7 +144,7 @@ JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this)
144
144
  check_content_length("31")
145
145
  check_json([{channel: "/meta/handshake"}])
146
146
  }})
147
-
147
+
148
148
  it("returns a 400 response if malformed JSON is given", function() { with(this) {
149
149
  expect(server, "process").exactly(0)
150
150
  post("/bayeux", "message=%7B%5B")
@@ -152,34 +152,34 @@ JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this)
152
152
  check_content_type("text/plain")
153
153
  }})
154
154
  }})
155
-
155
+
156
156
  describe("with text/plain", function() { with(this) {
157
157
  before(function() { this.header("Content-Type", "text/plain") })
158
158
  behavesLike("cross-origin request")
159
159
  }})
160
-
160
+
161
161
  describe("with application/xml", function() { with(this) {
162
162
  before(function() { this.header("Content-Type", "application/xml") })
163
163
  behavesLike("cross-origin request")
164
164
  }})
165
165
  }})
166
-
166
+
167
167
  describe("with application/json", function() { with(this) {
168
168
  before(function() { with(this) {
169
169
  header("Content-Type", "application/json")
170
170
  }})
171
-
171
+
172
172
  it("does not return an access control header", function() { with(this) {
173
173
  stub(server, "process").yields([[]])
174
174
  post("/bayeux", "[]")
175
175
  check_access_control_origin(undefined)
176
176
  }})
177
-
177
+
178
178
  it("forwards the POST body onto the server", function() { with(this) {
179
179
  expect(server, "process").given({channel: "/foo"}, false).yielding([[]])
180
180
  post("/bayeux", '{"channel":"/foo"}')
181
181
  }})
182
-
182
+
183
183
  it("returns the server's response as JSON", function() { with(this) {
184
184
  stub(server, "process").yields([[{channel: "/meta/handshake"}]])
185
185
  post("/bayeux", "[]")
@@ -188,7 +188,7 @@ JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this)
188
188
  check_content_length("31")
189
189
  check_json([{channel: "/meta/handshake"}])
190
190
  }})
191
-
191
+
192
192
  it("returns a 400 response if malformed JSON is given", function() { with(this) {
193
193
  expect(server, "process").exactly(0)
194
194
  post("/bayeux", "[}")
@@ -196,13 +196,13 @@ JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this)
196
196
  check_content_type("text/plain")
197
197
  }})
198
198
  }})
199
-
199
+
200
200
  describe("with no content type", function() { with(this) {
201
201
  it("forwards the message param onto the server", function() { with(this) {
202
202
  expect(server, "process").given({channel: "/foo"}, false).yielding([[]])
203
203
  post("/bayeux", {message: '{"channel":"/foo"}'})
204
204
  }})
205
-
205
+
206
206
  it("returns the server's response as JSON", function() { with(this) {
207
207
  stub(server, "process").yields([[{channel: "/meta/handshake"}]])
208
208
  post("/bayeux", {message: "[]"})
@@ -211,7 +211,7 @@ JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this)
211
211
  check_content_length("31")
212
212
  check_json([{channel: "/meta/handshake"}])
213
213
  }})
214
-
214
+
215
215
  it("returns a 400 response if malformed JSON is given", function() { with(this) {
216
216
  expect(server, "process").exactly(0)
217
217
  post("/bayeux", {message: "[}"})
@@ -220,22 +220,22 @@ JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this)
220
220
  }})
221
221
  }})
222
222
  }})
223
-
223
+
224
224
  describe("GET requests", function() { with(this) {
225
225
  before(function() { with(this) {
226
226
  this.params = {message: '{"channel":"/foo"}', jsonp: "callback"}
227
227
  }})
228
-
228
+
229
229
  describe("with valid params", function() { with(this) {
230
230
  before(function() { with(this) {
231
231
  expect(server, "flushConnection").given({channel: "/foo"})
232
232
  }})
233
-
233
+
234
234
  it("forwards the message param onto the server", function() { with(this) {
235
235
  expect(server, "process").given({channel: "/foo"}, false).yielding([[]])
236
236
  get("/bayeux", params)
237
237
  }})
238
-
238
+
239
239
  it("returns the server's response as JavaScript", function() { with(this) {
240
240
  stub(server, "process").yields([[{channel: "/meta/handshake"}]])
241
241
  get("/bayeux", params)
@@ -244,20 +244,20 @@ JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this)
244
244
  check_content_length("42")
245
245
  check_body('callback([{"channel":"/meta/handshake"}]);')
246
246
  }})
247
-
247
+
248
248
  it("does not let the client cache the response", function() { with(this) {
249
249
  stub(server, "process").yields([[{channel: "/meta/handshake"}]])
250
250
  get("/bayeux", params)
251
251
  check_cache_control("no-cache, no-store")
252
252
  }})
253
253
  }})
254
-
254
+
255
255
  describe("missing jsonp", function() { with(this) {
256
256
  before(function() { with(this) {
257
257
  delete params.jsonp
258
258
  expect(server, "flushConnection")
259
259
  }})
260
-
260
+
261
261
  it("returns the server's response using the default callback", function() { with(this) {
262
262
  stub(server, "process").yields([[{channel: "/meta/handshake"}]])
263
263
  get("/bayeux", params)
@@ -267,34 +267,34 @@ JS.ENV.NodeAdapterSpec = JS.Test.describe("NodeAdapter", function() { with(this)
267
267
  check_body('jsonpcallback([{"channel":"/meta/handshake"}]);')
268
268
  }})
269
269
  }})
270
-
270
+
271
271
  sharedBehavior("bad GET request", function() { with(this) {
272
272
  it("does not call the server", function() { with(this) {
273
273
  expect(server, "process").exactly(0)
274
274
  get("/bayeux", params)
275
275
  }})
276
-
276
+
277
277
  it("returns a 400 response", function() { with(this) {
278
278
  get("/bayeux", params)
279
279
  check_status(400)
280
280
  check_content_type("text/plain")
281
281
  }})
282
282
  }})
283
-
283
+
284
284
  describe("with malformed JSON", function() { with(this) {
285
285
  before(function() { with(this) {
286
286
  params.message = "[}"
287
287
  }})
288
288
  behavesLike("bad GET request")
289
289
  }})
290
-
290
+
291
291
  describe("missing message", function() { with(this) {
292
292
  before(function() { with(this) {
293
293
  delete params.message
294
294
  }})
295
295
  behavesLike("bad GET request")
296
296
  }})
297
-
297
+
298
298
  describe("for the client script", function() { with(this) {
299
299
  it("returns the client script", function() { with(this) {
300
300
  get("/bayeux.js", {})
@@ -2,21 +2,21 @@ JS.ENV.PublisherSpec = JS.Test.describe("Publisher", function() { with(this) {
2
2
  before(function() { with(this) {
3
3
  this.publisher = Faye.extend({}, Faye.Publisher)
4
4
  }})
5
-
5
+
6
6
  describe("with subscribers that remove themselves", function() { with(this) {
7
7
  before(function() { with(this) {
8
8
  this.calledA = false
9
9
  this.calledB = false
10
-
10
+
11
11
  this.handler = function() {
12
12
  calledA = true
13
13
  publisher.unbind("event", handler)
14
14
  }
15
-
15
+
16
16
  publisher.bind("event", handler)
17
17
  publisher.bind("event", function() { calledB = true })
18
18
  }})
19
-
19
+
20
20
  it("successfully calls all the callbacks", function() { with(this) {
21
21
  publisher.trigger("event")
22
22
  assert( calledA )