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
@@ -2,21 +2,21 @@ require "spec_helper"
2
2
 
3
3
  describe Faye::Publisher do
4
4
  let(:publisher) { Object.new.extend(Faye::Publisher) }
5
-
5
+
6
6
  describe "with subscribers that remove themselves" do
7
7
  before do
8
8
  @called_a = false
9
9
  @called_b = false
10
-
10
+
11
11
  handler = lambda do
12
12
  @called_a = true
13
13
  publisher.unbind(:event, &handler)
14
14
  end
15
-
15
+
16
16
  publisher.bind(:event, &handler)
17
17
  publisher.bind(:event) { @called_b = true }
18
18
  end
19
-
19
+
20
20
  it "successfully calls all the callbacks" do
21
21
  publisher.trigger(:event)
22
22
  @called_a.should == true
@@ -7,9 +7,9 @@ describe Faye::RackAdapter do
7
7
  let(:app) { ThinProxy.new(adapter) }
8
8
  let(:options) { {:mount => "/bayeux", :timeout => 30} }
9
9
  let(:server) { mock "server" }
10
-
10
+
11
11
  after { app.stop }
12
-
12
+
13
13
  let(:content_type) { last_response["Content-Type"] }
14
14
  let(:content_length) { last_response["Content-Length"] }
15
15
  let(:cache_control) { last_response["Cache-Control"] }
@@ -17,30 +17,30 @@ describe Faye::RackAdapter do
17
17
  let(:json) { Yajl::Parser.parse(body) }
18
18
  let(:body) { last_response.body }
19
19
  let(:status) { last_response.status.to_i }
20
-
20
+
21
21
  before do
22
22
  Faye::Server.should_receive(:new).with(options).and_return server
23
23
  adapter.stub(:get_client).and_return mock("client")
24
24
  end
25
-
25
+
26
26
  describe "POST requests" do
27
27
  describe "with cross-origin access control" do
28
28
  shared_examples_for "cross-origin request" do
29
29
  before do
30
30
  header "Origin", "http://example.com"
31
31
  end
32
-
32
+
33
33
  it "returns a matching cross-origin access control header" do
34
34
  server.stub(:process).and_yield []
35
35
  post "/bayeux", :message => '[]'
36
36
  access_control_origin.should == "http://example.com"
37
37
  end
38
-
38
+
39
39
  it "forwards the message param onto the server" do
40
40
  server.should_receive(:process).with({"channel" => "/plain"}, false).and_yield []
41
41
  post "/bayeux", "message=%7B%22channel%22%3A%22%2Fplain%22%7D"
42
42
  end
43
-
43
+
44
44
  it "returns the server's response as JSON" do
45
45
  server.stub(:process).and_yield ["channel" => "/meta/handshake"]
46
46
  post "/bayeux", "message=%5B%5D"
@@ -49,14 +49,14 @@ describe Faye::RackAdapter do
49
49
  content_length.should == "31"
50
50
  json.should == ["channel" => "/meta/handshake"]
51
51
  end
52
-
52
+
53
53
  it "returns a 400 response if malformed JSON is given" do
54
54
  server.should_not_receive(:process)
55
55
  post "/bayeux", "message=%7B%5B"
56
56
  status.should == 400
57
57
  content_type.should == "text/plain; charset=utf-8"
58
58
  end
59
-
59
+
60
60
  it "returns a 404 if the path is not matched" do
61
61
  server.should_not_receive(:process)
62
62
  post "/blaf", 'message=%5B%5D'
@@ -64,34 +64,34 @@ describe Faye::RackAdapter do
64
64
  content_type.should == "text/plain; charset=utf-8"
65
65
  end
66
66
  end
67
-
67
+
68
68
  describe "with text/plain" do
69
69
  before { header "Content-Type", "text/plain" }
70
70
  it_should_behave_like "cross-origin request"
71
71
  end
72
-
72
+
73
73
  describe "with application/xml" do
74
74
  before { header "Content-Type", "application/xml" }
75
75
  it_should_behave_like "cross-origin request"
76
76
  end
77
77
  end
78
-
78
+
79
79
  describe "with application/json" do
80
80
  before do
81
81
  header "Content-Type", "application/json"
82
82
  end
83
-
83
+
84
84
  it "does not return an access control header" do
85
85
  server.stub(:process).and_yield []
86
86
  post "/bayeux", :message => '[]'
87
87
  access_control_origin.should be_nil
88
88
  end
89
-
89
+
90
90
  it "forwards the POST body onto the server" do
91
91
  server.should_receive(:process).with({"channel" => "/foo"}, false).and_yield []
