pusher-fake 1.2.0 → 1.3.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 +4 -4
- data/lib/pusher-fake.rb +1 -1
- data/lib/pusher-fake/configuration.rb +2 -1
- data/lib/pusher-fake/server/application.rb +1 -1
- data/spec/features/api/channels_spec.rb +82 -0
- data/spec/features/api/users_spec.rb +34 -0
- data/spec/features/client/connect_spec.rb +9 -0
- data/spec/features/client/event_spec.rb +45 -0
- data/spec/features/client/presence_spec.rb +56 -0
- data/spec/features/client/subscribe_spec.rb +61 -0
- data/spec/features/server/event_spec.rb +120 -0
- data/spec/features/server/webhooks_spec.rb +64 -0
- data/spec/lib/pusher-fake/channel/presence_spec.rb +36 -30
- data/spec/lib/pusher-fake/channel/private_spec.rb +29 -25
- data/spec/lib/pusher-fake/channel/public_spec.rb +18 -18
- data/spec/lib/pusher-fake/channel_spec.rb +14 -14
- data/spec/lib/pusher-fake/configuration_spec.rb +6 -0
- data/spec/lib/pusher-fake/connection_spec.rb +38 -36
- data/spec/lib/pusher-fake/server/application_spec.rb +70 -70
- data/spec/lib/pusher-fake/server_spec.rb +42 -41
- data/spec/lib/pusher-fake/webhook_spec.rb +9 -7
- data/spec/lib/pusher_fake_spec.rb +5 -4
- data/spec/spec_helper.rb +3 -1
- data/{features → spec}/support/application.rb +0 -0
- data/{features/support/application/public/javascripts/vendor/pusher-2.2.2.js → spec/support/application/public/javascripts/vendor/pusher-2.2.4.js} +26 -19
- data/spec/support/application/views/index.erb +83 -0
- data/spec/support/capybara.rb +10 -0
- data/spec/support/coveralls.rb +0 -1
- data/spec/support/helpers/connect.rb +21 -0
- data/spec/support/helpers/event.rb +9 -0
- data/spec/support/helpers/subscription.rb +29 -0
- data/spec/support/helpers/user.rb +11 -0
- data/spec/support/{have_configuration_option_matcher.rb → matchers/have_configuration_option.rb} +0 -0
- data/spec/support/pusher-fake.rb +15 -0
- data/{features → spec}/support/webhooks.rb +5 -1
- metadata +51 -101
- data/features/channel.feature +0 -109
- data/features/channel_presence.feature +0 -27
- data/features/channel_subscribe.feature +0 -33
- data/features/channel_trigger.feature +0 -91
- data/features/channel_webhooks.feature +0 -40
- data/features/client_connect.feature +0 -8
- data/features/step_definitions/api_steps.rb +0 -40
- data/features/step_definitions/channel_steps.rb +0 -86
- data/features/step_definitions/client_steps.rb +0 -23
- data/features/step_definitions/event_steps.rb +0 -56
- data/features/step_definitions/navigation_steps.rb +0 -3
- data/features/step_definitions/presence_steps.rb +0 -6
- data/features/step_definitions/webhook_steps.rb +0 -21
- data/features/support/application/views/index.erb +0 -35
- data/features/support/coveralls.rb +0 -1
- data/features/support/environment.rb +0 -13
- data/features/support/pusher-fake.rb +0 -11
- data/features/support/timing.rb +0 -15
- data/features/user.feature +0 -14
@@ -0,0 +1,64 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
feature "Receiving event webhooks" do
|
4
|
+
let(:channel) { "room-1" }
|
5
|
+
let(:other_user) { "Bob" }
|
6
|
+
let(:presence_channel) { "presence-room-1" }
|
7
|
+
|
8
|
+
before do
|
9
|
+
connect
|
10
|
+
connect_as(other_user)
|
11
|
+
end
|
12
|
+
|
13
|
+
scenario "occupying a channel" do
|
14
|
+
subscribe_to(channel)
|
15
|
+
|
16
|
+
expect($events).to include_event("channel_occupied", "channel" => channel)
|
17
|
+
|
18
|
+
subscribe_to_as(channel, other_user)
|
19
|
+
|
20
|
+
expect($events.size).to eq(1)
|
21
|
+
end
|
22
|
+
|
23
|
+
scenario "vacating a channel" do
|
24
|
+
subscribe_to(channel)
|
25
|
+
subscribe_to_as(channel, other_user)
|
26
|
+
|
27
|
+
unsubscribe_from(channel)
|
28
|
+
|
29
|
+
expect($events.size).to eq(1)
|
30
|
+
|
31
|
+
unsubscribe_from_as(channel, other_user)
|
32
|
+
|
33
|
+
expect($events).to include_event("channel_vacated", "channel" => channel)
|
34
|
+
end
|
35
|
+
|
36
|
+
scenario "subscribing to a presence channel" do
|
37
|
+
subscribe_to(presence_channel)
|
38
|
+
|
39
|
+
expect($events).to include_event("member_added", "channel" => presence_channel, "user_id" => user_id)
|
40
|
+
|
41
|
+
subscribe_to_as(presence_channel, other_user)
|
42
|
+
|
43
|
+
expect($events).to include_event("member_added", "channel" => presence_channel, "user_id" => user_id(other_user))
|
44
|
+
end
|
45
|
+
|
46
|
+
scenario "unsubscribing from a presence channel" do
|
47
|
+
subscribe_to(presence_channel)
|
48
|
+
subscribe_to_as(presence_channel, other_user)
|
49
|
+
|
50
|
+
unsubscribe_from(presence_channel)
|
51
|
+
|
52
|
+
expect($events).to include_event("member_added", "channel" => presence_channel, "user_id" => user_id)
|
53
|
+
|
54
|
+
unsubscribe_from_as(presence_channel, other_user)
|
55
|
+
|
56
|
+
expect($events).to include_event("member_added", "channel" => presence_channel, "user_id" => user_id(other_user))
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def include_event(event, options = {})
|
62
|
+
include(options.merge("name" => event))
|
63
|
+
end
|
64
|
+
end
|
@@ -20,8 +20,8 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
20
20
|
let(:data) { { auth: authentication, channel_data: MultiJson.dump(channel_data) } }
|
21
21
|
let(:name) { "name" }
|
22
22
|
let(:user_id) { "1234" }
|
23
|
-
let(:connection) {
|
24
|
-
let(:connections) {
|
23
|
+
let(:connection) { double(:connection, emit: nil) }
|
24
|
+
let(:connections) { double(:connections, push: nil, length: 0) }
|
25
25
|
let(:channel_data) { { user_id: user_id } }
|
26
26
|
let(:authentication) { "auth" }
|
27
27
|
let(:subscription_data) { { presence: { hash: {}, count: 1 } } }
|
@@ -29,13 +29,15 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
29
29
|
subject { PusherFake::Channel::Presence.new(name) }
|
30
30
|
|
31
31
|
before do
|
32
|
-
PusherFake::Webhook.
|
33
|
-
MultiJson.
|
34
|
-
subject.
|
32
|
+
allow(PusherFake::Webhook).to receive(:trigger)
|
33
|
+
allow(MultiJson).to receive(:load).and_return(channel_data)
|
34
|
+
allow(subject).to receive(:connections).and_return(connections)
|
35
|
+
allow(subject).to receive(:emit).and_return(nil)
|
36
|
+
allow(subject).to receive(:subscription_data).and_return(subscription_data)
|
35
37
|
end
|
36
38
|
|
37
39
|
it "authorizes the connection" do
|
38
|
-
subject.
|
40
|
+
allow(subject).to receive(:authorized?).and_return(nil)
|
39
41
|
|
40
42
|
subject.add(connection, data)
|
41
43
|
|
@@ -43,7 +45,7 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
43
45
|
end
|
44
46
|
|
45
47
|
it "parses the channel_data when authorized" do
|
46
|
-
subject.
|
48
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
47
49
|
|
48
50
|
subject.add(connection, data)
|
49
51
|
|
@@ -51,7 +53,7 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
51
53
|
end
|
52
54
|
|
53
55
|
it "assigns the parsed channel_data to the members hash for the current connection" do
|
54
|
-
subject.
|
56
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
55
57
|
|
56
58
|
subject.add(connection, data)
|
57
59
|
|
@@ -59,7 +61,7 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
59
61
|
end
|
60
62
|
|
61
63
|
it "notifies the channel of the new member when authorized" do
|
62
|
-
subject.
|
64
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
63
65
|
|
64
66
|
subject.add(connection, data)
|
65
67
|
|
@@ -67,7 +69,7 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
67
69
|
end
|
68
70
|
|
69
71
|
it "successfully subscribes the connection when authorized" do
|
70
|
-
subject.
|
72
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
71
73
|
|
72
74
|
subject.add(connection, data)
|
73
75
|
|
@@ -76,7 +78,7 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
76
78
|
end
|
77
79
|
|
78
80
|
it "adds the connection to the channel when authorized" do
|
79
|
-
subject.
|
81
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
80
82
|
|
81
83
|
subject.add(connection, data)
|
82
84
|
|
@@ -84,8 +86,8 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
84
86
|
end
|
85
87
|
|
86
88
|
it "triggers channel occupied webhook for the first connection added when authorized" do
|
87
|
-
subject.
|
88
|
-
subject.
|
89
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
90
|
+
allow(subject).to receive(:connections).and_call_original
|
89
91
|
|
90
92
|
2.times { subject.add(connection, data) }
|
91
93
|
|
@@ -93,7 +95,7 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
93
95
|
end
|
94
96
|
|
95
97
|
it "triggers the member added webhook when authorized" do
|
96
|
-
subject.
|
98
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
97
99
|
|
98
100
|
subject.add(connection, data)
|
99
101
|
|
@@ -101,7 +103,7 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
101
103
|
end
|
102
104
|
|
103
105
|
it "unsuccessfully subscribes the connection when not authorized" do
|
104
|
-
subject.
|
106
|
+
allow(subject).to receive(:authorized?).and_return(false)
|
105
107
|
|
106
108
|
subject.add(connection, data)
|
107
109
|
|
@@ -109,35 +111,37 @@ describe PusherFake::Channel::Presence, "#add" do
|
|
109
111
|
end
|
110
112
|
|
111
113
|
it "does not trigger channel occupied webhook when not authorized" do
|
112
|
-
subject.
|
113
|
-
subject.
|
114
|
+
allow(subject).to receive(:authorized?).and_return(false)
|
115
|
+
allow(subject).to receive(:connections).and_call_original
|
114
116
|
|
115
117
|
2.times { subject.add(connection, data) }
|
116
118
|
|
117
|
-
expect(PusherFake::Webhook).
|
119
|
+
expect(PusherFake::Webhook).to_not have_received(:trigger)
|
118
120
|
end
|
119
121
|
|
120
122
|
it "does not trigger the member added webhook when not authorized" do
|
121
|
-
subject.
|
123
|
+
allow(subject).to receive(:authorized?).and_return(false)
|
122
124
|
|
123
125
|
subject.add(connection, data)
|
124
126
|
|
125
|
-
expect(PusherFake::Webhook).
|
127
|
+
expect(PusherFake::Webhook).to_not have_received(:trigger)
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
129
131
|
describe PusherFake::Channel::Presence, "#remove" do
|
130
132
|
let(:name) { "name" }
|
131
133
|
let(:user_id) { "1234" }
|
132
|
-
let(:connection) {
|
134
|
+
let(:connection) { double }
|
133
135
|
let(:channel_data) { { user_id: user_id } }
|
134
136
|
|
135
137
|
subject { PusherFake::Channel::Presence.new(name) }
|
136
138
|
|
137
139
|
before do
|
138
|
-
PusherFake::Webhook.
|
140
|
+
allow(PusherFake::Webhook).to receive(:trigger)
|
141
|
+
allow(subject).to receive(:connections).and_return([connection])
|
142
|
+
allow(subject).to receive(:emit).and_return(nil)
|
143
|
+
|
139
144
|
subject.members[connection] = channel_data
|
140
|
-
subject.stubs(connections: [connection], emit: nil)
|
141
145
|
end
|
142
146
|
|
143
147
|
it "removes the connection from the channel" do
|
@@ -168,13 +172,15 @@ end
|
|
168
172
|
describe PusherFake::Channel::Presence, "#remove, for an unsubscribed connection" do
|
169
173
|
let(:name) { "name" }
|
170
174
|
let(:user_id) { "1234" }
|
171
|
-
let(:connection) {
|
175
|
+
let(:connection) { double }
|
172
176
|
let(:channel_data) { { user_id: user_id } }
|
173
177
|
|
174
178
|
subject { PusherFake::Channel::Presence.new(name) }
|
175
179
|
|
176
180
|
before do
|
177
|
-
subject.
|
181
|
+
allow(subject).to receive(:connections).and_return([])
|
182
|
+
allow(subject).to receive(:emit).and_return(nil)
|
183
|
+
allow(subject).to receive(:trigger).and_return(nil)
|
178
184
|
end
|
179
185
|
|
180
186
|
it "does not raise an error" do
|
@@ -186,25 +192,25 @@ describe PusherFake::Channel::Presence, "#remove, for an unsubscribed connection
|
|
186
192
|
it "does not trigger an event" do
|
187
193
|
subject.remove(connection)
|
188
194
|
|
189
|
-
expect(
|
195
|
+
expect(subject).to_not have_received(:trigger).with("member_removed", channel: name, user_id: user_id)
|
190
196
|
end
|
191
197
|
|
192
198
|
it "does not emit an event" do
|
193
199
|
subject.remove(connection)
|
194
200
|
|
195
|
-
expect(subject).
|
201
|
+
expect(subject).to_not have_received(:emit).with("pusher_internal:member_removed", channel_data)
|
196
202
|
end
|
197
203
|
end
|
198
204
|
|
199
205
|
describe PusherFake::Channel::Presence, "#subscription_data" do
|
200
206
|
let(:other) { { user_id: 2, name: "Beau" } }
|
201
207
|
let(:member) { { user_id: 1, name: "Bob" } }
|
202
|
-
let(:members) { {
|
208
|
+
let(:members) { { double => member } }
|
203
209
|
|
204
210
|
subject { PusherFake::Channel::Presence.new("name") }
|
205
211
|
|
206
212
|
before do
|
207
|
-
subject.
|
213
|
+
allow(subject).to receive(:members).and_return(members)
|
208
214
|
end
|
209
215
|
|
210
216
|
it "returns hash with presence information" do
|
@@ -219,7 +225,7 @@ describe PusherFake::Channel::Presence, "#subscription_data" do
|
|
219
225
|
end
|
220
226
|
|
221
227
|
it "handles multiple members" do
|
222
|
-
members[
|
228
|
+
members[double] = other
|
223
229
|
|
224
230
|
data = subject.subscription_data
|
225
231
|
|
@@ -11,19 +11,19 @@ end
|
|
11
11
|
describe PusherFake::Channel::Private, "#add" do
|
12
12
|
let(:data) { { auth: authentication } }
|
13
13
|
let(:name) { "name" }
|
14
|
-
let(:connection) {
|
15
|
-
let(:connections) {
|
14
|
+
let(:connection) { double(:connection, emit: nil) }
|
15
|
+
let(:connections) { double(:connections, push: nil, length: 0) }
|
16
16
|
let(:authentication) { "auth" }
|
17
17
|
|
18
18
|
subject { PusherFake::Channel::Private.new(name) }
|
19
19
|
|
20
20
|
before do
|
21
|
-
PusherFake::Webhook.
|
22
|
-
subject.
|
21
|
+
allow(PusherFake::Webhook).to receive(:trigger)
|
22
|
+
allow(subject).to receive(:connections).and_return(connections)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "authorizes the connection" do
|
26
|
-
subject.
|
26
|
+
allow(subject).to receive(:authorized?).and_return(nil)
|
27
27
|
|
28
28
|
subject.add(connection, data)
|
29
29
|
|
@@ -31,7 +31,7 @@ describe PusherFake::Channel::Private, "#add" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "adds the connection to the channel when authorized" do
|
34
|
-
subject.
|
34
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
35
35
|
|
36
36
|
subject.add(connection, data)
|
37
37
|
|
@@ -39,7 +39,7 @@ describe PusherFake::Channel::Private, "#add" do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "successfully subscribes the connection when authorized" do
|
42
|
-
subject.
|
42
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
43
43
|
|
44
44
|
subject.add(connection, data)
|
45
45
|
|
@@ -47,8 +47,8 @@ describe PusherFake::Channel::Private, "#add" do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
it "triggers channel occupied webhook for the first connection added when authorized" do
|
50
|
-
subject.
|
51
|
-
subject.
|
50
|
+
allow(subject).to receive(:authorized?).and_return(true)
|
51
|
+
allow(subject).to receive(:connections).and_call_original
|
52
52
|
|
53
53
|
2.times { subject.add(connection, data) }
|
54
54
|
|
@@ -56,7 +56,7 @@ describe PusherFake::Channel::Private, "#add" do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "unsuccessfully subscribes the connection when not authorized" do
|
59
|
-
subject.
|
59
|
+
allow(subject).to receive(:authorized?).and_return(false)
|
60
60
|
|
61
61
|
subject.add(connection, data)
|
62
62
|
|
@@ -64,34 +64,36 @@ describe PusherFake::Channel::Private, "#add" do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it "does not trigger channel occupied webhook when not authorized" do
|
67
|
-
subject.
|
68
|
-
subject.
|
67
|
+
allow(subject).to receive(:authorized?).and_return(false)
|
68
|
+
allow(subject).to receive(:connections).and_call_original
|
69
69
|
|
70
70
|
2.times { subject.add(connection, data) }
|
71
71
|
|
72
|
-
expect(PusherFake::Webhook).
|
72
|
+
expect(PusherFake::Webhook).to_not have_received(:trigger)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
describe PusherFake::Channel::Private, "#authentication_for" do
|
77
77
|
let(:id) { "1234" }
|
78
78
|
let(:name) { "private-channel" }
|
79
|
+
let(:digest) { double(:digest) }
|
79
80
|
let(:string) { [id, name].join(":") }
|
80
81
|
let(:signature) { "signature" }
|
81
|
-
let(:configuration) {
|
82
|
+
let(:configuration) { double(:configuration, key: "key", secret: "secret") }
|
82
83
|
|
83
84
|
subject { PusherFake::Channel::Private.new(name) }
|
84
85
|
|
85
86
|
before do
|
86
|
-
PusherFake.
|
87
|
-
OpenSSL::HMAC.
|
87
|
+
allow(PusherFake).to receive(:configuration).and_return(configuration)
|
88
|
+
allow(OpenSSL::HMAC).to receive(:hexdigest).and_return(signature)
|
89
|
+
allow(OpenSSL::Digest::SHA256).to receive(:new).and_return(digest)
|
88
90
|
end
|
89
91
|
|
90
92
|
it "generates a signature" do
|
91
93
|
subject.authentication_for(id)
|
92
94
|
|
93
95
|
expect(OpenSSL::HMAC).to have_received(:hexdigest)
|
94
|
-
.with(
|
96
|
+
.with(digest, configuration.secret, string)
|
95
97
|
end
|
96
98
|
|
97
99
|
it "returns the authentication string" do
|
@@ -104,23 +106,25 @@ end
|
|
104
106
|
describe PusherFake::Channel::Private, "#authentication_for, with channel data" do
|
105
107
|
let(:id) { "1234" }
|
106
108
|
let(:name) { "private-channel" }
|
109
|
+
let(:digest) { double(:digest) }
|
107
110
|
let(:string) { [id, name, channel_data].join(":") }
|
108
111
|
let(:signature) { "signature" }
|
109
112
|
let(:channel_data) { "{}" }
|
110
|
-
let(:configuration) {
|
113
|
+
let(:configuration) { double(:configuration, key: "key", secret: "secret") }
|
111
114
|
|
112
115
|
subject { PusherFake::Channel::Private.new(name) }
|
113
116
|
|
114
117
|
before do
|
115
|
-
PusherFake.
|
116
|
-
OpenSSL::HMAC.
|
118
|
+
allow(PusherFake).to receive(:configuration).and_return(configuration)
|
119
|
+
allow(OpenSSL::HMAC).to receive(:hexdigest).and_return(signature)
|
120
|
+
allow(OpenSSL::Digest::SHA256).to receive(:new).and_return(digest)
|
117
121
|
end
|
118
122
|
|
119
123
|
it "generates a signature" do
|
120
124
|
subject.authentication_for(id, channel_data)
|
121
125
|
|
122
126
|
expect(OpenSSL::HMAC).to have_received(:hexdigest)
|
123
|
-
.with(
|
127
|
+
.with(digest, configuration.secret, string)
|
124
128
|
end
|
125
129
|
|
126
130
|
it "returns the authentication string" do
|
@@ -133,14 +137,14 @@ end
|
|
133
137
|
describe PusherFake::Channel::Private, "#authorized?" do
|
134
138
|
let(:data) { { auth: authentication, channel_data: channel_data } }
|
135
139
|
let(:name) { "private-channel" }
|
136
|
-
let(:connection) {
|
140
|
+
let(:connection) { double(:connection, id: "1") }
|
137
141
|
let(:channel_data) { "{}" }
|
138
142
|
let(:authentication) { "authentication" }
|
139
143
|
|
140
144
|
subject { PusherFake::Channel::Private.new(name) }
|
141
145
|
|
142
146
|
before do
|
143
|
-
subject.
|
147
|
+
allow(subject).to receive(:authentication_for)
|
144
148
|
end
|
145
149
|
|
146
150
|
it "generates authentication for the connection ID" do
|
@@ -150,13 +154,13 @@ describe PusherFake::Channel::Private, "#authorized?" do
|
|
150
154
|
end
|
151
155
|
|
152
156
|
it "returns true if the authentication matches" do
|
153
|
-
subject.
|
157
|
+
allow(subject).to receive(:authentication_for).and_return(authentication)
|
154
158
|
|
155
159
|
expect(subject).to be_authorized(connection, data)
|
156
160
|
end
|
157
161
|
|
158
162
|
it "returns false if the authentication matches" do
|
159
|
-
subject.
|
163
|
+
allow(subject).to receive(:authentication_for).and_return("")
|
160
164
|
|
161
165
|
expect(subject).to_not be_authorized(connection, data)
|
162
166
|
end
|
@@ -20,14 +20,14 @@ end
|
|
20
20
|
|
21
21
|
describe PusherFake::Channel, "#add" do
|
22
22
|
let(:name) { "name" }
|
23
|
-
let(:connection) {
|
24
|
-
let(:connections) {
|
23
|
+
let(:connection) { double(:connection, emit: nil) }
|
24
|
+
let(:connections) { double(:connections, push: nil, length: 0) }
|
25
25
|
|
26
26
|
subject { PusherFake::Channel::Public.new(name) }
|
27
27
|
|
28
28
|
before do
|
29
|
-
PusherFake::Webhook.
|
30
|
-
subject.
|
29
|
+
allow(PusherFake::Webhook).to receive(:trigger)
|
30
|
+
allow(subject).to receive(:connections).and_return(connections)
|
31
31
|
end
|
32
32
|
|
33
33
|
it "adds the connection" do
|
@@ -43,7 +43,7 @@ describe PusherFake::Channel, "#add" do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
it "triggers channel occupied webhook for the first connection added" do
|
46
|
-
subject.
|
46
|
+
allow(subject).to receive(:connections).and_call_original
|
47
47
|
|
48
48
|
2.times { subject.add(connection) }
|
49
49
|
|
@@ -52,17 +52,17 @@ describe PusherFake::Channel, "#add" do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
describe PusherFake::Channel, "#emit" do
|
55
|
-
let(:data) {
|
55
|
+
let(:data) { double }
|
56
56
|
let(:name) { "name" }
|
57
57
|
let(:event) { "event" }
|
58
58
|
let(:connections) { [connection_1, connection_2] }
|
59
|
-
let(:connection_1) {
|
60
|
-
let(:connection_2) {
|
59
|
+
let(:connection_1) { double(:connection, emit: nil, id: "1") }
|
60
|
+
let(:connection_2) { double(:connection, emit: nil, id: "2") }
|
61
61
|
|
62
62
|
subject { PusherFake::Channel::Public.new(name) }
|
63
63
|
|
64
64
|
before do
|
65
|
-
subject.
|
65
|
+
allow(subject).to receive(:connections).and_return(connections)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "emits the event for each connection in the channel" do
|
@@ -76,23 +76,23 @@ describe PusherFake::Channel, "#emit" do
|
|
76
76
|
subject.emit(event, data, socket_id: connection_2.id)
|
77
77
|
|
78
78
|
expect(connection_1).to have_received(:emit).with(event, data, name)
|
79
|
-
expect(connection_2).
|
79
|
+
expect(connection_2).to_not have_received(:emit)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
describe PusherFake::Channel, "#includes?" do
|
84
|
-
let(:connection) {
|
84
|
+
let(:connection) { double }
|
85
85
|
|
86
86
|
subject { PusherFake::Channel::Public.new("name") }
|
87
87
|
|
88
88
|
it "returns true if the connection is in the channel" do
|
89
|
-
subject.
|
89
|
+
allow(subject).to receive(:connections).and_return([connection])
|
90
90
|
|
91
91
|
expect(subject).to be_includes(connection)
|
92
92
|
end
|
93
93
|
|
94
94
|
it "returns false if the connection is not in the channel" do
|
95
|
-
subject.
|
95
|
+
allow(subject).to receive(:connections).and_return([])
|
96
96
|
|
97
97
|
expect(subject).to_not be_includes(connection)
|
98
98
|
end
|
@@ -100,14 +100,14 @@ end
|
|
100
100
|
|
101
101
|
describe PusherFake::Channel, "#remove" do
|
102
102
|
let(:name) { "name" }
|
103
|
-
let(:connection_1) {
|
104
|
-
let(:connection_2) {
|
103
|
+
let(:connection_1) { double }
|
104
|
+
let(:connection_2) { double }
|
105
105
|
|
106
106
|
subject { PusherFake::Channel::Public.new(name) }
|
107
107
|
|
108
108
|
before do
|
109
|
-
subject.
|
110
|
-
PusherFake::Webhook.
|
109
|
+
allow(subject).to receive(:connections).and_return([connection_1, connection_2])
|
110
|
+
allow(PusherFake::Webhook).to receive(:trigger)
|
111
111
|
end
|
112
112
|
|
113
113
|
it "removes the connection from the channel" do
|
@@ -119,7 +119,7 @@ describe PusherFake::Channel, "#remove" do
|
|
119
119
|
it "triggers channel vacated webhook when all connections are removed" do
|
120
120
|
subject.remove(connection_1)
|
121
121
|
|
122
|
-
expect(PusherFake::Webhook).
|
122
|
+
expect(PusherFake::Webhook).to_not have_received(:trigger)
|
123
123
|
|
124
124
|
subject.remove(connection_2)
|
125
125
|
|