pusher-fake 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6f3eacabe00d510d5ad31f3796c821a0b34de364
4
- data.tar.gz: c144fc964da7577d3244f08f3c36f648302c8e4f
2
+ SHA256:
3
+ metadata.gz: d164bb85fcc0e139fada900d4703abb1340319cc595cb31d4add51d90f4b5ac3
4
+ data.tar.gz: 55d1cfda30b76adca304332495d9e5cab16c788bf07d15aa8e85b6be695ed11a
5
5
  SHA512:
6
- metadata.gz: 4dda368dd7c7c488399ce316e7eac7c8e90e0da213c8b96009aef2fc01e997ebfebddd8fd7fe8acae6413953427b31a3d0ee5106e5f0f491f4f4031dc80f7e81
7
- data.tar.gz: 535020b68c34f77dac67828bef623d3ca76f9bb72139bd4290cc644d31e6e380b2248074c502c8f89c46b737e1df74b3b4cc6d29ba24c2667f8366d144c81aa6
6
+ metadata.gz: 7d8eee35e30bd8e6ec013d4cb9b196beb542c4fa4b3802defa4a26dde91cc18db64801133cbbe922b7475d0fa3c030d5f9660217375d6d49df38353698a0bf96
7
+ data.tar.gz: 9d8fa2e40e6c5dc158df21df74dcafca0f358a876163e9eab844d00c43ac67eb8cd5786e2955797449926b842c21462133fa57848ab4b4f6d96c9199252499b6
data/bin/pusher-fake CHANGED
@@ -50,3 +50,5 @@ raise OptionParser::MissingArgument.new("--key") if Pusher.key.nil?
50
50
  raise OptionParser::MissingArgument.new("--secret") if Pusher.secret.nil?
51
51
 
52
52
  PusherFake::Server.start
53
+
54
+ # rubocop:enable Metrics/BlockLength, Metrics/LineLength
data/lib/pusher-fake.rb CHANGED
@@ -1,5 +1,3 @@
1
- # rubocop:disable Naming/FileName
2
-
3
1
  require "em-http-request"
4
2
  require "em-websocket"
5
3
  require "multi_json"
@@ -9,7 +7,7 @@ require "thin"
9
7
  # A Pusher fake.
10
8
  module PusherFake
11
9
  # The current version string.
12
- VERSION = "1.9.0".freeze
10
+ VERSION = "1.10.0".freeze
13
11
 
14
12
  autoload :Channel, "pusher-fake/channel"
15
13
  autoload :Configuration, "pusher-fake/configuration"
@@ -2,7 +2,7 @@ module PusherFake
2
2
  # Configuration class.
3
3
  class Configuration
4
4
  # @return [String] The Pusher Applicaiton ID. (Defaults to +PUSHER_APP_ID+.)
5
- attr_accessor :app_id
5
+ attr_reader :app_id
6
6
 
7
7
  # @return [String] The Pusher API key. (Defaults to +PUSHER_API_KEY+.)
8
8
  attr_accessor :key
@@ -34,6 +34,13 @@ module PusherFake
34
34
  reset!
35
35
  end
36
36
 
37
+ # Assign the application ID, ensuring it's a string.
38
+ #
39
+ # @params [Integer|String] id The application ID.
40
+ def app_id=(id)
41
+ @app_id = id.to_s
42
+ end
43
+
37
44
  def reset!
38
45
  self.app_id = "PUSHER_APP_ID"
39
46
  self.key = "PUSHER_API_KEY"
@@ -28,7 +28,7 @@ module PusherFake
28
28
  response = response_for(request)
29
29
 
30
30
  Rack::Response.new(MultiJson.dump(response)).finish
31
- rescue => error # rubocop:disable Lint/RescueWithoutErrorClass
31
+ rescue StandardError => error
32
32
  Rack::Response.new(error.message, 400).finish
33
33
  end
34
34
 
@@ -143,8 +143,6 @@ module PusherFake
143
143
  { users: users || [] }
144
144
  end
145
145
 