92
92
  post "/bayeux", '{"channel":"/foo"}'
93
93
  end
94
-
94
+
95
95
  it "returns the server's response as JSON" do
96
96
  server.stub(:process).and_yield ["channel" => "/meta/handshake"]
97
97
  post "/bayeux", '[]'
@@ -100,14 +100,14 @@ describe Faye::RackAdapter do
100
100
  content_length.should == "31"
101
101
  json.should == ["channel" => "/meta/handshake"]
102
102
  end
103
-
103
+
104
104
  it "returns a 400 response if malformed JSON is given" do
105
105
  server.should_not_receive(:process)
106
106
  post "/bayeux", "[}"
107
107
  status.should == 400
108
108
  content_type.should == "text/plain; charset=utf-8"
109
109
  end
110
-
110
+
111
111
  it "returns a 404 if the path is not matched" do
112
112
  server.should_not_receive(:process)
113
113
  post "/blaf", "[]"
@@ -115,13 +115,13 @@ describe Faye::RackAdapter do
115
115
  content_type.should == "text/plain; charset=utf-8"
116
116
  end
117
117
  end
118
-
118
+
119
119
  describe "with no content type" do
120
120
  it "forwards the message param onto the server" do
121
121
  server.should_receive(:process).with({"channel" => "/foo"}, false).and_yield []
122
122
  post "/bayeux", :message => '{"channel":"/foo"}'
123
123
  end
124
-
124
+
125
125
  it "returns the server's response as JSON" do
126
126
  server.stub(:process).and_yield ["channel" => "/meta/handshake"]
127
127
  post "/bayeux", :message => '[]'
@@ -130,14 +130,14 @@ describe Faye::RackAdapter do
130
130
  content_length.should == "31"
131
131
  json.should == ["channel" => "/meta/handshake"]
132
132
  end
133
-
133
+
134
134
  it "returns a 400 response if malformed JSON is given" do
135
135
  server.should_not_receive(:process)
136
136
  post "/bayeux", :message => "[}"
137
137
  status.should == 400
138
138
  content_type.should == "text/plain; charset=utf-8"
139
139
  end
140
-
140
+
141
141
  it "returns a 404 if the path is not matched" do
142
142
  server.should_not_receive(:process)
143
143
  post "/blaf", :message => "[]"
@@ -146,20 +146,20 @@ describe Faye::RackAdapter do
146
146
  end
147
147
  end
148
148
  end
149
-
149
+
150
150
  describe "GET requests" do
151
151
  let(:params) {{:message => '{"channel":"/foo"}', :jsonp => "callback"}}
152
-
152
+
153
153
  describe "with valid params" do
154
154
  before do
155
155
  server.should_receive(:flush_connection).with("channel" => "/foo")
156
156
  end
157
-
157
+
158
158
  it "forwards the message param onto the server" do
159
159
  server.should_receive(:process).with({"channel" => "/foo"}, false).and_yield []
160
160
  get "/bayeux", params
161
161
  end
162
-
162
+
163
163
  it "returns the server's response as JavaScript" do
164
164
  server.stub(:process).and_yield ["channel" => "/meta/handshake"]
165
165
  get "/bayeux", params
@@ -168,14 +168,14 @@ describe Faye::RackAdapter do
168
168
  content_length.should == "42"
169
169
  body.should == 'callback([{"channel":"/meta/handshake"}]);'
170
170
  end
171
-
171
+
172
172
  it "does not let the client cache the response" do
173
173
  server.stub(:process).and_yield ["channel" => "/meta/handshake"]
174
174
  get "/bayeux", params
175
175
  cache_control.should == "no-cache, no-store"
176
176
  end
177
177
  end
178
-
178
+
179
179
  describe "with an unknown path" do
180
180
  it "returns a 404" do
181
181
  server.should_not_receive(:process)
@@ -184,13 +184,13 @@ describe Faye::RackAdapter do
184
184
  content_type.should == "text/plain; charset=utf-8"
185
185
  end
186
186
  end
187
-
187
+
188
188
  describe "missing jsonp" do
189
189
  before do
190
190
  params.delete(:jsonp)
191
191
  server.should_receive(:flush_connection)
192
192
  end
193
-
193
+
194
194
  it "returns the server's response using the default callback" do
195
195
  server.stub(:process).and_yield ["channel" => "/meta/handshake"]
196
196
  get "/bayeux", params
@@ -200,30 +200,30 @@ describe Faye::RackAdapter do
200
200
  body.should == 'jsonpcallback([{"channel":"/meta/handshake"}]);'
201
201
  end
202
202
  end
