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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pusher-fake/server/chain_trap_handlers.rb +24 -0
  3. data/lib/pusher-fake/server.rb +10 -0
  4. data/lib/pusher-fake.rb +1 -1
  5. metadata +20 -81
  6. data/spec/features/api/channels_spec.rb +0 -86
  7. data/spec/features/api/users_spec.rb +0 -36
  8. data/spec/features/client/connect_spec.rb +0 -11
  9. data/spec/features/client/event_spec.rb +0 -49
  10. data/spec/features/client/presence_spec.rb +0 -58
  11. data/spec/features/client/subscribe_spec.rb +0 -84
  12. data/spec/features/server/event_spec.rb +0 -122
  13. data/spec/features/server/webhooks_spec.rb +0 -107
  14. data/spec/lib/pusher-fake/channel/presence_spec.rb +0 -249
  15. data/spec/lib/pusher-fake/channel/private_spec.rb +0 -180
  16. data/spec/lib/pusher-fake/channel/public_spec.rb +0 -206
  17. data/spec/lib/pusher-fake/channel_spec.rb +0 -122
  18. data/spec/lib/pusher-fake/configuration_spec.rb +0 -123
  19. data/spec/lib/pusher-fake/connection_spec.rb +0 -332
  20. data/spec/lib/pusher-fake/server/application_spec.rb +0 -604
  21. data/spec/lib/pusher-fake/server_spec.rb +0 -177
  22. data/spec/lib/pusher-fake/webhook_spec.rb +0 -67
  23. data/spec/lib/pusher_fake_spec.rb +0 -96
  24. data/spec/spec_helper.rb +0 -31
  25. data/spec/support/application/public/javascripts/vendor/polyfill.min.js +0 -1
  26. data/spec/support/application/public/javascripts/vendor/pusher-7.0.6.js +0 -4567
  27. data/spec/support/application/views/index.erb +0 -91
  28. data/spec/support/application.rb +0 -35
  29. data/spec/support/capybara.rb +0 -10
  30. data/spec/support/helpers/connect.rb +0 -21
  31. data/spec/support/helpers/event.rb +0 -11
  32. data/spec/support/helpers/subscription.rb +0 -31
  33. data/spec/support/helpers/user.rb +0 -13
  34. data/spec/support/matchers/have_configuration_option.rb +0 -19
  35. data/spec/support/pusher_fake.rb +0 -21
  36. data/spec/support/webhooks.rb +0 -40
