pusher-fake 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pusher-fake/server/chain_trap_handlers.rb +24 -0
- data/lib/pusher-fake/server.rb +10 -0
- data/lib/pusher-fake.rb +1 -1
- metadata +20 -81
- data/spec/features/api/channels_spec.rb +0 -86
- data/spec/features/api/users_spec.rb +0 -36
- data/spec/features/client/connect_spec.rb +0 -11
- data/spec/features/client/event_spec.rb +0 -49
- data/spec/features/client/presence_spec.rb +0 -58
- data/spec/features/client/subscribe_spec.rb +0 -84
- data/spec/features/server/event_spec.rb +0 -122
- data/spec/features/server/webhooks_spec.rb +0 -107
- data/spec/lib/pusher-fake/channel/presence_spec.rb +0 -249
- data/spec/lib/pusher-fake/channel/private_spec.rb +0 -180
- data/spec/lib/pusher-fake/channel/public_spec.rb +0 -206
- data/spec/lib/pusher-fake/channel_spec.rb +0 -122
- data/spec/lib/pusher-fake/configuration_spec.rb +0 -123
- data/spec/lib/pusher-fake/connection_spec.rb +0 -332
- data/spec/lib/pusher-fake/server/application_spec.rb +0 -604
- data/spec/lib/pusher-fake/server_spec.rb +0 -177
- data/spec/lib/pusher-fake/webhook_spec.rb +0 -67
- data/spec/lib/pusher_fake_spec.rb +0 -96
- data/spec/spec_helper.rb +0 -31
- data/spec/support/application/public/javascripts/vendor/polyfill.min.js +0 -1
- data/spec/support/application/public/javascripts/vendor/pusher-7.0.6.js +0 -4567
- data/spec/support/application/views/index.erb +0 -91
- data/spec/support/application.rb +0 -35
- data/spec/support/capybara.rb +0 -10
- data/spec/support/helpers/connect.rb +0 -21
- data/spec/support/helpers/event.rb +0 -11
- data/spec/support/helpers/subscription.rb +0 -31
- data/spec/support/helpers/user.rb +0 -13
- data/spec/support/matchers/have_configuration_option.rb +0 -19
- data/spec/support/pusher_fake.rb +0 -21
- data/spec/support/webhooks.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz: '
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '05043028e1837c87118d83e74496c9189036a69f170bf71c15e9e6c452af7565'
|
4
|
+
data.tar.gz: bdefba87a3ff23c7e4ec13b14d852b2c27dd0d7daeb202708ac0d1767ae9d5e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d47d6a29b94b3a95fe5d0023a4d3d577e1160a2aa357884f617998778c5a5ba8a4a5353a40de7a709d044f5d3324e31448d53c6c06bbc9917f3e449e37f5c3f5
|
7
|
+
data.tar.gz: cde630c89000bc96b0d56f700f4a2f0568e9e410fc5d445f906bbfc22acd9fec559a171ae9fee388606bdd94406328be04a2136073d2f546dd3bfadd1e367384
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# :nocov:
|
4
|
+
module PusherFake
|
5
|
+
module Server
|
6
|
+
# Monkeypatch to ensure previous trap handlers are called when new handlers
|
7
|
+
# are added.
|
8
|
+
#
|
9
|
+
# @see +PusherFake::Server.chain_trap_handlers+
|
10
|
+
module ChainTrapHandlers
|
11
|
+
# Ensure a previous trap is chained when a new trap is added.
|
12
|
+
#
|
13
|
+
# @see +Signal.trap+
|
14
|
+
def trap(*arguments)
|
15
|
+
previous_trap = super do
|
16
|
+
yield
|
17
|
+
|
18
|
+
previous_trap&.call
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
# :nocov:
|
data/lib/pusher-fake/server.rb
CHANGED
@@ -4,6 +4,7 @@ module PusherFake
|
|
4
4
|
# Socket and web server manager.
|
5
5
|
module Server
|
6
6
|
autoload :Application, "pusher-fake/server/application"
|
7
|
+
autoload :ChainTrapHandlers, "pusher-fake/server/chain_trap_handlers"
|
7
8
|
|
8
9
|
class << self
|
9
10
|
# Start the servers.
|
@@ -11,6 +12,8 @@ module PusherFake
|
|
11
12
|
# @see start_socket_server
|
12
13
|
# @see start_web_server
|
13
14
|
def start
|
15
|
+
chain_trap_handlers
|
16
|
+
|
14
17
|
EventMachine.run do
|
15
18
|
start_web_server
|
16
19
|
start_socket_server
|
@@ -48,6 +51,13 @@ module PusherFake
|
|
48
51
|
|
49
52
|
private
|
50
53
|
|
54
|
+
# Force +Thin::Server+ and +EventMachine::WebSocket+ to call the chain of
|
55
|
+
# trap handlers to ensure other handles, such as +RSpec+, can interrupt.
|
56
|
+
def chain_trap_handlers
|
57
|
+
EventMachine::WebSocket.singleton_class.prepend(ChainTrapHandlers)
|
58
|
+
Thin::Server.prepend(ChainTrapHandlers)
|
59
|
+
end
|
60
|
+
|
51
61
|
# Convenience method for access the configuration object.
|
52
62
|
#
|
53
63
|
# @return [Configuration] The configuration object.
|
data/lib/pusher-fake.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pusher-fake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tristan Dunn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-http-request
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1
|
61
|
+
version: '1'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1
|
68
|
+
version: '1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: capybara
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - '='
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 3.
|
75
|
+
version: 3.37.1
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - '='
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
82
|
+
version: 3.37.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: puma
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,28 +142,28 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: 1.
|
145
|
+
version: 1.32.0
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - '='
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: 1.
|
152
|
+
version: 1.32.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rubocop-performance
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - '='
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 1.
|
159
|
+
version: 1.14.3
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - '='
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 1.
|
166
|
+
version: 1.14.3
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rubocop-rake
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,56 +184,56 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - '='
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: 2.
|
187
|
+
version: 2.12.1
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - '='
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: 2.
|
194
|
+
version: 2.12.1
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: selenium-webdriver
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
199
|
- - '='
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: 4.
|
201
|
+
version: 4.3.0
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
206
|
- - '='
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: 4.
|
208
|
+
version: 4.3.0
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: sinatra
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
213
|
- - '='
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version: 2.2.
|
215
|
+
version: 2.2.2
|
216
216
|
type: :development
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
220
|
- - '='
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version: 2.2.
|
222
|
+
version: 2.2.2
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
224
|
name: yard
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
226
226
|
requirements:
|
227
227
|
- - '='
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version: 0.9.
|
229
|
+
version: 0.9.28
|
230
230
|
type: :development
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
234
|
- - '='
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: 0.9.
|
236
|
+
version: 0.9.28
|
237
237
|
description: A fake Pusher server for development and testing.
|
238
238
|
email: hello@tristandunn.com
|
239
239
|
executables:
|
@@ -251,41 +251,11 @@ files:
|
|
251
251
|
- lib/pusher-fake/connection.rb
|
252
252
|
- lib/pusher-fake/server.rb
|
253
253
|
- lib/pusher-fake/server/application.rb
|
254
|
+
- lib/pusher-fake/server/chain_trap_handlers.rb
|
254
255
|
- lib/pusher-fake/support/base.rb
|
255
256
|
- lib/pusher-fake/support/cucumber.rb
|
256
257
|
- lib/pusher-fake/support/rspec.rb
|
257
258
|
- lib/pusher-fake/webhook.rb
|
258
|
-
- spec/features/api/channels_spec.rb
|
259
|
-
- spec/features/api/users_spec.rb
|
260
|
-
- spec/features/client/connect_spec.rb
|
261
|
-
- spec/features/client/event_spec.rb
|
262
|
-
- spec/features/client/presence_spec.rb
|
263
|
-
- spec/features/client/subscribe_spec.rb
|
264
|
-
- spec/features/server/event_spec.rb
|
265
|
-
- spec/features/server/webhooks_spec.rb
|
266
|
-
- spec/lib/pusher-fake/channel/presence_spec.rb
|
267
|
-
- spec/lib/pusher-fake/channel/private_spec.rb
|
268
|
-
- spec/lib/pusher-fake/channel/public_spec.rb
|
269
|
-
- spec/lib/pusher-fake/channel_spec.rb
|
270
|
-
- spec/lib/pusher-fake/configuration_spec.rb
|
271
|
-
- spec/lib/pusher-fake/connection_spec.rb
|
272
|
-
- spec/lib/pusher-fake/server/application_spec.rb
|
273
|
-
- spec/lib/pusher-fake/server_spec.rb
|
274
|
-
- spec/lib/pusher-fake/webhook_spec.rb
|
275
|
-
- spec/lib/pusher_fake_spec.rb
|
276
|
-
- spec/spec_helper.rb
|
277
|
-
- spec/support/application.rb
|
278
|
-
- spec/support/application/public/javascripts/vendor/polyfill.min.js
|
279
|
-
- spec/support/application/public/javascripts/vendor/pusher-7.0.6.js
|
280
|
-
- spec/support/application/views/index.erb
|
281
|
-
- spec/support/capybara.rb
|
282
|
-
- spec/support/helpers/connect.rb
|
283
|
-
- spec/support/helpers/event.rb
|
284
|
-
- spec/support/helpers/subscription.rb
|
285
|
-
- spec/support/helpers/user.rb
|
286
|
-
- spec/support/matchers/have_configuration_option.rb
|
287
|
-
- spec/support/pusher_fake.rb
|
288
|
-
- spec/support/webhooks.rb
|
289
259
|
homepage: https://github.com/tristandunn/pusher-fake
|
290
260
|
licenses:
|
291
261
|
- MIT
|
@@ -310,35 +280,4 @@ rubygems_version: 3.3.7
|
|
310
280
|
signing_key:
|
311
281
|
specification_version: 4
|
312
282
|
summary: A fake Pusher server for development and testing.
|
313
|
-
test_files:
|
314
|
-
- spec/features/api/channels_spec.rb
|
315
|
-
- spec/features/api/users_spec.rb
|
316
|
-
- spec/features/client/connect_spec.rb
|
317
|
-
- spec/features/client/event_spec.rb
|
318
|
-
- spec/features/client/presence_spec.rb
|
319
|
-
- spec/features/client/subscribe_spec.rb
|
320
|
-
- spec/features/server/event_spec.rb
|
321
|
-
- spec/features/server/webhooks_spec.rb
|
322
|
-
- spec/lib/pusher-fake/channel/presence_spec.rb
|
323
|
-
- spec/lib/pusher-fake/channel/private_spec.rb
|
324
|
-
- spec/lib/pusher-fake/channel/public_spec.rb
|
325
|
-
- spec/lib/pusher-fake/channel_spec.rb
|
326
|
-
- spec/lib/pusher-fake/configuration_spec.rb
|
327
|
-
- spec/lib/pusher-fake/connection_spec.rb
|
328
|
-
- spec/lib/pusher-fake/server/application_spec.rb
|
329
|
-
- spec/lib/pusher-fake/server_spec.rb
|
330
|
-
- spec/lib/pusher-fake/webhook_spec.rb
|
331
|
-
- spec/lib/pusher_fake_spec.rb
|
332
|
-
- spec/spec_helper.rb
|
333
|
-
- spec/support/application/public/javascripts/vendor/polyfill.min.js
|
334
|
-
- spec/support/application/public/javascripts/vendor/pusher-7.0.6.js
|
335
|
-
- spec/support/application/views/index.erb
|
336
|
-
- spec/support/application.rb
|
337
|
-
- spec/support/capybara.rb
|
338
|
-
- spec/support/helpers/connect.rb
|
339
|
-
- spec/support/helpers/event.rb
|
340
|
-
- spec/support/helpers/subscription.rb
|
341
|
-
- spec/support/helpers/user.rb
|
342
|
-
- spec/support/matchers/have_configuration_option.rb
|
343
|
-
- spec/support/pusher_fake.rb
|
344
|
-
- spec/support/webhooks.rb
|
283
|
+
test_files: []
|
@@ -1,86 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
feature "Requesting channel API endpoint" do
|
6
|
-
let(:channel_name) { "public-1" }
|
7
|
-
let(:presence_name) { "presence-example" }
|
8
|
-
|
9
|
-
before do
|
10
|
-
connect
|
11
|
-
end
|
12
|
-
|
13
|
-
scenario "all channels, with none created" do
|
14
|
-
expect(channels).to be_empty
|
15
|
-
end
|
16
|
-
|
17
|
-
scenario "all channels, with one created" do
|
18
|
-
subscribe_to(channel_name)
|
19
|
-
|
20
|
-
expect(channels).to have_key(channel_name)
|
21
|
-
end
|
22
|
-
|
23
|
-
scenario "all channels, with a filter" do
|
24
|
-
subscribe_to("other")
|
25
|
-
subscribe_to(channel_name)
|
26
|
-
|
27
|
-
result = channels(filter_by_prefix: "pu")
|
28
|
-
|
29
|
-
expect(result.size).to eq(1)
|
30
|
-
expect(result).to have_key(channel_name)
|
31
|
-
end
|
32
|
-
|
33
|
-
scenario "all channels, with info attributes" do
|
34
|
-
subscribe_to(presence_name)
|
35
|
-
|
36
|
-
result = channels(filter_by_prefix: "presence-", info: "user_count")
|
37
|
-
|
38
|
-
expect(result.size).to eq(1)
|
39
|
-
expect(result).to have_key(presence_name)
|
40
|
-
expect(result[presence_name]).to have_key("user_count")
|
41
|
-
expect(result[presence_name]["user_count"]).to eq(1)
|
42
|
-
end
|
43
|
-
|
44
|
-
scenario "all channels, with invalid info attributes" do
|
45
|
-
expect do
|
46
|
-
channels(info: "user_count")
|
47
|
-
end.to raise_error(/user_count may only be requested for presence channels/)
|
48
|
-
end
|
49
|
-
|
50
|
-
scenario "channel, with no occupants" do
|
51
|
-
expect(channel[:occupied]).to be(false)
|
52
|
-
end
|
53
|
-
|
54
|
-
scenario "channel, with an occupant" do
|
55
|
-
subscribe_to(channel_name)
|
56
|
-
|
57
|
-
expect(channel[:occupied]).to be(true)
|
58
|
-
end
|
59
|
-
|
60
|
-
scenario "channel, with info attributes" do
|
61
|
-
subscribe_to(presence_name)
|
62
|
-
|
63
|
-
result = Pusher.get("/channels/#{presence_name}", info: "user_count")
|
64
|
-
|
65
|
-
expect(result[:occupied]).to be(true)
|
66
|
-
expect(result[:user_count]).to eq(1)
|
67
|
-
end
|
68
|
-
|
69
|
-
scenario "channel, with invalid info attributes" do
|
70
|
-
expect do
|
71
|
-
channel(info: "user_count")
|
72
|
-
end.to raise_error(
|
73
|
-
/Cannot retrieve the user count unless the channel is a presence channel/
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
protected
|
78
|
-
|
79
|
-
def channel(options = {})
|
80
|
-
Pusher.get("/channels/#{channel_name}", options)
|
81
|
-
end
|
82
|
-
|
83
|
-
def channels(options = {})
|
84
|
-
Pusher.get("/channels", options)[:channels]
|
85
|
-
end
|
86
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
feature "Requesting user API endpoint" do
|
6
|
-
let(:users) { Pusher.get("/channels/#{channel_name}/users")[:users] }
|
7
|
-
let(:channel_name) { "public-1" }
|
8
|
-
|
9
|
-
before do
|
10
|
-
connect
|
11
|
-
connect_as "Bob"
|
12
|
-
end
|
13
|
-
|
14
|
-
scenario "with no users subscribed" do
|
15
|
-
expect(users).to be_empty
|
16
|
-
end
|
17
|
-
|
18
|
-
scenario "with a single user subscribed" do
|
19
|
-
subscribe_to(channel_name)
|
20
|
-
|
21
|
-
expect(users.size).to eq(1)
|
22
|
-
end
|
23
|
-
|
24
|
-
scenario "with a multiple users subscribed" do
|
25
|
-
subscribe_to(channel_name)
|
26
|
-
subscribe_to_as(channel_name, "Bob")
|
27
|
-
|
28
|
-
ids = PusherFake::Channel.channels[channel_name].connections.map(&:id)
|
29
|
-
|
30
|
-
expect(users.size).to eq(2)
|
31
|
-
|
32
|
-
users.each do |user|
|
33
|
-
expect(ids).to include(user["id"])
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
feature "Client triggers a client event" do
|
6
|
-
let(:event) { "client-message" }
|
7
|
-
let(:other_user) { "Bob" }
|
8
|
-
let(:public_channel) { "chat" }
|
9
|
-
let(:private_channel) { "private-chat" }
|
10
|
-
|
11
|
-
before do
|
12
|
-
connect
|
13
|
-
connect_as(other_user)
|
14
|
-
end
|
15
|
-
|
16
|
-
scenario "on a subscribed private channel" do
|
17
|
-
subscribe_to(private_channel)
|
18
|
-
subscribe_to_as(private_channel, other_user)
|
19
|
-
|
20
|
-
trigger(private_channel, event)
|
21
|
-
|
22
|
-
expect(page).not_to have_event(event, on: private_channel)
|
23
|
-
|
24
|
-
using_session(other_user) do
|
25
|
-
expect(page).to have_event(event, on: private_channel)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
scenario "on a subscribed public channel" do
|
30
|
-
subscribe_to(public_channel)
|
31
|
-
subscribe_to_as(public_channel, other_user)
|
32
|
-
|
33
|
-
trigger(public_channel, event)
|
34
|
-
|
35
|
-
expect(page).not_to have_event(event, on: public_channel)
|
36
|
-
|
37
|
-
using_session(other_user) do
|
38
|
-
expect(page).not_to have_event(event, on: public_channel)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
protected
|
43
|
-
|
44
|
-
def trigger(channel, event)
|
45
|
-
page.execute_script(
|
46
|
-
"Helpers.trigger(#{MultiJson.dump(channel)}, #{MultiJson.dump(event)})"
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
feature "Client on a presence channel" do
|
6
|
-
let(:other_user) { "Bob" }
|
7
|
-
|
8
|
-
before do
|
9
|
-
connect
|
10
|
-
end
|
11
|
-
|
12
|
-
scenario "subscribing to a presence channel" do
|
13
|
-
subscribe_to("presence-game-1")
|
14
|
-
|
15
|
-
expect(page).to have_clients(1, in: "presence-game-1")
|
16
|
-
end
|
17
|
-
|
18
|
-
scenario "subscribing to a presence channel, with existing users" do
|
19
|
-
connect_as(other_user, channel: "presence-game-1")
|
20
|
-
|
21
|
-
subscribe_to("presence-game-1")
|
22
|
-
|
23
|
-
expect(page).to have_clients(2, in: "presence-game-1", named: "Alan Turing")
|
24
|
-
end
|
25
|
-
|
26
|
-
scenario "member entering notification" do
|
27
|
-
subscribe_to("presence-game-1")
|
28
|
-
|
29
|
-
connect_as(other_user, channel: "presence-game-1")
|
30
|
-
|
31
|
-
expect(page).to have_clients(2, in: "presence-game-1")
|
32
|
-
end
|
33
|
-
|
34
|
-
scenario "member leaving notification" do
|
35
|
-
connect_as(other_user, channel: "presence-game-1")
|
36
|
-
subscribe_to("presence-game-1")
|
37
|
-
|
38
|
-
expect(page).to have_clients(2, in: "presence-game-1")
|
39
|
-
|
40
|
-
unsubscribe_from_as("presence-game-1", other_user)
|
41
|
-
|
42
|
-
expect(page).to have_clients(1, in: "presence-game-1")
|
43
|
-
end
|
44
|
-
|
45
|
-
scenario "other client connecting" do
|
46
|
-
subscribe_to("presence-game-1")
|
47
|
-
|
48
|
-
connect_as(other_user)
|
49
|
-
|
50
|
-
expect(page).to have_clients(1, in: "presence-game-1")
|
51
|
-
end
|
52
|
-
|
53
|
-
protected
|
54
|
-
|
55
|
-
def have_clients(count, options = {})
|
56
|
-
have_css("li.channel-#{options[:in]}", count: count, text: options[:named])
|
57
|
-
end
|
58
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
feature "Client subscribing to a channel" do
|
6
|
-
let(:cache_event) { "command" }
|
7
|
-
let(:cache_channel) { "cache-last-command" }
|
8
|
-
let(:other_user) { "Bob" }
|
9
|
-
|
10
|
-
before do
|
11
|
-
connect
|
12
|
-
end
|
13
|
-
|
14
|
-
scenario "successfully subscribes to a channel" do
|
15
|
-
subscribe_to("chat-message")
|
16
|
-
|
17
|
-
expect(page).to have_content("Subscribed to chat-message.")
|
18
|
-
end
|
19
|
-
|
20
|
-
scenario "successfully subscribes to multiple channel" do
|
21
|
-
subscribe_to("chat-enter")
|
22
|
-
subscribe_to("chat-exit")
|
23
|
-
|
24
|
-
expect(page).to have_content("Subscribed to chat-enter.")
|
25
|
-
expect(page).to have_content("Subscribed to chat-exit.")
|
26
|
-
end
|
27
|
-
|
28
|
-
scenario "successfully subscribes to a private channel" do
|
29
|
-
subscribe_to("private-message-bob")
|
30
|
-
|
31
|
-
expect(page).to have_content("Subscribed to private-message-bob.")
|
32
|
-
end
|
33
|
-
|
34
|
-
scenario "successfully subscribes to a presence channel" do
|
35
|
-
subscribe_to("presence-game-1")
|
36
|
-
|
37
|
-
expect(page).to have_content("Subscribed to presence-game-1.")
|
38
|
-
end
|
39
|
-
|
40
|
-
scenario "unsuccessfully subscribes to a private channel" do
|
41
|
-
override_socket_id("13.37")
|
42
|
-
|
43
|
-
attempt_to_subscribe_to("private-message-bob")
|
44
|
-
|
45
|
-
expect(page).not_to have_content("Subscribed to private-message-bob.")
|
46
|
-
end
|
47
|
-
|
48
|
-
scenario "unsuccessfully subscribes to a presence channel" do
|
49
|
-
override_socket_id("13.37")
|
50
|
-
|
51
|
-
attempt_to_subscribe_to("presence-game-1")
|
52
|
-
|
53
|
-
expect(page).not_to have_content("Subscribed to presence-game-1.")
|
54
|
-
end
|
55
|
-
|
56
|
-
scenario "successfully subscribes to a cache channel, with no cached event" do
|
57
|
-
subscribe_to(cache_channel)
|
58
|
-
|
59
|
-
expect(page).to have_content("No cached event for cache-last-command.")
|
60
|
-
end
|
61
|
-
|
62
|
-
scenario "successfully subscribes to a cache channel, with cached event" do
|
63
|
-
subscribe_to(cache_channel)
|
64
|
-
Pusher.trigger(cache_channel, cache_event, {}, {})
|
65
|
-
|
66
|
-
connect_as(other_user, channel: cache_channel)
|
67
|
-
|
68
|
-
using_session(other_user) do
|
69
|
-
expect(page).to have_content("Channel #{cache_channel} received #{cache_event} event.")
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
protected
|
74
|
-
|
75
|
-
def attempt_to_subscribe_to(channel)
|
76
|
-
page.execute_script("Helpers.subscribe(#{MultiJson.dump(channel)})")
|
77
|
-
end
|
78
|
-
|
79
|
-
def override_socket_id(value)
|
80
|
-
page.execute_script(
|
81
|
-
"Pusher.instance.connection.socket_id = #{MultiJson.dump(value)};"
|
82
|
-
)
|
83
|
-
end
|
84
|
-
end
|