146
- private_class_method
147
-
148
146
  # Emit an event with data to the requested channel(s).
149
147
  #
150
148
  # @param [Hash] event The raw event JSON.
@@ -158,6 +156,7 @@ module PusherFake
158
156
  channel.emit(event["name"], data, socket_id: event["socket_id"])
159
157
  end
160
158
  end
159
+ private_class_method :send_event
161
160
  # rubocop:enable Style/RescueModifier
162
161
  end
163
162
  end
@@ -1,5 +1,3 @@
1
- # rubocop:disable Style/GlobalVars
2
-
3
1
  require "spec_helper"
4
2
 
5
3
  feature "Receiving event webhooks" do
@@ -8,6 +6,10 @@ feature "Receiving event webhooks" do
8
6
  let(:presence_channel) { "presence-room-1" }
9
7
 
10
8
  before do
9
+ events.clear
10
+
11
+ PusherFake.configuration.webhooks = ["http://127.0.0.1:8082"]
12
+
11
13
  connect
12
14
  connect_as(other_user)
13
15
  end
@@ -15,11 +17,11 @@ feature "Receiving event webhooks" do
15
17
  scenario "occupying a channel" do
16
18
  subscribe_to(channel)
17
19
 
18
- expect($events).to include_event("channel_occupied", "channel" => channel)
20
+ expect(events).to include_event("channel_occupied", "channel" => channel)
19
21
 
20
22
  subscribe_to_as(channel, other_user)
21
23
 
22
- expect($events.size).to eq(1)
24
+ expect(events.size).to eq(1)
23
25
  end
24
26
 
25
27
  scenario "vacating a channel" do
@@ -28,24 +30,24 @@ feature "Receiving event webhooks" do
28
30
 
29
31
  unsubscribe_from(channel)
30
32
 
31
- expect($events.size).to eq(1)
33
+ expect(events.size).to eq(1)
32
34
 
33
35
  unsubscribe_from_as(channel, other_user)
34
36
 
35
- expect($events).to include_event("channel_vacated", "channel" => channel)
37
+ expect(events).to include_event("channel_vacated", "channel" => channel)
36
38
  end
37
39
 
38
40
  scenario "subscribing to a presence channel" do
39
41
  subscribe_to(presence_channel)
40
42
 