@@ -1,91 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>PusherFake Test Application</title>
5
- </head>
6
- <body>
7
-
8
- <section>
9
- <header>
10
- <h1>Client disconnected.</h1>
11
- </header>
12
-
13
- <ul></ul>
14
- </section>
15
-
16
- <script src="/javascripts/vendor/polyfill.min.js"></script>
17
- <script src="/javascripts/vendor/pusher-7.0.6.js"></script>
18
- <script>
19
- Pusher.instance = <%= PusherFake.javascript %>;
20
- Pusher.instance.connection.bind("state_change", function(states) {
21
- var header = document.querySelector("h1");
22
-
23
- header.innerText = "Client " + states.current + ".";
24
- });
25
-
26
- var Helpers = {
27
- log: function(text, attributes) {
28
- var list = document.querySelector("ul"),
29
- element = document.createElement("li");
30
-
31
- element.innerText = text;
32
-
33
- for (var name in attributes) {
34
- element.setAttribute(name, attributes[name]);
35
- }
36
-
37
- list.appendChild(element);
38
- },
39
-
40
- safeID: function(id) {
41
- return id.replace(".", "");
42
- },
43
-
44
- subscribe: function(name) {
45
- Pusher.instance.subscribe(name)
46
- .bind("pusher:subscription_succeeded", function(client) {
47
- Helpers.log("Subscribed to " + name + ".");
48
-
49
- for (var id in client.members) {
50
- Helpers.log(client.members[id].name, {
51
- "id" : "client-" + Helpers.safeID(id),
52
- "class" : "channel-" + name
53
- });
54
- }
55
- })
56
- .bind("pusher:member_added", function(client) {
57
- Helpers.log(client.info.name, {
58
- "id" : "client-" + Helpers.safeID(client.id),
59
- "class" : "channel-" + name
60
- });
61
- })
62
- .bind("pusher:member_removed", function(client) {
63
- var list = document.querySelector("ul"),
64
- item = list.querySelector("#client-" + Helpers.safeID(client.id));
65
-
66
- list.removeChild(item);
67
- })
68
- .bind("pusher:cache_miss", function(client) {
69
- Helpers.log("No cached event for " + name + ".");
70
- })
71
- .bind_global(function(event, message) {
72
- Helpers.log("Channel " + name + " received " + event + " event.");
73
- });
74
- },
75
-
76
- trigger: function(channel, event) {
77
- var channel = Pusher.instance.channel(channel);
78
-
79
- channel.trigger(event, {});
80
- },
81
-
82
- unsubscribe: function(name) {
83
- Pusher.instance.unsubscribe(name)
84
-
85
- Helpers.log("Unsubscribed from " + name + ".");
86
- }
87
- };
88
- </script>
89
-
90
- </body>
91
- </html>
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "sinatra"
4
- require "tilt/erb"
5
-
6
- module Sinatra
7
- class Application
8
- set(:root, proc { File.join(File.dirname(__FILE__), "application") })
9
- set(:views, proc { File.join(root, "views") })
10
-
11
- disable :logging
12
-
13
- get "/" do
14
- erb :index
15
- end
16
-
17
- post "/pusher/auth" do
18
- channel = Pusher[params[:channel_name]]
19
- response = channel.authenticate(params[:socket_id], channel_data)
20
-
21
- MultiJson.dump(response)
22
- end
23
-
24
- protected
25
-
26
- def channel_data
27
- return unless /^presence-/.match?(params[:channel_name])
28
-
29
- {
30
- user_id: params[:socket_id],
31
- user_info: { name: "Alan Turing" }
32
- }
33
- end
34
- end
35
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "capybara/rspec"
4
-
5
- Capybara.app = Sinatra::Application
6
- Capybara.server = :puma, { Silent: true }
7
- Capybara.default_driver = :selenium_chrome_headless
8
-
9
- # Ignore deprecation warning.
10
- Selenium::WebDriver.logger.ignore(:browser_options)
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ConnectHelpers
4
- def connect(options = {})
5
- visit "/"
6
-
7
- expect(page).to have_content("Client connected.")
8
-
9
- subscribe_to(options[:channel]) if options[:channel]
10
- end
11
-
12
- def connect_as(name, options = {})
13
- using_session(name) do
14
- connect(options)
15
- end
16
- end
17
- end
18
-
19
- RSpec.configure do |config|
20
- config.include(ConnectHelpers)
21
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module EventHelpers
4
- def have_event(event, options = {})
5
- have_css("li", text: "Channel #{options[:on]} received #{event} event.")
6
- end
7
- end
8
-
9
- RSpec.configure do |config|
10
- config.include(EventHelpers)
11
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module SubscriptionHelpers
4
- def subscribe_to(channel)
5
- page.execute_script("Helpers.subscribe(#{MultiJson.dump(channel)})")
6
-
7
- expect(page).to have_content("Subscribed to #{channel}.")
8
- end
9
-
10
- def subscribe_to_as(channel, name)
11
- using_session(name) do
12
- subscribe_to(channel)
13
- end
14
- end
15
-
16
- def unsubscribe_from(channel)
17
- page.execute_script("Helpers.unsubscribe(#{MultiJson.dump(channel)})")
18
-
19
- expect(page).to have_content("Unsubscribed from #{channel}.")
20
- end
21
-
22
- def unsubscribe_from_as(channel, name)
23
- using_session(name) do
24
- unsubscribe_from(channel)
25
- end
26
- end
27
- end
28
-
29
- RSpec.configure do |config|
30
- config.include(SubscriptionHelpers)
31
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module UserHelpers
4
- def user_id(name = nil)
5
- using_session(name) do
6
- return page.evaluate_script("Pusher.instance.connection.socket_id")
7
- end
8
- end
9
- end
10
-
11
- RSpec.configure do |config|
12
- config.include(UserHelpers)
13
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec::Matchers.define :have_configuration_option do |option|
4
- match do |configuration|
5
- configuration.respond_to?(option) &&
6
- configuration.respond_to?("#{option}=") &&
7
- (@default.nil? || configuration.public_send(option) == @default)
8
- end
9
-
10
- chain :with_default do |default|
11
- @default = default
12
- end
13
-
14
- failure_message do |_configuration|
15
- description = "expected configuration to have #{option.inspect} option"
16
- description << " with a default of #{@default.inspect}" unless @default.nil?
17
- description
18
- end
19
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "thin/server"
4
-
5
- RSpec.configure do |config|
6
- config.before(:each, type: :feature) do
7
- PusherFake.configuration.reset!
8
- PusherFake.configuration.web_options.tap do |options|
9
- Pusher.url = "http://PUSHER_API_KEY:PUSHER_API_SECRET@" \
10
- "#{options[:host]}:#{options[:port]}/apps/PUSHER_APP_ID"
11
- end
12
-
13
- @thread = Thread.new { PusherFake::Server.start }
14
- end
15
-
16
- config.after(:each, type: :feature) do
17
- @thread.exit
18
-
19
- PusherFake::Channel.reset
20
- end
21
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class WebhookHelper
4
- def self.events
5
- @events ||= []
6
- end
7
-
8
- def self.mutex
9
- @mutex ||= Mutex.new
10
- end
11
- end
12
-
13
- class WebhookEndpoint
14
- def self.call(environment)
15
- request = Rack::Request.new(environment)
16
- webhook = Pusher::WebHook.new(request)
17
-
18
- if webhook.valid?
19
- WebhookHelper.mutex.synchronize do
20
- WebhookHelper.events.concat(webhook.events)
21
- end
22
- end
23
-
24
- Rack::Response.new.finish
25
- end
26
- end
27
-
28
- thread = Thread.new do
29
- # Not explicitly requiring Thin::Server occasionally results in
30
- # Thin::Server.start not being defined.
31
- require "thin"
32
- require "thin/server"
33
-
34
- EventMachine.run do
35
- Thin::Logging.silent = true
36
- Thin::Server.start("0.0.0.0", 8082, WebhookEndpoint)
37
- end
38
- end
39
-
40
- at_exit { thread.exit }