pusher-fake 3.0.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pusher-fake/channel/presence.rb +1 -1
  3. data/lib/pusher-fake/channel/public.rb +32 -0
  4. data/lib/pusher-fake/server/chain_trap_handlers.rb +24 -0
  5. data/lib/pusher-fake/server.rb +10 -9
  6. data/lib/pusher-fake.rb +1 -1
  7. metadata +28 -90
  8. data/spec/features/api/channels_spec.rb +0 -86
  9. data/spec/features/api/users_spec.rb +0 -36
  10. data/spec/features/client/connect_spec.rb +0 -11
  11. data/spec/features/client/event_spec.rb +0 -49
  12. data/spec/features/client/presence_spec.rb +0 -58
  13. data/spec/features/client/subscribe_spec.rb +0 -69
  14. data/spec/features/server/event_spec.rb +0 -122
  15. data/spec/features/server/webhooks_spec.rb +0 -88
  16. data/spec/lib/pusher-fake/channel/presence_spec.rb +0 -249
  17. data/spec/lib/pusher-fake/channel/private_spec.rb +0 -180
  18. data/spec/lib/pusher-fake/channel/public_spec.rb +0 -148
  19. data/spec/lib/pusher-fake/channel_spec.rb +0 -122
  20. data/spec/lib/pusher-fake/configuration_spec.rb +0 -123
  21. data/spec/lib/pusher-fake/connection_spec.rb +0 -332
  22. data/spec/lib/pusher-fake/server/application_spec.rb +0 -604
  23. data/spec/lib/pusher-fake/server_spec.rb +0 -177
  24. data/spec/lib/pusher-fake/webhook_spec.rb +0 -67
  25. data/spec/lib/pusher_fake_spec.rb +0 -96
  26. data/spec/spec_helper.rb +0 -18
  27. data/spec/support/application/public/javascripts/vendor/polyfill.min.js +0 -1
  28. data/spec/support/application/public/javascripts/vendor/pusher-7.0.0.js +0 -4565
  29. data/spec/support/application/views/index.erb +0 -88
  30. data/spec/support/application.rb +0 -35
  31. data/spec/support/capybara.rb +0 -7
  32. data/spec/support/coveralls.rb +0 -9
  33. data/spec/support/helpers/connect.rb +0 -21
  34. data/spec/support/helpers/event.rb +0 -11
  35. data/spec/support/helpers/subscription.rb +0 -31
  36. data/spec/support/helpers/user.rb +0 -13
  37. data/spec/support/matchers/have_configuration_option.rb +0 -19
  38. data/spec/support/pusher_fake.rb +0 -21
  39. data/spec/support/webhooks.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3bb752700c2e699cf4af6685b1583905f0f9ccc772d7e323129621c5de38625
4
- data.tar.gz: 2ad770522739c7c11833efd13614f1731b9690583b5b08c1e48c7a9cdfb037ef
3
+ metadata.gz: '05043028e1837c87118d83e74496c9189036a69f170bf71c15e9e6c452af7565'
4
+ data.tar.gz: bdefba87a3ff23c7e4ec13b14d852b2c27dd0d7daeb202708ac0d1767ae9d5e9
5
5
  SHA512:
6
- metadata.gz: c1aee6b0c2cbcdbe170ef203392f439558b358159983f1e9dda4634cb54ad966ea0f6ad9f4e4a5d6d3ad2a85fc3b33e2855b2286007d0b7d39829d2d24bf3a15
7
- data.tar.gz: c3d408c4c4fd805a5d007f1e2c7a67f9278a38f9cc0848527ac0f06d8c8b453b0d6d06c642ea4e6597db798a1bf811d122d91325888efb4aed04843e83b15a46
6
+ metadata.gz: d47d6a29b94b3a95fe5d0023a4d3d577e1160a2aa357884f617998778c5a5ba8a4a5353a40de7a709d044f5d3324e31448d53c6c06bbc9917f3e449e37f5c3f5
7
+ data.tar.gz: cde630c89000bc96b0d56f700f4a2f0568e9e410fc5d445f906bbfc22acd9fec559a171ae9fee388606bdd94406328be04a2136073d2f546dd3bfadd1e367384
@@ -36,7 +36,7 @@ module PusherFake
36
36
  #
37
37
  # @return [Hash] Hash containing presence information.
38
38
  def subscription_data
39
- hash = members.map { |_, member| [member[:user_id], member[:user_info]] }.to_h
39
+ hash = members.to_h { |_, member| [member[:user_id], member[:user_info]] }
40
40
 
41
41
  { presence: { hash: hash, count: members.size } }
42
42
  end
@@ -4,6 +4,8 @@ module PusherFake
4
4
  module Channel
5
5
  # A public channel.
6
6
  class Public
7
+ CACHE_CHANNEL_PREFIX = /^(private-|presence-){0,1}cache-/.freeze
8
+
7
9
  # @return [Array] Connections in this channel.
8
10
  attr_reader :connections
9
11
 
@@ -15,6 +17,7 @@ module PusherFake
15
17
  # @param [String] name The channel name.
16
18
  def initialize(name)
17
19
  @name = name
20
+ @last_event = nil
18
21
  @connections = []
19
22
  end
20
23
 
@@ -24,6 +27,7 @@ module PusherFake
24
27
  # @param [Hash] options The options for the channel.