41
- expect($events).to include_event(
43
+ expect(events).to include_event(
42
44
  "member_added",
43
45
  "channel" => presence_channel, "user_id" => user_id
44
46
  )
45
47
 
46
48
  subscribe_to_as(presence_channel, other_user)
47
49
 
48
- expect($events).to include_event(
50
+ expect(events).to include_event(
49
51
  "member_added",
50
52
  "channel" => presence_channel, "user_id" => user_id(other_user)
51
53
  )
@@ -57,19 +59,27 @@ feature "Receiving event webhooks" do
57
59
 
58
60
  unsubscribe_from(presence_channel)
59
61
 
60
- expect($events).to include_event("member_added",
61
- "channel" => presence_channel,
62
- "user_id" => user_id)
62
+ expect(events).to include_event("member_added",
63
+ "channel" => presence_channel,
64
+ "user_id" => user_id)
63
65
 
64
66
  unsubscribe_from_as(presence_channel, other_user)
65
67
 
66
- expect($events).to include_event("member_added",
67
- "channel" => presence_channel,
68
- "user_id" => user_id(other_user))
68
+ expect(events).to include_event("member_added",
69
+ "channel" => presence_channel,
70
+ "user_id" => user_id(other_user))
69
71
  end
70
72
 
71
73
  protected
72
74
 
75
+ def events
76
+ sleep(1)
77
+
78
+ WebhookHelper.mutex.synchronize do
79
+ WebhookHelper.events
80
+ end
81
+ end
82
+
73
83
  def include_event(event, options = {})
74
84
  include(options.merge("name" => event))
75
85
  end
@@ -36,21 +36,21 @@ describe PusherFake::Channel, ".factory" do
36
36
  end
37
37
  end
38
38
 
39
- context "for a public channel" do
39
+ context "with a public channel" do
40
40
  let(:name) { "channel" }
41
41
  let(:channel_class) { PusherFake::Channel::Public }
42
42
 
43
43
  it_behaves_like "a channel factory"
44
44
  end
45
45
 
46
- context "for a private channel" do
46
+ context "with a private channel" do
47
47
  let(:name) { "private-channel" }
48
48
  let(:channel_class) { PusherFake::Channel::Private }
49
49
 
50
50
  it_behaves_like "a channel factory"
51
51
  end
52
52
 
53
- context "for a presence channel" do
53
+ context "with a presence channel" do
54
54
  let(:name) { "presence-channel" }
55
55
  let(:channel_class) { PusherFake::Channel::Presence }
56
56
 
@@ -2,32 +2,32 @@ require "spec_helper"
2
2
 
3
3
  describe PusherFake::Configuration do
4
4
  it do
5
- is_expected.to have_configuration_option(:key)
5
+ expect(subject).to have_configuration_option(:key)
6
6
  .with_default("PUSHER_API_KEY")
7
7
  end
8
8
 
9
9
  it do
10
- is_expected.to have_configuration_option(:logger)
10
+ expect(subject).to have_configuration_option(:logger)
11
11
  .with_default(STDOUT.to_io)
12
12
  end
13
13
 
14
14
  it do
15
- is_expected.to have_configuration_option(:verbose)
15
+ expect(subject).to have_configuration_option(:verbose)
16
16
  .with_default(false)
17
17
  end
18
18
 
19
19
  it do
20
- is_expected.to have_configuration_option(:webhooks)
20
+ expect(subject).to have_configuration_option(:webhooks)
21
21
  .with_default([])
22
22
  end
23
23
 
24
24
  it do
25
- is_expected.to have_configuration_option(:app_id)
25
+ expect(subject).to have_configuration_option(:app_id)
26
26
  .with_default("PUSHER_APP_ID")
27
27
  end
28
28
 
29
29
  it do
30
- is_expected.to have_configuration_option(:secret)
30
+ expect(subject).to have_configuration_option(:secret)
31
31
  .with_default("PUSHER_API_SECRET")
32
32
  end
33
33
 
@@ -48,6 +48,16 @@ describe PusherFake::Configuration do
48
48
  end
49
49
  end
50
50
 
51
+ describe PusherFake::Configuration, "#app_id=" do
52
+ subject { described_class.new }
53
+
54
+ it "converts value to a string" do
55
+ subject.app_id = 1_337
56
+
57
+ expect(subject.app_id).to eq("1337")
58
+ end
59
+ end
60
+
51
61
  describe PusherFake::Configuration, "#to_options" do
52
62
  it "includes the socket host as wsHost" do
53
63
  options = subject.to_options
@@ -48,6 +48,23 @@ shared_examples_for "an API request" do
48
48
  end
49
49
  end
50
50
 
51
+ describe PusherFake::Server::Application, ".call, with a numeric ID" do
52
+ it_behaves_like "an API request" do
53
+ let(:id) { Time.now.to_i }
54
+ let(:path) { "/apps/#{id}/events" }
55
+
56
+ before do
57
+ PusherFake.configuration.app_id = id
58
+
59
+ allow(subject).to receive(:events).and_return(hash)
60
+ end
61
+
62
+ after do
63
+ PusherFake.configuration.app_id = "PUSHER_APP_ID"
64
+ end
65
+ end
66
+ end
67
+
51
68
  describe PusherFake::Server::Application, ".call, for triggering events" do
52
69
  it_behaves_like "an API request" do
53
70
  let(:id) { PusherFake.configuration.app_id }
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ require "bundler/setup"
2
2
 
3
3
  Bundler.require(:default, :development)
4
4
 
5
- Dir[File.expand_path("../support/**/*.rb", __FILE__)].each do |file|
5
+ Dir[File.expand_path("support/**/*.rb", __dir__)].each do |file|
6
6
  require file
7
7
  end
8
8
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Pusher JavaScript Library v4.2.1
2
+ * Pusher JavaScript Library v4.2.2
3
3
  * https://pusher.com/
4
4
  *
5
5
  * Copyright 2017, Pusher
@@ -89,7 +89,7 @@ return /******/ (function(modules) { // webpackBootstrap
89
89
  var _this = this;
90
90
  checkAppKey(app_key);
91
91
  options = options || {};
92
- if (!options.cluster) {
92
+ if (!options.cluster && !(options.wsHost || options.httpHost)) {
93
93
  var suffix = url_store_1["default"].buildLogSuffix("javascriptQuickStart");
94
94
  logger_1["default"].warn("You should always specify a cluster when connecting. " + suffix);
95
95
  }
@@ -476,11 +476,12 @@ return /******/ (function(modules) { // webpackBootstrap
476
476
 
477
477
  "use strict";
478
478
  var Defaults = {
479
- VERSION: "4.2.1",
479
+ VERSION: "4.2.2",
480
480
  PROTOCOL: 7,
481
481
  host: 'ws.pusherapp.com',
482
482
  ws_port: 80,
483
483
  wss_port: 443,
484
+ ws_path: '',
484
485
  sockjs_host: 'sockjs.pusher.com',
485
486
  sockjs_http_port: 80,
486
487
  sockjs_https_port: 443,
@@ -629,7 +630,10 @@ return /******/ (function(modules) { // webpackBootstrap
629
630
  args[_i - 0] = arguments[_i];
630
631
  }
631
632
  var message = collections_1.stringify.apply(this, arguments);
632
- if ((window).console) {
633
+ if (pusher_1["default"].log) {
634
+ pusher_1["default"].log(message);
635
+ }
636
+ else if ((window).console) {
633
637
  if ((window).console.warn) {
634
638
  (window).console.warn(message);
635
639
  }
@@ -637,9 +641,6 @@ return /******/ (function(modules) { // webpackBootstrap
637
641
  (window).console.log(message);
638
642
  }
639
643
  }
640
- if (pusher_1["default"].log) {
641
- pusher_1["default"].log(message);
642
- }
643
644
  }
644
645
  };
645
646
  exports.__esModule = true;
@@ -1339,7 +1340,8 @@ return /******/ (function(modules) { // webpackBootstrap
1339
1340
  }
1340
1341
  exports.ws = {
1341
1342
  getInitial: function (key, params) {
1342
- return getGenericURL("ws", params, getGenericPath(key, "flash=false"));
1343
+ var path = (params.httpPath || "") + getGenericPath(key, "flash=false");
1344
+ return getGenericURL("ws", params, path);
1343
1345
  }
1344
1346
  };
1345
1347
  exports.http = {
@@ -1725,7 +1727,8 @@ return /******/ (function(modules) { // webpackBootstrap
1725
1727
  return [
1726
1728
  [":def", "ws_options", {
1727
1729
  hostUnencrypted: config.wsHost + ":" + config.wsPort,
1728
- hostEncrypted: config.wsHost + ":" + config.wssPort
1730
+ hostEncrypted: config.wsHost + ":" + config.wssPort,
1731
+ httpPath: config.wsPath
1729
1732
  }],
1730
1733
  [":def", "wss_options", [":extend", ":ws_options", {
1731
1734
  encrypted: true
@@ -4153,6 +4156,7 @@ return /******/ (function(modules) { // webpackBootstrap
4153
4156
  wsHost: defaults_1["default"].host,
4154
4157
  wsPort: defaults_1["default"].ws_port,
4155
4158
  wssPort: defaults_1["default"].wss_port,
4159
+ wsPath: defaults_1["default"].ws_path,
4156
4160
  httpHost: defaults_1["default"].sockjs_host,
4157
4161
  httpPort: defaults_1["default"].sockjs_http_port,
4158
4162
  httpsPort: defaults_1["default"].sockjs_https_port,
@@ -13,7 +13,7 @@
13
13
  <ul></ul>
14
14
  </section>
15
15
 
16
- <script src="/javascripts/vendor/pusher-4.2.1.js"></script>
16
+ <script src="/javascripts/vendor/pusher-4.2.2.js"></script>
17
17
  <script>
18
18
  Pusher.instance = <%= PusherFake.javascript %>;
19
19
  Pusher.instance.connection.bind("state_change", function(states) {
@@ -6,4 +6,5 @@ Capybara.register_driver :poltergeist do |app|
6
6
  end
7
7
 
8
8
  Capybara.app = Sinatra::Application
9
+ Capybara.server = :webrick
9
10
  Capybara.default_driver = :poltergeist
@@ -1,4 +1,12 @@
1
- # rubocop:disable Style/GlobalVars
1
+ class WebhookHelper
2
+ def self.events
3
+ @events ||= []
4
+ end
5
+
6
+ def self.mutex
7
+ @mutex ||= Mutex.new
8
+ end
9
+ end
2
10
 
3
11
  thread = Thread.new do
4
12
  # Not explicitly requiring Thin::Server occasionally results in
@@ -12,7 +20,9 @@ thread = Thread.new do
12
20
  webhook = Pusher::WebHook.new(request)
13
21
 
14
22
  if webhook.valid?
15
- $events.concat(webhook.events)
23
+ WebhookHelper.mutex.synchronize do
24
+ WebhookHelper.events.concat(webhook.events)
25
+ end
16
26
  end
17
27
 
18
28
  Rack::Response.new.finish
@@ -26,11 +36,3 @@ thread = Thread.new do
26
36
  end
27
37
 
28
38
  at_exit { thread.exit }
29
-
30
- RSpec.configure do |config|
31
- config.before do
32
- $events = []
33
-
34
- PusherFake.configuration.webhooks = ["http://127.0.0.1:8082"]
35
- end
36
- end
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.9.0
4
+ version: 1.10.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: 2017-11-02 00:00:00.000000000 Z
11
+ date: 2018-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.16.0
75
+ version: 1.18.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: 1.16.0
82
+ version: 1.18.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pusher
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,84 +100,84 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 12.2.1
103
+ version: 12.3.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 12.2.1
110
+ version: 12.3.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 3.7.0
117
+ version: 3.8.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 3.7.0
124
+ version: 3.8.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.51.0
131
+ version: 0.58.2
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.51.0
138
+ version: 0.58.2
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.19.0
145
+ version: 1.29.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.19.0
152
+ version: 1.29.0
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.0
159
+ version: 2.0.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: 2.0.0
166
+ version: 2.0.3
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: yard
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 0.9.9
173
+ version: 0.9.16
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 0.9.9
180
+ version: 0.9.16
181
181
  description: A fake Pusher server for development and testing.
182
182
  email: hello@tristandunn.com
183
183
  executables:
@@ -220,7 +220,7 @@ files:
220
220
  - spec/lib/pusher_fake_spec.rb
221
221
  - spec/spec_helper.rb
222
222
  - spec/support/application.rb
223
- - spec/support/application/public/javascripts/vendor/pusher-4.2.1.js
223
+ - spec/support/application/public/javascripts/vendor/pusher-4.2.2.js
224
224
  - spec/support/application/views/index.erb
225
225
  - spec/support/capybara.rb
226
226
  - spec/support/coveralls.rb
@@ -251,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
251
  version: '0'
252
252
  requirements: []
253
253
  rubyforge_project:
254
- rubygems_version: 2.6.13
254
+ rubygems_version: 2.7.6
255
255
  signing_key:
256
256
  specification_version: 4
257
257
  summary: A fake Pusher server for development and testing.
@@ -270,7 +270,7 @@ test_files:
270
270
  - spec/support/application.rb
271
271
  - spec/support/pusher_fake.rb
272
272
  - spec/support/matchers/have_configuration_option.rb
273
- - spec/support/application/public/javascripts/vendor/pusher-4.2.1.js
273
+ - spec/support/application/public/javascripts/vendor/pusher-4.2.2.js
274
274
  - spec/support/application/views/index.erb
275
275
  - spec/support/coveralls.rb
276
276
  - spec/support/helpers/connect.rb