pusher-fake 1.10.0 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d164bb85fcc0e139fada900d4703abb1340319cc595cb31d4add51d90f4b5ac3
4
- data.tar.gz: 55d1cfda30b76adca304332495d9e5cab16c788bf07d15aa8e85b6be695ed11a
3
+ metadata.gz: 791394d448a74ca4961e1fba348d729cec78707e9c06e502cd83d65778eb2e5d
4
+ data.tar.gz: f32b3aab29485d672566ae06c7d670b5cbe3607e7e32c5a09baeffa156c14df3
5
5
  SHA512:
6
- metadata.gz: 7d8eee35e30bd8e6ec013d4cb9b196beb542c4fa4b3802defa4a26dde91cc18db64801133cbbe922b7475d0fa3c030d5f9660217375d6d49df38353698a0bf96
7
- data.tar.gz: 9d8fa2e40e6c5dc158df21df74dcafca0f358a876163e9eab844d00c43ac67eb8cd5786e2955797449926b842c21462133fa57848ab4b4f6d96c9199252499b6
6
+ metadata.gz: e8df1c937ba729cc693f7d1a666573934155c7b0dc06b9708e38f8a78030efe9a7e2efc69b2a4dac7197f68c94fe96eb62a3a006d5f3d5690b00b7cd41b3aad2
7
+ data.tar.gz: 0db82d0635bb6958fae833c131813e6ef6eed51c7ef7835d9370322531a83957b543ce99ea2972aa55feecce4655ed5b3d54e7772aa1efb495653b726831f623
@@ -7,7 +7,7 @@ require "thin"
7
7
  # A Pusher fake.
8
8
  module PusherFake
9
9
  # The current version string.
10
- VERSION = "1.10.0".freeze
10
+ VERSION = "1.11.0".freeze
11
11
 
12
12
  autoload :Channel, "pusher-fake/channel"
13
13
  autoload :Configuration, "pusher-fake/configuration"
@@ -5,13 +5,13 @@ module PusherFake
5
5
  autoload :Private, "pusher-fake/channel/private"
6
6
  autoload :Presence, "pusher-fake/channel/presence"
7
7
 
8
- class << self
9
- # Name matcher for private channels.
10
- PRIVATE_CHANNEL_MATCHER = /\Aprivate-/
8
+ # Prefix for private channels.
9
+ PRIVATE_CHANNEL_PREFIX = "private-".freeze
11
10
 
12
- # Name matcher for presence channels.
13
- PRESENCE_CHANNEL_MATCHER = /\Apresence-/
11
+ # Prefix for presence channels.
12
+ PRESENCE_CHANNEL_PREFIX = "presence-".freeze
14
13
 
14
+ class << self
15
15
  # @return [Hash] Cache of existing channels.
16
16
  attr_writer :channels
17
17
 
@@ -58,10 +58,9 @@ module PusherFake
58
58
  # @param [String] name The name of the channel.
59
59
  # @return [Class] The class to use for the channel.
60
60
  def class_for(name)
61
- case name
62
- when PRIVATE_CHANNEL_MATCHER
61
+ if name.start_with?(PRIVATE_CHANNEL_PREFIX)
63
62
  Private
64
- when PRESENCE_CHANNEL_MATCHER
63
+ elsif name.start_with?(PRESENCE_CHANNEL_PREFIX)
65
64
  Presence
66
65
  else
67
66
  Public
@@ -4,6 +4,9 @@ module PusherFake
4
4
  # @return [String] The Pusher Applicaiton ID. (Defaults to +PUSHER_APP_ID+.)
5
5
  attr_reader :app_id
6
6
 
7
+ # @return [Boolean] Disable the client statistics. (Defaults to +true+.)
8
+ attr_accessor :disable_stats
9
+
7
10
  # @return [String] The Pusher API key. (Defaults to +PUSHER_API_KEY+.)
8
11
  attr_accessor :key
9
12
 
@@ -49,6 +52,7 @@ module PusherFake
49
52
  self.verbose = false
50
53
  self.webhooks = []
51
54
 
55
+ self.disable_stats = true
52
56
  self.socket_options = { host: "127.0.0.1", port: available_port }
53
57
  self.web_options = { host: "127.0.0.1", port: available_port }
54
58
  end
@@ -58,9 +62,10 @@ module PusherFake
58
62
  # @param [Hash] options Custom options for Pusher client.
59
63
  def to_options(options = {})
60
64
  options.merge(
61
- wsHost: socket_options[:host],
62
- wsPort: socket_options[:port],
63
- cluster: "us-east-1"
65
+ wsHost: socket_options[:host],
66
+ wsPort: socket_options[:port],
67
+ cluster: "us-east-1",
68
+ disableStats: disable_stats
64
69
  )