25
28
  def add(connection, options = {})
26
29
  subscription_succeeded(connection, options)
30
+ emit_last_event(connection)
27
31
  end
28
32
 
29
33
  # Emit an event to the channel.
@@ -31,6 +35,10 @@ module PusherFake
31
35
  # @param [String] event The event name.
32
36
  # @param [Hash] data The event data.
33
37
  def emit(event, data, options = {})
38
+ if cache_channel?
39
+ @last_event = [event, data]
40
+ end
41
+
34
42
  connections.each do |connection|
35
43
  unless connection.id == options[:socket_id]
36
44
  connection.emit(event, data, name)
@@ -71,6 +79,30 @@ module PusherFake
71
79
 
72
80
  private
73
81
 
82
+ # @return [Array] Arguments for the last event emitted.
83
+ attr_reader :last_event
84
+
85
+ # Whether or not the channel is a cache channel.
86
+ #
87
+ # @return [Boolean]
88
+ def cache_channel?
89
+ @cache_channel ||= name.match?(CACHE_CHANNEL_PREFIX)
90
+ end
91
+
92
+ # Emit the last event if present and a cache channel.
93
+ #
94
+ # @param [Connection] connection The connection to emit to.
95
+ def emit_last_event(connection)
96
+ return unless cache_channel?
97
+
98
+ if last_event
99
+ connection.emit(*last_event, name)
100
+ else
101
+ connection.emit("pusher:cache_miss", nil, name)
102
+ trigger("cache_miss", channel: name)
103
+ end
104
+ end
105
+
74
106
  # Notify the +connection+ of the successful subscription and add the
75
107
  # connection to the channel.
76
108
  #
@@ -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:
@@ -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,21 +51,19 @@ 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.
54
64
  def configuration
55
65
  PusherFake.configuration
56
66
  end
57
-
58
- # Return a hash of options for the socket server based on
59
- # the configuration.
60
- #
61
- # @return [Hash] The socket server configuration options.
62
- def socket_server_options
63
- { host: configuration.socket_host,
64
- port: configuration.socket_port }
65
- end
66
67
  end
67
68
  end
68
69
  end
data/lib/pusher-fake.rb CHANGED
@@ -9,7 +9,7 @@ require "thin"
9
9
  # A Pusher fake.
10
10
  module PusherFake
11
11
  # The current version string.
12
- VERSION = "3.0.1"
12
+ VERSION = "4.2.0"
13
13
 
14
14
  autoload :Channel, "pusher-fake/channel"
15
15
  autoload :Configuration, "pusher-fake/configuration"
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: 3.0.1
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: 2021-09-10 00:00:00.000000000 Z
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,42 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.5'
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.5'
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.35.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.35.3
82
+ version: 3.37.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: puma
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 5.4.0
89
+ version: 5.6.4
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 5.4.0
96
+ version: 5.6.4
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pusher
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -128,42 +128,42 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 3.10.0
131
+ version: 3.11.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 3.10.0
138
+ version: 3.11.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 1.20.0
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.20.0
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.11.5
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.11.5
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.4.0
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.4.0
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: 3.142.7
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: 3.142.7
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.1.0
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.1.0
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.26
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.26
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,46 +251,16 @@ 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.0.js
280
- - spec/support/application/views/index.erb
281
- - spec/support/capybara.rb
282
- - spec/support/coveralls.rb
283
- - spec/support/helpers/connect.rb
284
- - spec/support/helpers/event.rb
285
- - spec/support/helpers/subscription.rb
286
- - spec/support/helpers/user.rb
287
- - spec/support/matchers/have_configuration_option.rb
288
- - spec/support/pusher_fake.rb
289
- - spec/support/webhooks.rb
290
259
  homepage: https://github.com/tristandunn/pusher-fake
291
260
  licenses:
292
261
  - MIT
293
- metadata: {}
262
+ metadata:
263
+ rubygems_mfa_required: 'true'
294
264
  post_install_message:
295
265
  rdoc_options: []
296
266
  require_paths:
@@ -299,47 +269,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
299
269
  requirements:
300
270
  - - ">="
301
271
  - !ruby/object:Gem::Version
302
- version: '2.6'
272
+ version: '2.7'
303
273
  required_rubygems_version: !ruby/object:Gem::Requirement
304
274
  requirements:
305
275
  - - ">="
306
276
  - !ruby/object:Gem::Version
307
277
  version: '0'
308
278
  requirements: []
309
- rubygems_version: 3.2.22
279
+ 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.0.js
335
- - spec/support/application/views/index.erb
336
- - spec/support/application.rb
337
- - spec/support/capybara.rb
338
- - spec/support/coveralls.rb
339
- - spec/support/helpers/connect.rb
340
- - spec/support/helpers/event.rb
341
- - spec/support/helpers/subscription.rb
342
- - spec/support/helpers/user.rb
343
- - spec/support/matchers/have_configuration_option.rb
344
- - spec/support/pusher_fake.rb
345
- - 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 eq(false)
52
- end
53
-
54
- scenario "channel, with an occupant" do
55
- subscribe_to(channel_name)
56
-
57
- expect(channel[:occupied]).to eq(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 eq(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,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- feature "Client connecting to the server" do
6
- scenario "successfully connects" do
7
- visit "/"
8
-
9
- expect(page).to have_content("Client connected.")
10
- end
11
- 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