203
-
203
+
204
204
  shared_examples_for "bad GET request" do
205
205
  it "does not call the server" do
206
206
  server.should_not_receive(:process)
207
207
  get "/bayeux", params
208
208
  end
209
-
209
+
210
210
  it "returns a 400 response" do
211
211
  get "/bayeux", params
212
212
  status.should == 400
213
213
  content_type.should == "text/plain; charset=utf-8"
214
214
  end
215
215
  end
216
-
216
+
217
217
  describe "with malformed JSON" do
218
218
  before { params[:message] = "[}" }
219
219
  it_should_behave_like "bad GET request"
220
220
  end
221
-
221
+
222
222
  describe "missing message" do
223
223
  before { params.delete(:message) }
224
224
  it_should_behave_like "bad GET request"
225
225
  end
226
-
226
+
227
227
  describe "for the client script" do
228
228
  it "returns the client script" do
229
229
  get "/bayeux.js"
@@ -3,29 +3,29 @@ require "spec_helper"
3
3
  describe "server connect" do
4
4
  let(:engine) { mock "engine" }
5
5
  let(:server) { Faye::Server.new }
6
-
6
+
7
7
  before do
8
8
  Faye::Engine.stub(:get).and_return engine
9
9
  end
10
-
10
+
11
11
  describe :connect do
12
12
  let(:client_id) { "fakeclientid" }
13
13
  let(:message) {{"channel" => "/meta/connect",
14
14
  "clientId" => "fakeclientid",
15
15
  "connectionType" => "long-polling"
16
16
  }}
17
-
17
+
18
18
  describe "with valid paramters" do
19
19
  before do
20
20
  message["advice"] = {"timeout" => 60}
21
21
  engine.should_receive(:client_exists).with(client_id).and_yield true
22
22
  end
23
-
23
+
24
24
  it "connects to the engine to wait for new messages" do
25
25
  engine.should_receive(:connect).with(client_id, {"timeout" => 60})
26
26
  server.connect(message) {}
27
27
  end
28
-
28
+
29
29
  it "returns a successful response and any queued messages" do
30
30
  engine.stub(:connect).and_yield([{"channel" => "/x", "data" => "hello"}])
31
31
  server.connect(message) do |response|
@@ -40,10 +40,10 @@ describe "server connect" do
40
40
  ]
41
41
  end
42
42
  end
43
-
43
+
44
44
  describe "with a message id" do
45
45
  before { message["id"] = "foo" }
46
-
46
+
47
47
  it "returns the same id" do
48
48
  engine.stub(:connect)
49
49
  server.connect(message) do |response|
@@ -57,17 +57,17 @@ describe "server connect" do
57
57
  end
58
58
  end
59
59
  end
60
-
60
+
61
61
  describe "with an unknown client" do
62
62
  before do
63
63
  engine.should_receive(:client_exists).with(client_id).and_yield false
64
64
  end
65
-
65
+
66
66
  it "does not connect to the engine" do
67
67
  engine.should_not_receive(:connect)
68
68
  server.connect(message) {}
69
69
  end
70
-
70
+
71
71
  it "returns an unsuccessful response" do
72
72
  server.connect(message) do |response|