65
70
  end
66
71
 
@@ -1,8 +1,8 @@
1
1
  module PusherFake
2
2
  # A client connection.
3
3
  class Connection
4
- # Name matcher for client events.
5
- CLIENT_EVENT_MATCHER = /\Aclient-(.+)\z/
4
+ # Prefix for client events.
5
+ CLIENT_EVENT_PREFIX = "client-".freeze
6
6
 
7
7
  # @return [EventMachine::WebSocket::Connection] Socket for the connection.
8
8
  attr_reader :socket
@@ -53,7 +53,7 @@ module PusherFake
53
53
 
54
54
  PusherFake.log("RECV #{id}: #{message}")
55
55
 
56
- if event =~ CLIENT_EVENT_MATCHER
56
+ if event.start_with?(CLIENT_EVENT_PREFIX)
57
57
  process_trigger(event, message)
58
58
  else
59
59
  process_event(event, message)
@@ -9,8 +9,6 @@ module PusherFake
9
9
  CHANNEL_USER_COUNT_ERROR = "Cannot retrieve the user count unless the " \
10
10
  "channel is a presence channel".freeze
11
11
 
12
- PRESENCE_PREFIX_MATCHER = /\Apresence-/
13
-
14
12
  REQUEST_PATHS = {
15
13
  %r{\A/apps/:id/batch_events\z} => :batch_events,
16
14
  %r{\A/apps/:id/events\z} => :events,
@@ -68,11 +66,9 @@ module PusherFake
68
66
  def self.channel(name, request)
69
67
  count = request.params["info"].to_s.split(",").include?("user_count")
70
68
 
71
- if count && name !~ PRESENCE_PREFIX_MATCHER
72
- raise CHANNEL_USER_COUNT_ERROR
73
- end
69
+ raise CHANNEL_USER_COUNT_ERROR if invalid_channel_to_count?(name, count)
74
70
 
75
- channel = PusherFake::Channel.channels[name]
71
+ channel = Channel.channels[name]
76
72
  connections = channel ? channel.connections : []
77
73
 
78
74
  result = { occupied: connections.any? }
@@ -92,7 +88,7 @@ module PusherFake
92
88
  count = request.params["info"].to_s.split(",").include?("user_count")
93
89
  prefix = request.params["filter_by_prefix"].to_s
94
90
 
95
- raise CHANNEL_FILTER_ERROR if count && prefix !~ PRESENCE_PREFIX_MATCHER
91
+ raise CHANNEL_FILTER_ERROR if invalid_channel_to_count?(prefix, count)
96
92
 
97
93
  PusherFake::Channel
98
94
  .channels
@@ -143,6 +139,12 @@ module PusherFake
143
139
  { users: users || [] }
144
140
  end
145
141
 
142
+ # @return [Boolean]
143
+ def self.invalid_channel_to_count?(name, includes_count)
144
+ includes_count && !name.start_with?(Channel::PRESENCE_CHANNEL_PREFIX)
145
+ end
146
+ private_class_method :invalid_channel_to_count?
147
+
146
148
  # Emit an event with data to the requested channel(s).
147
149
  #
148
150
  # @param [Hash] event The raw event JSON.
@@ -1,6 +1,11 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe PusherFake::Configuration do
4
+ it do
5
+ expect(subject).to have_configuration_option(:disable_stats)
6
+ .with_default(true)
7
+ end
8
+
4
9
  it do
5
10
  expect(subject).to have_configuration_option(:key)
6
11
  .with_default("PUSHER_API_KEY")
@@ -59,6 +64,12 @@ describe PusherFake::Configuration, "#app_id=" do
59
64
  end
60
65
 
61
66
  describe PusherFake::Configuration, "#to_options" do
67
+ it "includes disable_stats as disableStats" do
68
+ options = subject.to_options
69
+
70
+ expect(options).to include(disableStats: subject.disable_stats)
71
+ end
72
+
62
73
  it "includes the socket host as wsHost" do
63
74
  options = subject.to_options
64
75
 
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: 1.10.0
4
+ version: 1.11.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: 2018-09-05 00:00:00.000000000 Z
11
+ date: 2018-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 1.3.1
89
+ version: 1.3.2
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: 1.3.1
96
+ version: 1.3.2
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
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: 0.58.2
131
+ version: 0.60.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: 0.58.2
138
+ version: 0.60.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 1.29.0
145
+ version: 1.30.1
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.29.0
152
+ version: 1.30.1
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: sinatra
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 2.0.3
159
+ version: 2.0.4
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: 2.0.3
166
+ version: 2.0.4
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: yard
169
169
  requirement: !ruby/object:Gem::Requirement