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.
- checksums.yaml +4 -4
- data/lib/pusher-fake/channel/presence.rb +1 -1
- data/lib/pusher-fake/channel/public.rb +32 -0
- data/lib/pusher-fake/server/chain_trap_handlers.rb +24 -0
- data/lib/pusher-fake/server.rb +10 -9
- data/lib/pusher-fake.rb +1 -1
- metadata +28 -90
- 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 -69
- data/spec/features/server/event_spec.rb +0 -122
- data/spec/features/server/webhooks_spec.rb +0 -88
- 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 -148
- 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 -18
- data/spec/support/application/public/javascripts/vendor/polyfill.min.js +0 -1
- data/spec/support/application/public/javascripts/vendor/pusher-7.0.0.js +0 -4565
- data/spec/support/application/views/index.erb +0 -88
- data/spec/support/application.rb +0 -35
- data/spec/support/capybara.rb +0 -7
- data/spec/support/coveralls.rb +0 -9
- 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
@@ -1,148 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe PusherFake::Channel::Public do
|
6
|
-
subject { described_class }
|
7
|
-
|
8
|
-
let(:name) { "channel" }
|
9
|
-
|
10
|
-
it "assigns the provided name" do
|
11
|
-
channel = subject.new(name)
|
12
|
-
|
13
|
-
expect(channel.name).to eq(name)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "creates an empty connections array" do
|
17
|
-
channel = subject.new(name)
|
18
|
-
|
19
|
-
expect(channel.connections).to eq([])
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe PusherFake::Channel, "#add" do
|
24
|
-
subject { PusherFake::Channel::Public.new(name) }
|
25
|
-
|
26
|
-
let(:name) { "name" }
|
27
|
-
let(:connection) { instance_double(PusherFake::Connection, emit: nil) }
|
28
|
-
let(:connections) { instance_double(Array, push: nil, length: 0) }
|
29
|
-
|
30
|
-
before do
|
31
|
-
allow(PusherFake::Webhook).to receive(:trigger)
|
32
|
-
allow(subject).to receive(:connections).and_return(connections)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "adds the connection" do
|
36
|
-
subject.add(connection)
|
37
|
-
|
38
|
-
expect(connections).to have_received(:push).with(connection)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "successfully subscribes the connection" do
|
42
|
-
subject.add(connection)
|
43
|
-
|
44
|
-
expect(connection).to have_received(:emit)
|
45
|
-
.with("pusher_internal:subscription_succeeded", {}, subject.name)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "triggers channel occupied webhook for the first connection added" do
|
49
|
-
allow(subject).to receive(:connections).and_call_original
|
50
|
-
|
51
|
-
2.times { subject.add(connection) }
|
52
|
-
|
53
|
-
expect(PusherFake::Webhook).to have_received(:trigger)
|
54
|
-
.with("channel_occupied", channel: name).once
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe PusherFake::Channel, "#emit" do
|
59
|
-
subject { PusherFake::Channel::Public.new(name) }
|
60
|
-
|
61
|
-
let(:data) { double }
|
62
|
-
let(:name) { "name" }
|
63
|
-
let(:event) { "event" }
|
64
|
-
let(:connections) { [connection_1, connection_2] }
|
65
|
-
|
66
|
-
let(:connection_1) do
|
67
|
-
instance_double(PusherFake::Connection, emit: nil, id: "1")
|
68
|
-
end
|
69
|
-
|
70
|
-
let(:connection_2) do
|
71
|
-
instance_double(PusherFake::Connection, emit: nil, id: "2")
|
72
|
-
end
|
73
|
-
|
74
|
-
before do
|
75
|
-
allow(subject).to receive(:connections).and_return(connections)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "emits the event for each connection in the channel" do
|
79
|
-
subject.emit(event, data)
|
80
|
-
|
81
|
-
expect(connection_1).to have_received(:emit).with(event, data, name)
|
82
|
-
expect(connection_2).to have_received(:emit).with(event, data, name)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "ignores connection if socket_id matches the connections ID" do
|
86
|
-
subject.emit(event, data, socket_id: connection_2.id)
|
87
|
-
|
88
|
-
expect(connection_1).to have_received(:emit).with(event, data, name)
|
89
|
-
expect(connection_2).not_to have_received(:emit)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe PusherFake::Channel, "#includes?" do
|
94
|
-
subject { PusherFake::Channel::Public.new("name") }
|
95
|
-
|
96
|
-
let(:connection) { double }
|
97
|
-
|
98
|
-
it "returns true if the connection is in the channel" do
|
99
|
-
allow(subject).to receive(:connections).and_return([connection])
|
100
|
-
|
101
|
-
expect(subject).to be_includes(connection)
|
102
|
-
end
|
103
|
-
|
104
|
-
it "returns false if the connection is not in the channel" do
|
105
|
-
allow(subject).to receive(:connections).and_return([])
|
106
|
-
|
107
|
-
expect(subject).not_to be_includes(connection)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe PusherFake::Channel, "#remove" do
|
112
|
-
subject { PusherFake::Channel::Public.new(name) }
|
113
|
-
|
114
|
-
let(:name) { "name" }
|
115
|
-
let(:connection_1) { double }
|
116
|
-
let(:connection_2) { double }
|
117
|
-
|
118
|
-
before do
|
119
|
-
allow(PusherFake::Webhook).to receive(:trigger)
|
120
|
-
allow(subject).to receive(:connections)
|
121
|
-
.and_return([connection_1, connection_2])
|
122
|
-
end
|
123
|
-
|
124
|
-
it "removes the connection from the channel" do
|
125
|
-
subject.remove(connection_1)
|
126
|
-
|
127
|
-
expect(subject.connections).not_to include(connection_1)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "triggers channel vacated webhook when all connections are removed" do
|
131
|
-
subject.remove(connection_1)
|
132
|
-
|
133
|
-
expect(PusherFake::Webhook).not_to have_received(:trigger)
|
134
|
-
|
135
|
-
subject.remove(connection_2)
|
136
|
-
|
137
|
-
expect(PusherFake::Webhook).to have_received(:trigger)
|
138
|
-
.with("channel_vacated", channel: name).once
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe PusherFake::Channel::Public, "#subscription_data" do
|
143
|
-
subject { described_class.new("name") }
|
144
|
-
|
145
|
-
it "returns an empty hash" do
|
146
|
-
expect(subject.subscription_data).to eq({})
|
147
|
-
end
|
148
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe PusherFake::Channel, ".factory" do
|
6
|
-
shared_examples_for "a channel factory" do
|
7
|
-
subject { described_class }
|
8
|
-
|
9
|
-
let(:channel) { double }
|
10
|
-
|
11
|
-
before do
|
12
|
-
allow(channel_class).to receive(:new).and_return(channel)
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
subject.reset
|
17
|
-
end
|
18
|
-
|
19
|
-
it "caches the channel" do
|
20
|
-
allow(channel_class).to receive(:new).and_call_original
|
21
|
-
|
22
|
-
factory_one = subject.factory(name)
|
23
|
-
factory_two = subject.factory(name)
|
24
|
-
|
25
|
-
expect(factory_one).to eq(factory_two)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "creates the channel by name" do
|
29
|
-
subject.factory(name)
|
30
|
-
|
31
|
-
expect(channel_class).to have_received(:new).with(name)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "returns the channel instance" do
|
35
|
-
factory = subject.factory(name)
|
36
|
-
|
37
|
-
expect(factory).to eq(channel)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "with a public channel" do
|
42
|
-
let(:name) { "channel" }
|
43
|
-
let(:channel_class) { PusherFake::Channel::Public }
|
44
|
-
|
45
|
-
it_behaves_like "a channel factory"
|
46
|
-
end
|
47
|
-
|
48
|
-
context "with a private channel" do
|
49
|
-
let(:name) { "private-channel" }
|
50
|
-
let(:channel_class) { PusherFake::Channel::Private }
|
51
|
-
|
52
|
-
it_behaves_like "a channel factory"
|
53
|
-
end
|
54
|
-
|
55
|
-
context "with a presence channel" do
|
56
|
-
let(:name) { "presence-channel" }
|
57
|
-
let(:channel_class) { PusherFake::Channel::Presence }
|
58
|
-
|
59
|
-
it_behaves_like "a channel factory"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe PusherFake::Channel, ".remove" do
|
64
|
-
subject { described_class }
|
65
|
-
|
66
|
-
let(:channels) { { channel_1: channel_1, channel_2: channel_2 } }
|
67
|
-
let(:connection) { double }
|
68
|
-
|
69
|
-
let(:channel_1) do
|
70
|
-
instance_double(PusherFake::Channel::Public,
|
71
|
-
remove: nil,
|
72
|
-
connections: instance_double(Array, empty?: true))
|
73
|
-
end
|
74
|
-
|
75
|
-
let(:channel_2) do
|
76
|
-
instance_double(PusherFake::Channel::Public,
|
77
|
-
remove: nil,
|
78
|
-
connections: instance_double(Array, empty?: false))
|
79
|
-
end
|
80
|
-
|
81
|
-
before do
|
82
|
-
allow(subject).to receive(:channels).and_return(channels)
|
83
|
-
end
|
84
|
-
|
85
|
-
it "removes the connection from all channels" do
|
86
|
-
subject.remove(connection)
|
87
|
-
|
88
|
-
expect(channel_1).to have_received(:remove).with(connection)
|
89
|
-
expect(channel_2).to have_received(:remove).with(connection)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "deletes a channel with no connections remaining" do
|
93
|
-
subject.remove(connection)
|
94
|
-
|
95
|
-
expect(channels).not_to have_key(:channel_1)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "does not delete a channel with connections remaining" do
|
99
|
-
subject.remove(connection)
|
100
|
-
|
101
|
-
expect(channels).to have_key(:channel_2)
|
102
|
-
end
|
103
|
-
|
104
|
-
it "handles channels not being defined" do
|
105
|
-
allow(subject).to receive(:channels).and_return(nil)
|
106
|
-
|
107
|
-
expect do
|
108
|
-
subject.remove(connection)
|
109
|
-
end.not_to raise_error
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe PusherFake::Channel, ".reset" do
|
114
|
-
subject { described_class }
|
115
|
-
|
116
|
-
it "empties the channel cache" do
|
117
|
-
subject.factory("example")
|
118
|
-
subject.reset
|
119
|
-
|
120
|
-
expect(subject.channels).to eq({})
|
121
|
-
end
|
122
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
describe PusherFake::Configuration do
|
6
|
-
it do
|
7
|
-
expect(subject).to have_configuration_option(:disable_stats)
|
8
|
-
.with_default(true)
|
9
|
-
end
|
10
|
-
|
11
|
-
it do
|
12
|
-
expect(subject).to have_configuration_option(:key)
|
13
|
-
.with_default("PUSHER_API_KEY")
|
14
|
-
end
|
15
|
-
|
16
|
-
it do
|
17
|
-
expect(subject).to have_configuration_option(:logger)
|
18
|
-
.with_default($stdout.to_io)
|
19
|
-
end
|
20
|
-
|
21
|
-
it do
|
22
|
-
expect(subject).to have_configuration_option(:verbose)
|
23
|
-
.with_default(false)
|
24
|
-
end
|
25
|
-
|
26
|
-
it do
|
27
|
-
expect(subject).to have_configuration_option(:webhooks)
|
28
|
-
.with_default([])
|
29
|
-
end
|
30
|
-
|
31
|
-
it do
|
32
|
-
expect(subject).to have_configuration_option(:app_id)
|
33
|
-
.with_default("PUSHER_APP_ID")
|
34
|
-
end
|
35
|
-
|
36
|
-
it do
|
37
|
-
expect(subject).to have_configuration_option(:secret)
|
38
|
-
.with_default("PUSHER_API_SECRET")
|
39
|
-
end
|
40
|
-
|
41
|
-
it "has configuration option :socket_options" do
|
42
|
-
expect(subject.socket_options).to be_a(Hash)
|
43
|
-
expect(subject.socket_options[:host]).to eq("127.0.0.1")
|
44
|
-
expect(subject.socket_options[:port]).to be_a(Integer)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "has configuration option :web_options" do
|
48
|
-
expect(subject.web_options).to be_a(Hash)
|
49
|
-
expect(subject.web_options[:host]).to eq("127.0.0.1")
|
50
|
-
expect(subject.web_options[:port]).to be_a(Integer)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "defaults socket and web ports to different values" do
|
54
|
-
expect(subject.socket_options[:port]).not_to eq(subject.web_options[:port])
|
55
|
-
end
|
56
|
-
|
57
|
-
context "with StringIO as standard out" do
|
58
|
-
let(:io) { StringIO.new }
|
59
|
-
|
60
|
-
around do |example|
|
61
|
-
original = $stdout
|
62
|
-
$stdout = io # rubocop:disable RSpec/ExpectOutput
|
63
|
-
|
64
|
-
example.run
|
65
|
-
|
66
|
-
$stdout = original # rubocop:disable RSpec/ExpectOutput
|
67
|
-
end
|
68
|
-
|
69
|
-
it "assigns standard out to the logger" do
|
70
|
-
subject.reset!
|
71
|
-
|
72
|
-
expect(subject.logger).to eq(io)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe PusherFake::Configuration, "#app_id=" do
|
78
|
-
subject { described_class.new }
|
79
|
-
|
80
|
-
it "converts value to a string" do
|
81
|
-
subject.app_id = 1_337
|
82
|
-
|
83
|
-
expect(subject.app_id).to eq("1337")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe PusherFake::Configuration, "#to_options" do
|
88
|
-
it "includes disable_stats as disableStats" do
|
89
|
-
options = subject.to_options
|
90
|
-
|
91
|
-
expect(options).to include(disableStats: subject.disable_stats)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "includes the socket host as wsHost" do
|
95
|
-
options = subject.to_options
|
96
|
-
|
97
|
-
expect(options).to include(wsHost: subject.socket_options[:host])
|
98
|
-
end
|
99
|
-
|
100
|
-
it "includes the socket port as wsPort" do
|
101
|
-
options = subject.to_options
|
102
|
-
|
103
|
-
expect(options).to include(wsPort: subject.socket_options[:port])
|
104
|
-
end
|
105
|
-
|
106
|
-
it "includes the cluster by default" do
|
107
|
-
options = subject.to_options
|
108
|
-
|
109
|
-
expect(options).to include(cluster: "us-east-1")
|
110
|
-
end
|
111
|
-
|
112
|
-
it "disables the forceTLS option" do
|
113
|
-
options = subject.to_options
|
114
|
-
|
115
|
-
expect(options).to include(forceTLS: false)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "supports passing custom options" do
|
119
|
-
options = subject.to_options(custom: "option")
|
120
|
-
|
121
|
-
expect(options).to include(custom: "option")
|
122
|
-
end
|
123
|
-
end
|