73
73
  response.should == {
@@ -78,18 +78,18 @@ describe "server connect" do
78
78
  end
79
79
  end
80
80
  end
81
-
81
+
82
82
  describe "missing clientId" do
83
83
  before do
84
84
  message.delete("clientId")
85
85
  engine.should_receive(:client_exists).with(nil).and_yield false
86
86
  end
87
-
87
+
88
88
  it "does not connect to the engine" do
89
89
  engine.should_not_receive(:connect)
90
90
  server.connect(message) {}
91
91
  end
92
-
92
+
93
93
  it "returns an unsuccessful response" do
94
94
  server.connect(message) do |response|
95
95
  response.should == {
@@ -100,18 +100,18 @@ describe "server connect" do
100
100
  end
101
101
  end
102
102
  end
103
-
103
+
104
104
  describe "missing connectionType" do
105
105
  before do
106
106
  message.delete("connectionType")
107
107
  engine.should_receive(:client_exists).with(client_id).and_yield true
108
108
  end
109
-
109
+
110
110
  it "does not connect to the engine" do
111
111
  engine.should_not_receive(:connect)
112
112
  server.connect(message) {}
113
113
  end
114
-
114
+
115
115
  it "returns an unsuccessful response" do
116
116
  server.connect(message) do |response|
117
117
  response.should == {
@@ -122,18 +122,18 @@ describe "server connect" do
122
122
  end
123
123
  end
124
124
  end
125
-
125
+
126
126
  describe "with an unknown connectionType" do
127
127
  before do
128
128
  message["connectionType"] = "flash"
129
129
  engine.should_receive(:client_exists).with(client_id).and_yield true
130
130
  end
131
-
131
+
132
132
  it "does not connect to the engine" do
133
133
  engine.should_not_receive(:connect)
134
134
  server.connect(message) {}
135
135
  end
136
-
136
+
137
137
  it "returns an unsuccessful response" do
138
138
  server.connect(message) do |response|
139
139
  response.should == {
@@ -144,18 +144,18 @@ describe "server connect" do
144
144
  end
145
145
  end
146
146
  end
147
-
147
+
148
148
  describe "with an error" do
149
149
  before do
150
150
  message["error"] = "invalid"
151
151
  engine.should_receive(:client_exists).with(client_id).and_yield true
152
152
  end
153
-
153
+
154
154
  it "does not connect to the engine" do
155
155
  engine.should_not_receive(:connect)
156
156
  server.connect(message) {}
157
157
  end
158
-
158
+
159
159
  it "returns an unsuccessful response" do
160
160
  server.connect(message) do |response|
161
161
  response.should == {
@@ -3,27 +3,27 @@ require "spec_helper"
3
3
  describe "server disconnect" do
4
4
  let(:engine) { mock "engine" }
5
5
  let(:server) { Faye::Server.new }
6
-
6
+
7
7
  before do
8
8
  Faye::Engine.stub(:get).and_return engine
9
9
  end
10
-
10
+
11
11
  describe :disconnect do
12
12
  let(:client_id) { "fakeclientid" }
13
13
  let(:message) {{"channel" => "/meta/disconnect",
14
14
  "clientId" => "fakeclientid"
15
15
  }}
16
-
16
+
17
17
  describe "with valid parameters" do
18
18
  before do
19
19
  engine.should_receive(:client_exists).with(client_id).and_yield true
20
20
  end
21
-
21
+
22
22
  it "destroys the client" do
23
23
  engine.should_receive(:destroy_client).with(client_id)
24
24
  server.disconnect(message) {}
25
25
  end
26
-
26
+
27
27
  it "returns a successful response" do
28
28
  engine.stub(:destroy_client)
29
29
  server.disconnect(message) do |response|
@@ -34,10 +34,10 @@ describe "server disconnect" do
34
34
  }
35
35
  end
36
36
  end
37
-
37
+
38
38
  describe "with a message id" do
39
39
  before { message["id"] = "foo" }
40
-
40
+
41
41
  it "returns the same id" do
42
42
  engine.stub(:destroy_client)
43
43
  server.disconnect(message) do |response|
@@ -51,17 +51,17 @@ describe "server disconnect" do
51
51
  end
52
52
  end
53
53
  end
54
-
54
+
55
55
  describe "with an unknown client" do
56
56
  before do
57
57
  engine.should_receive(:client_exists).with(client_id).and_yield false
58
58
  end
59
-
59
+
60
60
  it "does not destroy the client" do
61
61
  engine.should_not_receive(:destroy_client)
62
62
  server.disconnect(message) {}
63
63
  end
64
-
64
+
65
65
  it "returns an unsuccessful response" do
66
66
  server.disconnect(message) do |response|
67
67
  response.should == {
@@ -72,18 +72,18 @@ describe "server disconnect" do
72
72
  end
73
73
  end
74
74
  end
75
-
75
+
76
76
  describe "missing clientId" do
77
77
  before do
78
78
  message.delete("clientId")
79
79
  engine.should_receive(:client_exists).with(nil).and_yield false
80
80
  end
81
-
81
+
82
82
  it "does not destroy the client" do
83
83
  engine.should_not_receive(:destroy_client)
84
84
  server.disconnect(message) {}
85
85
  end
86
-
86
+
87
87
  it "returns an unsuccessful response" do
88
88
  server.disconnect(message) do |response|
89
89
  response.should == {
@@ -94,18 +94,18 @@ describe "server disconnect" do
94
94
  end
95
95
  end
96
96
  end
97
-
97
+
98
98
  describe "with an error" do
99
99
  before do
100
100
  message["error"] = "invalid"
101
101
  engine.should_receive(:client_exists).with(client_id).and_yield true
102
102
  end
103
-
103
+
104
104
  it "does not destroy the client" do
105
105
  engine.should_not_receive(:destroy_client)
106
106
  server.disconnect(message) {}
107
107
  end
108
-
108
+
109
109
  it "returns an unsuccessful response" do
110
110
  server.disconnect(message) do |response|
111
111
  response.should == {