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
@@ -3,28 +3,28 @@ require "spec_helper"
3
3
  describe "server unsubscribe" 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 :unsubscribe do
12
12
  let(:client_id) { "fakeclientid" }
13
13
  let(:message) {{"channel" => "/meta/unsubscribe",
14
14
  "clientId" => "fakeclientid",
15
15
  "subscription" => "/foo"
16
16
  }}
17
-
17
+
18
18
  describe "with valid parameters" do
19
19
  before do
20
20
  engine.should_receive(:client_exists).with(client_id).and_yield true
21
21
  end
22
-
22
+
23
23
  it "unsubscribes the client from the channel" do
24
24
  engine.should_receive(:unsubscribe).with(client_id, "/foo")
25
25
  server.unsubscribe(message) {}
26
26
  end
27
-
27
+
28
28
  it "returns a successful response" do
29
29
  engine.stub(:unsubscribe)
30
30
  server.unsubscribe(message) do |response|
@@ -36,18 +36,18 @@ describe "server unsubscribe" do
36
36
  }
37
37
  end
38
38
  end
39
-
39
+
40
40
  describe "with a list of subscriptions" do
41
41
  before do
42
42
  message["subscription"] = ["/foo", "/bar"]
43
43
  end
44
-
44
+
45
45
  it "destroys multiple subscriptions" do
46
46
  engine.should_receive(:unsubscribe).with(client_id, "/foo")
47
47
  engine.should_receive(:unsubscribe).with(client_id, "/bar")
48
48
  server.unsubscribe(message) {}
49
49
  end
50
-
50
+
51
51
  it "returns a successful response" do
52
52
  engine.stub(:unsubscribe)
53
53
  server.unsubscribe(message) do |response|
@@ -60,17 +60,17 @@ describe "server unsubscribe" do
60
60
  end
61
61
  end
62
62
  end
63
-
63
+
64
64
  describe "with a subscription pattern" do
65
65
  before do
66
66
  message["subscription"] = "/foo/**"
67
67
  end
68
-
68
+
69
69
  it "destroys the subscription to the channel pattern" do
70
70
  engine.should_receive(:unsubscribe).with(client_id, "/foo/**")
71
71
  server.unsubscribe(message) {}
72
72
  end
73
-
73
+
74
74
  it "returns a successful response" do
75
75
  engine.stub(:unsubscribe)
76
76
  server.unsubscribe(message) do |response|
@@ -84,17 +84,17 @@ describe "server unsubscribe" do
84
84
  end
85
85
  end
86
86
  end
87
-
87
+
88
88
  describe "with an unknown client" do
89
89
  before do
90
90
  engine.should_receive(:client_exists).with(client_id).and_yield false
91
91
  end
92
-
92
+
93
93
  it "does not unsubscribe the client from the channel" do
94
94
  engine.should_not_receive(:unsubscribe)
95
95
  server.unsubscribe(message) {}
96
96
  end
97
-
97
+
98
98
  it "returns an unsuccessful response" do
99
99
  server.unsubscribe(message) do |response|
