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,81 @@
1
+ require "spec_helper"
2
+
3
+ describe "server publish" do
4
+ let(:engine) { mock "engine" }
5
+ let(:server) { Faye::Server.new }
6
+ let(:message) {{ "channel" => "/some/channel", "data" => "publish" }}
7
+
8
+ before do
9
+ Faye::Engine.stub(:get).and_return engine
10
+ end
11
+
12
+ describe "publishing a message" do
13
+ it "tells the engine to publish the message" do
14
+ engine.should_receive(:publish).with(message)
15
+ server.process(message, false) {}
16
+ end
17
+
18
+ it "returns a successful response" do
19
+ engine.stub(:publish)
20
+ server.process(message, false) do |response|
21
+ response.should == [
22
+ { "channel" => "/some/channel",
23
+ "successful" => true
24
+ }
25
+ ]
26
+ end
27
+ end
28
+
29
+ describe "with an invalid channel" do
30
+ before { message["channel"] = "channel" }
31
+
32
+ it "does not tell the engine to publish the message" do
33
+ engine.should_not_receive(:publish)
34
+ server.process(message, false) {}
35
+ end
36
+
37
+ it "returns an unsuccessful response" do
38
+ engine.stub(:publish)
39
+ server.process(message, false) do |response|
40
+ response.should == [
41
+ { "channel" => "channel",
42
+ "successful" => false,
43
+ "error" => "405:channel:Invalid channel"
44
+ }
45
+ ]
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "with an error" do
51
+ before { message["error"] = "invalid" }
52
+
53
+ it "does not tell the engine to publish the message" do
54
+ engine.should_not_receive(:publish)
55
+ server.process(message, false) {}
56
+ end
57
+
58
+ it "returns an unsuccessful response" do
59
+ engine.stub(:publish)
60
+ server.process(message, false) do |response|
61
+ response.should == [
62
+ { "channel" => "/some/channel",
63
+ "successful" => false,
64
+ "error" => "invalid"
65
+ }
66
+ ]
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "to an invalid channel" do
72
+ before { message["channel"] = "/invalid/*" }
73
+
74
+ it "does not tell the engine to publish the message" do
75
+ engine.should_not_receive(:publish)
76
+ server.process(message, false) {}
77
+ end
78
+ end
79
+ end
80
+ end
81
+
@@ -0,0 +1,247 @@
1
+ require "spec_helper"
2
+
3
+ describe "server subscribe" do
4
+ let(:engine) { mock "engine" }
5
+ let(:server) { Faye::Server.new }
6
+
7
+ before do
8
+ Faye::Engine.stub(:get).and_return engine
9
+ end
10
+
11
+ describe :subscribe do
12
+ let(:client_id) { "fakeclientid" }
13
+ let(:message) {{"channel" => "/meta/subscribe",
14
+ "clientId" => "fakeclientid",
15
+ "subscription" => "/foo"
16
+ }}
17
+
18
+ describe "with valid parameters" do
19
+ before do
20
+ engine.should_receive(:client_exists).with(client_id).and_yield true
21
+ end
22
+
23
+ it "subscribes the client to the channel" do
24
+ engine.should_receive(:subscribe).with(client_id, "/foo")
25
+ server.subscribe(message) {}
26
+ end
27
+
28
+ it "returns a successful response" do
29
+ engine.stub(:subscribe)
30
+ server.subscribe(message) do |response|
31
+ response.should == {
32
+ "channel" => "/meta/subscribe",
33
+ "successful" => true,
34
+ "clientId" => client_id,
35
+ "subscription" => "/foo"
36
+ }
37
+ end
38
+ end
39
+
40
+ describe "with a list of subscriptions" do
41
+ before do
42
+ message["subscription"] = ["/foo", "/bar"]
43
+ end
44
+
45
+ it "creates multiple subscriptions" do
46
+ engine.should_receive(:subscribe).with(client_id, "/foo")
47
+ engine.should_receive(:subscribe).with(client_id, "/bar")
48
+ server.subscribe(message) {}
49
+ end
50
+
51
+ it "returns a successful response" do
52
+ engine.stub(:subscribe)
53
+ server.subscribe(message) do |response|
54
+ response.should == {
55
+ "channel" => "/meta/subscribe",
56
+ "successful" => true,
57
+ "clientId" => client_id,
58
+ "subscription" => ["/foo", "/bar"]
59
+ }
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "with a subscription pattern" do
65
+ before do
66
+ message["subscription"] = "/foo/**"
67
+ end
68
+
69
+ it "subscribes the client to the channel pattern" do
70
+ engine.should_receive(:subscribe).with(client_id, "/foo/**")
71
+ server.subscribe(message) {}
72
+ end
73
+
74
+ it "returns a successful response" do
75
+ engine.stub(:subscribe)
76
+ server.subscribe(message) do |response|
77
+ response.should == {
78
+ "channel" => "/meta/subscribe",
79
+ "successful" => true,
80
+ "clientId" => client_id,
81
+ "subscription" => "/foo/**"
82
+ }
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ describe "with an unknown client" do
89
+ before do
90
+ engine.should_receive(:client_exists).with(client_id).and_yield false
91
+ end
92
+
93
+ it "does not subscribe the client to the channel" do
94
+ engine.should_not_receive(:subscribe)
95
+ server.subscribe(message) {}
96
+ end
97
+
98
+ it "returns an unsuccessful response" do
99
+ server.subscribe(message) do |response|
100
+ response.should == {
101
+ "channel" => "/meta/subscribe",
102
+ "successful" => false,
103
+ "error" => "401:fakeclientid:Unknown client",
104
+ "clientId" => client_id,
105
+ "subscription" => "/foo"
106
+ }
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "missing clientId" do
112
+ before do
113
+ message.delete("clientId")
114
+ engine.should_receive(:client_exists).with(nil).and_yield false
115
+ end
116
+
117
+ it "does not subscribe the client to the channel" do
118
+ engine.should_not_receive(:subscribe)
119
+ server.subscribe(message) {}
120
+ end
121
+
122
+ it "returns an unsuccessful response" do
123
+ server.subscribe(message) do |response|
124
+ response.should == {
125
+ "channel" => "/meta/subscribe",
126
+ "successful" => false,
127
+ "error" => "402:clientId:Missing required parameter",
128
+ "subscription" => "/foo"
129
+ }
130
+ end
131
+ end
132
+ end
133
+
134
+ describe "missing subscription" do
135
+ before do
136
+ message.delete("subscription")
137
+ engine.should_receive(:client_exists).with(client_id).and_yield true
138
+ end
139
+
140
+ it "does not subscribe the client to the channel" do
141
+ engine.should_not_receive(:subscribe)
142
+ server.subscribe(message) {}
143
+ end
144
+
145
+ it "returns an unsuccessful response" do
146
+ server.subscribe(message) do |response|
147
+ response.should == {
148
+ "channel" => "/meta/subscribe",
149
+ "successful" => false,
150
+ "error" => "402:subscription:Missing required parameter",
151
+ "clientId" => client_id,
152
+ "subscription" => []
153
+ }
154
+ end
155
+ end
156
+ end
157
+
158
+ describe "with an invalid channel" do
159
+ before do
160
+ message["subscription"] = "foo"
161
+ engine.should_receive(:client_exists).with(client_id).and_yield true
162
+ end
163
+
164
+ it "does not subscribe the client to the channel" do
165
+ engine.should_not_receive(:subscribe)
166
+ server.subscribe(message) {}
167
+ end
168
+
169
+ it "returns an unsuccessful response" do
170
+ server.subscribe(message) do |response|
171
+ response.should == {
172
+ "channel" => "/meta/subscribe",
173
+ "successful" => false,
174
+ "error" => "405:foo:Invalid channel",
175
+ "clientId" => client_id,
176
+ "subscription" => "foo"
177
+ }
178
+ end
179
+ end
180
+ end
181
+
182
+ describe "with a /meta/* channel" do
183
+ before do
184
+ message["subscription"] = "/meta/foo"
185
+ engine.should_receive(:client_exists).with(client_id).and_yield true
186
+ end
187
+
188
+ it "does not subscribe the client to the channel" do
189
+ engine.should_not_receive(:subscribe)
190
+ server.subscribe(message) {}
191
+ end
192
+
193
+ it "returns an unsuccessful response" do
194
+ server.subscribe(message) do |response|
195
+ response.should == {
196
+ "channel" => "/meta/subscribe",
197
+ "successful" => false,
198
+ "error" => "403:/meta/foo:Forbidden channel",
199
+ "clientId" => client_id,
200
+ "subscription" => "/meta/foo"
201
+ }
202
+ end
203
+ end
204
+
205
+ it "subscribes local clients to the channel" do
206
+ engine.should_receive(:subscribe).with(client_id, "/meta/foo")
207
+ server.subscribe(message, true) {}
208
+ end
209
+
210
+ it "returns a successful response for local clients" do
211
+ engine.stub(:subscribe)
212
+ server.subscribe(message, true) do |response|
213
+ response.should == {
214
+ "channel" => "/meta/subscribe",
215
+ "successful" => true,
216
+ "clientId" => client_id,
217
+ "subscription" => "/meta/foo"
218
+ }
219
+ end
220
+ end
221
+ end
222
+
223
+ describe "with an error" do
224
+ before do
225
+ message["error"] = "invalid"
226
+ engine.should_receive(:client_exists).with(client_id).and_yield true
227
+ end
228
+
229
+ it "does not subscribe the client to the channel" do
230
+ engine.should_not_receive(:subscribe)
231
+ server.subscribe(message) {}
232
+ end
233
+
234
+ it "returns an unsuccessful response" do
235
+ server.subscribe(message) do |response|
236
+ response.should == {
237
+ "channel" => "/meta/subscribe",
238
+ "successful" => false,
239
+ "error" => "invalid",
240
+ "clientId" => client_id,
241
+ "subscription" => "/foo"
242
+ }
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end
@@ -0,0 +1,247 @@
1
+ require "spec_helper"
2
+
3
+ describe "server unsubscribe" do
4
+ let(:engine) { mock "engine" }
5
+ let(:server) { Faye::Server.new }
6
+
7
+ before do
8
+ Faye::Engine.stub(:get).and_return engine
9
+ end
10
+
11
+ describe :unsubscribe do
12
+ let(:client_id) { "fakeclientid" }
13
+ let(:message) {{"channel" => "/meta/unsubscribe",
14
+ "clientId" => "fakeclientid",
15
+ "subscription" => "/foo"
16
+ }}
17
+
18
+ describe "with valid parameters" do
19
+ before do
20
+ engine.should_receive(:client_exists).with(client_id).and_yield true
21
+ end
22
+
23
+ it "unsubscribes the client from the channel" do
24
+ engine.should_receive(:unsubscribe).with(client_id, "/foo")
25
+ server.unsubscribe(message) {}
26
+ end
27
+
28
+ it "returns a successful response" do
29
+ engine.stub(:unsubscribe)
30
+ server.unsubscribe(message) do |response|
31
+ response.should == {
32
+ "channel" => "/meta/unsubscribe",
33
+ "successful" => true,
34
+ "clientId" => client_id,
35
+ "subscription" => "/foo"
36
+ }
37
+ end
38
+ end
39
+
40
+ describe "with a list of subscriptions" do
41
+ before do
42
+ message["subscription"] = ["/foo", "/bar"]
43
+ end
44
+
45
+ it "destroys multiple subscriptions" do
46
+ engine.should_receive(:unsubscribe).with(client_id, "/foo")
47
+ engine.should_receive(:unsubscribe).with(client_id, "/bar")
48
+ server.unsubscribe(message) {}
49
+ end
50
+
51
+ it "returns a successful response" do
52
+ engine.stub(:unsubscribe)
53
+ server.unsubscribe(message) do |response|
54
+ response.should == {
55
+ "channel" => "/meta/unsubscribe",
56
+ "successful" => true,
57
+ "clientId" => client_id,
58
+ "subscription" => ["/foo", "/bar"]
59
+ }
60
+ end
61
+ end
62
+ end
63
+
64
+ describe "with a subscription pattern" do
65
+ before do
66
+ message["subscription"] = "/foo/**"
67
+ end
68
+
69
+ it "destroys the subscription to the channel pattern" do
70
+ engine.should_receive(:unsubscribe).with(client_id, "/foo/**")
71
+ server.unsubscribe(message) {}
72
+ end
73
+
74
+ it "returns a successful response" do
75
+ engine.stub(:unsubscribe)
76
+ server.unsubscribe(message) do |response|
77
+ response.should == {
78
+ "channel" => "/meta/unsubscribe",
79
+ "successful" => true,
80
+ "clientId" => client_id,
81
+ "subscription" => "/foo/**"
82
+ }
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ describe "with an unknown client" do
89
+ before do
90
+ engine.should_receive(:client_exists).with(client_id).and_yield false
91
+ end
92
+
93
+ it "does not unsubscribe the client from the channel" do
94
+ engine.should_not_receive(:unsubscribe)
95
+ server.unsubscribe(message) {}
96
+ end
97
+
98
+ it "returns an unsuccessful response" do
99
+ server.unsubscribe(message) do |response|
100
+ response.should == {
101
+ "channel" => "/meta/unsubscribe",
102
+ "successful" => false,
103
+ "error" => "401:fakeclientid:Unknown client",
104
+ "clientId" => client_id,
105
+ "subscription" => "/foo"
106
+ }
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "missing clientId" do
112
+ before do
113
+ message.delete("clientId")
114
+ engine.should_receive(:client_exists).with(nil).and_yield false
115
+ end
116
+
117
+ it "does not unsubscribe the client from the channel" do
118
+ engine.should_not_receive(:unsubscribe)
119
+ server.unsubscribe(message) {}
120
+ end
121
+
122
+ it "returns an unsuccessful response" do
123
+ server.unsubscribe(message) do |response|
124
+ response.should == {
125
+ "channel" => "/meta/unsubscribe",
126
+ "successful" => false,
127
+ "error" => "402:clientId:Missing required parameter",
128
+ "subscription" => "/foo"
129
+ }
130
+ end
131
+ end
132
+ end
133
+
134
+ describe "missing subscription" do
135
+ before do
136
+ message.delete("subscription")
137
+ engine.should_receive(:client_exists).with(client_id).and_yield true
138
+ end
139
+
140
+ it "does not unsubscribe the client from the channel" do
141
+ engine.should_not_receive(:unsubscribe)
142
+ server.unsubscribe(message) {}
143
+ end
144
+
145
+ it "returns an unsuccessful response" do
146
+ server.unsubscribe(message) do |response|
147
+ response.should == {
148
+ "channel" => "/meta/unsubscribe",
149
+ "successful" => false,
150
+ "error" => "402:subscription:Missing required parameter",
151
+ "clientId" => client_id,
152
+ "subscription" => []
153
+ }
154
+ end
155
+ end
156
+ end
157
+
158
+ describe "with an invalid channel" do
159
+ before do
160
+ message["subscription"] = "foo"
161
+ engine.should_receive(:client_exists).with(client_id).and_yield true
162
+ end
163
+
164
+ it "does not unsubscribe the client from the channel" do
165
+ engine.should_not_receive(:unsubscribe)
166
+ server.unsubscribe(message) {}
167
+ end
168
+
169
+ it "returns an unsuccessful response" do
170
+ server.unsubscribe(message) do |response|
171
+ response.should == {
172
+ "channel" => "/meta/unsubscribe",
173
+ "successful" => false,
174
+ "error" => "405:foo:Invalid channel",
175
+ "clientId" => client_id,
176
+ "subscription" => "foo"
177
+ }
178
+ end
179
+ end
180
+ end
181
+
182
+ describe "with a /meta/* channel" do
183
+ before do
184
+ message["subscription"] = "/meta/foo"
185
+ engine.should_receive(:client_exists).with(client_id).and_yield true
186
+ end
187
+
188
+ it "does not unsubscribe the client from the channel" do
189
+ engine.should_not_receive(:unsubscribe)
190
+ server.unsubscribe(message) {}
191
+ end
192
+
193
+ it "returns an unsuccessful response" do
194
+ server.unsubscribe(message) do |response|
195
+ response.should == {
196
+ "channel" => "/meta/unsubscribe",
197
+ "successful" => false,
198
+ "error" => "403:/meta/foo:Forbidden channel",
199
+ "clientId" => client_id,
200
+ "subscription" => "/meta/foo"
201
+ }
202
+ end
203
+ end
204
+
205
+ it "unsubscribes local clients from the channel" do
206
+ engine.should_receive(:unsubscribe).with(client_id, "/meta/foo")
207
+ server.unsubscribe(message, true) {}
208
+ end
209
+
210
+ it "returns a successful response for local clients" do
211
+ engine.stub(:unsubscribe)
212
+ server.unsubscribe(message, true) do |response|
213
+ response.should == {
214
+ "channel" => "/meta/unsubscribe",
215
+ "successful" => true,
216
+ "clientId" => client_id,
217
+ "subscription" => "/meta/foo"
218
+ }
219
+ end
220
+ end
221
+ end
222
+
223
+ describe "with an error" do
224
+ before do
225
+ message["error"] = "invalid"
226
+ engine.should_receive(:client_exists).with(client_id).and_yield true
227
+ end
228
+
229
+ it "does not unsubscribe the client from the channel" do
230
+ engine.should_not_receive(:unsubscribe)
231
+ server.unsubscribe(message) {}
232
+ end
233
+
234
+ it "returns an unsuccessful response" do
235
+ server.unsubscribe(message) do |response|
236
+ response.should == {
237
+ "channel" => "/meta/unsubscribe",
238
+ "successful" => false,
239
+ "error" => "invalid",
240
+ "clientId" => client_id,
241
+ "subscription" => "/foo"
242
+ }
243
+ end
244
+ end
245
+ end
246
+ end
247
+ end