100
100
  response.should == {
@@ -107,18 +107,18 @@ describe "server unsubscribe" do
107
107
  end
108
108
  end
109
109
  end
110
-
110
+
111
111
  describe "missing clientId" do
112
112
  before do
113
113
  message.delete("clientId")
114
114
  engine.should_receive(:client_exists).with(nil).and_yield false
115
115
  end
116
-
116
+
117
117
  it "does not unsubscribe the client from the channel" do
118
118
  engine.should_not_receive(:unsubscribe)
119
119
  server.unsubscribe(message) {}
120
120
  end
121
-
121
+
122
122
  it "returns an unsuccessful response" do
123
123
  server.unsubscribe(message) do |response|
124
124
  response.should == {
@@ -130,18 +130,18 @@ describe "server unsubscribe" do
130
130
  end
131
131
  end
132
132
  end
133
-
133
+
134
134
  describe "missing subscription" do
135
135
  before do
136
136
  message.delete("subscription")
137
137
  engine.should_receive(:client_exists).with(client_id).and_yield true
138
138
  end
139
-
139
+
140
140
  it "does not unsubscribe the client from the channel" do
141
141
  engine.should_not_receive(:unsubscribe)
142
142
  server.unsubscribe(message) {}
143
143
  end
144
-
144
+
145
145
  it "returns an unsuccessful response" do
146
146
  server.unsubscribe(message) do |response|
147
147
  response.should == {
@@ -154,18 +154,18 @@ describe "server unsubscribe" do
154
154
  end
155
155
  end
156
156
  end
157
-
157
+
158
158
  describe "with an invalid channel" do
159
159
  before do
160
160
  message["subscription"] = "foo"
161
161
  engine.should_receive(:client_exists).with(client_id).and_yield true
162
162
  end
163
-
163
+
164
164
  it "does not unsubscribe the client from the channel" do
165
165
  engine.should_not_receive(:unsubscribe)
166
166
  server.unsubscribe(message) {}
167
167
  end
168
-
168
+
169
169
  it "returns an unsuccessful response" do
170
170
  server.unsubscribe(message) do |response|
171
171
  response.should == {
@@ -178,18 +178,18 @@ describe "server unsubscribe" do
178
178
  end
179
179
  end
180
180
  end
181
-
181
+
182
182
  describe "with a /meta/* channel" do
183
183
  before do
184
184
  message["subscription"] = "/meta/foo"
185
185
  engine.should_receive(:client_exists).with(client_id).and_yield true
186
186
  end
187
-
187
+
188
188
  it "does not unsubscribe the client from the channel" do
189
189
  engine.should_not_receive(:unsubscribe)
190
190
  server.unsubscribe(message) {}
191
191
  end
192
-
192
+
193
193
  it "returns an unsuccessful response" do
194
194
  server.unsubscribe(message) do |response|
195
195
  response.should == {
@@ -201,12 +201,12 @@ describe "server unsubscribe" do
201
201
  }
202
202
  end
203
203
  end
204
-
204
+
205
205
  it "unsubscribes local clients from the channel" do
206
206
  engine.should_receive(:unsubscribe).with(client_id, "/meta/foo")
207
207
  server.unsubscribe(message, true) {}
208
208
  end
209
-
209
+
210
210
  it "returns a successful response for local clients" do
211
211
  engine.stub(:unsubscribe)
212
212
  server.unsubscribe(message, true) do |response|
@@ -219,18 +219,18 @@ describe "server unsubscribe" do
219
219
  end
220
220
  end
221
221
  end
222
-
222
+
223
223
  describe "with an error" do
224
224
  before do
225
225
  message["error"] = "invalid"
226
226
  engine.should_receive(:client_exists).with(client_id).and_yield true
227
227
  end
228
-
228
+
229
229
  it "does not unsubscribe the client from the channel" do
230
230
  engine.should_not_receive(:unsubscribe)
231
231
  server.unsubscribe(message) {}
232
232
  end
233
-
233
+
234
234
  it "returns an unsuccessful response" do
235
235
  server.unsubscribe(message) do |response|
236
236
  response.should == {
@@ -3,11 +3,11 @@ require "spec_helper"
3
3
  describe Faye::Server 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 :process do
12
12
  let(:handshake) {{"channel" => "/meta/handshake", "data" => "handshake" }}
13
13
  let(:connect) {{"channel" => "/meta/connect", "data" => "connect" }}
@@ -15,18 +15,18 @@ describe Faye::Server do
15
15
  let(:subscribe) {{"channel" => "/meta/subscribe", "data" => "subscribe" }}
16
16
  let(:unsubscribe) {{"channel" => "/meta/unsubscribe", "data" => "unsubscribe"}}
17
17
  let(:publish) {{"channel" => "/some/channel", "data" => "publish" }}
18
-
18
+
19
19
  before do
20
20
  engine.stub(:interval).and_return(0)
21
21
  engine.stub(:timeout).and_return(60)
22
22
  end
23
-
23
+
24
24
  it "returns an empty response for no messages" do
25
25
  response = nil
26
26
  server.process([], false) { |r| response = r }
27
27
  response.should == []
28
28
  end
29
-
29
+
30
30
  it "ignores invalid messages" do
31
31
  response = nil
32
32
  server.process([{}, {"channel" => "invalid"}], false) { |r| response = r }
@@ -51,35 +51,35 @@ describe Faye::Server do
51
51
  }
52
52
  ]
53
53
  end
54
-
54
+
55
55
  it "routes single messages to appropriate handlers" do
56
56
  server.should_receive(:handshake).with(handshake, false)
57
57
  server.process(handshake, false) {}
58
58
  end
59
-
59
+
60
60
  it "routes a list of messages to appropriate handlers" do
61
61
  server.should_receive(:handshake).with(handshake, false)
62
62
  server.should_receive(:connect).with(connect, false)
63
63
  server.should_receive(:disconnect).with(disconnect, false)
64
64
  server.should_receive(:subscribe).with(subscribe, false)
65
65
  server.should_receive(:unsubscribe).with(unsubscribe, false)
66
-
66
+
67
67
  engine.should_not_receive(:publish).with(handshake)
68
68
  engine.should_not_receive(:publish).with(connect)
69
69
  engine.should_not_receive(:publish).with(disconnect)
70
70
  engine.should_not_receive(:publish).with(subscribe)
71
71
  engine.should_not_receive(:publish).with(unsubscribe)
72
72
  engine.should_receive(:publish).with(publish)
73
-
73
+
74
74
  server.process([handshake, connect, disconnect, subscribe, unsubscribe, publish], false)
75
75
  end
76
-
76
+
77
77
  describe "handshaking" do
78
78
  before do
79
79
  response = {"channel" => "/meta/handshake", "successful" => true}
80
80
  server.should_receive(:handshake).with(handshake, false).and_yield(response)
81
81
  end
82
-
82
+
83
83
  it "returns the handshake response with advice" do
84
84
  server.process(handshake, false) do |response|
85
85
  response.should == [
@@ -91,28 +91,28 @@ describe Faye::Server do
91
91
  end
92
92
  end
93
93
  end
94
-
94
+
95
95
  describe "connecting for messages" do
96
96
  let(:messages) { [{"channel" => "/a"}, {"channel" => "/b"}] }
97
-
97
+
98
98
  before do
99
99
  server.should_receive(:connect).with(connect, false).and_yield(messages)
100
100
  end
101
-
101
+
102
102
  it "returns the new messages" do
103
103
  server.process(connect, false) { |r| r.should == messages }
104
104
  end
105
105
  end
106
106
  end
107
-
107
+
108
108
  describe :flush_connection do
109
109
  let(:message) {{"clientId" => "fakeclientid"}}
110
-
110
+
111
111
  it "flushes the connection when given one message" do
112
112
  engine.should_receive(:flush).with("fakeclientid")
113
113
  server.flush_connection(message)
114
114
  end
115
-
115
+
116
116
  it "flushes the connection when given a list of messages" do
117
117
  engine.should_receive(:flush).with("fakeclientid")
118
118
  server.flush_connection([message])
@@ -4,77 +4,77 @@ describe Faye::Transport do
4
4
  before do
5
5
  Faye.ensure_reactor_running!
6
6
  end
7
-
7
+
8
8
  let :client do
9
9
  mock("client", :endpoint => "http://example.com/", :endpoints => {}, :transports => {})
10
10
  end
11
-
11
+
12
12
  describe :get do
13
13
  before do
14
14
  Faye::Transport::Local.stub(:usable?).and_yield(false)
15
15
  Faye::Transport::Http.stub(:usable?).and_yield(false)
16
16
  end
17
-
17
+
18
18
  def get_transport(connection_types)
19
19
  transport = nil
20
- Faye::Transport.get(client, connection_types) { |t| transport = t }
20
+ Faye::Transport.get(client, connection_types, []) { |t| transport = t }
21
21
  transport
22
22
  end
23
-
23
+
24
24
  let(:transport) { get_transport ["long-polling", "in-process"] }
25
25
  let(:local_transport) { get_transport ["in-process"] }
26
26
  let(:http_transport) { get_transport ["long-polling"] }
27
-
27
+
28
28
  describe "when no transport is usable" do
29
29
  it "raises an exception" do
30
30
  lambda { transport }.should raise_error
31
31
  end
32
32
  end
33
-
33
+
34
34
  describe "when a less preferred transport is usable" do
35
35
  before do
36
36
  Faye::Transport::Http.stub(:usable?).and_yield(true)
37
37
  end
38
-
38
+
39
39
  it "returns a transport of the usable type" do
40
40
  transport.should be_kind_of(Faye::Transport::Http)
41
41
  end
42
-
42
+
43
43
  it "rasies an exception of the usable type is not requested" do
44
44
  lambda { local_transport }.should raise_error
45
45
  end
46
-
46
+
47
47
  it "allows the usable type to be specifically selected" do
48
48
  http_transport.should be_kind_of(Faye::Transport::Http)
49
49
  end
50
50
  end
51
-
51
+
52
52
  describe "when all transports are usable" do
53
53
  before do
54
54
  Faye::Transport::Local.stub(:usable?).and_yield(true)
55
55
  Faye::Transport::Http.stub(:usable?).and_yield(true)
56
56
  end
57
-
57
+
58
58
  it "returns the most preferred type" do
59
59
  transport.should be_kind_of(Faye::Transport::Local)
60
60
  end
61
-
61
+
62
62
  it "allows types to be specifically selected" do
63
63
  local_transport.should be_kind_of(Faye::Transport::Local)
64
64
  http_transport.should be_kind_of(Faye::Transport::Http)
65
65
  end
66
66
  end
67
67
  end
68
-
68
+
69
69
  describe :send do
70
70
  include EM::RSpec::FakeClock
71
71
  before { clock.stub }
72
72
  after { clock.reset }
73
-
73
+
74
74
  before do
75
75
  client.stub(:client_id).and_return("abc123")
76
76
  end
77
-
77
+
78
78
  describe "for batching transports" do
79
79
  before do
80
80
  transport_klass = Class.new(Faye::Transport) do
@@ -84,39 +84,39 @@ describe Faye::Transport do
84
84
  end
85
85
  @transport = transport_klass.new(client, "")
86
86
  end
87
-
87
+
88
88
  it "does not make an immediate request" do
89
89
  @transport.should_not_receive(:request)
90
90
  @transport.send({"batch" => "me"}, 60)
91
91
  end
92
-
92
+
93
93
  it "queues the message to be sent after a timeout" do
94
94
  @transport.should_receive(:request).with([{"batch" => "me"}], 60)
95
95
  @transport.send({"batch" => "me"}, 60)
96
96
  clock.tick(0.01)
97
97
  end
98
-
98
+
99
99
  it "allows multiple messages to be batched together" do
100
100
  @transport.should_receive(:request).with([{"id" => 1}, {"id" => 2}], 60)
101
101
  @transport.send({"id" => 1}, 60)
102
102
  @transport.send({"id" => 2}, 60)
103
103
  clock.tick(0.01)
104
104
  end
105
-
105
+
106
106
  it "adds advice to connect messages sent with others" do
107
107
  @transport.should_receive(:request).with([{"channel" => "/meta/connect", "advice" => {"timeout" => 0}}, {}], 60)
108
108
  @transport.send({"channel" => "/meta/connect"}, 60)
109
109
  @transport.send({}, 60)
110
110
  clock.tick(0.01)
111
111
  end
112
-
112
+
113
113
  it "adds no advice to connect messages sent alone" do
114
114
  @transport.should_receive(:request).with([{"channel" => "/meta/connect"}], 60)
115
115
  @transport.send({"channel" => "/meta/connect"}, 60)
116
116
  clock.tick(0.01)
117
117
  end
118
118
  end
119
-
119
+
120
120
  describe "for non-batching transports" do
121
121
  before do
122
122
  transport_klass = Class.new(Faye::Transport) do
@@ -126,7 +126,7 @@ describe Faye::Transport do
126
126
  end
127
127
  @transport = transport_klass.new(client, "")
128
128
  end
129
-
129
+
130
130
  it "makes a request immediately" do
131
131
  @transport.should_receive(:request).with([{"no" => "batch"}], 60)
132
132
  @transport.send({"no" => "batch"}, 60)