pusher-fake 0.13.0 → 0.14.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/features/step_definitions/api_steps.rb +11 -9
- data/features/step_definitions/channel_steps.rb +6 -3
- data/features/step_definitions/client_steps.rb +4 -2
- data/features/step_definitions/event_steps.rb +4 -2
- data/features/step_definitions/presence_steps.rb +2 -2
- data/features/step_definitions/webhook_steps.rb +1 -1
- data/features/support/environment.rb +6 -0
- data/features/support/webhooks.rb +1 -1
- data/lib/pusher-fake.rb +8 -2
- data/lib/pusher-fake/channel/presence.rb +4 -2
- data/lib/pusher-fake/channel/public.rb +3 -3
- data/lib/pusher-fake/configuration.rb +10 -2
- data/lib/pusher-fake/connection.rb +10 -9
- data/lib/pusher-fake/server/application.rb +1 -1
- data/lib/pusher-fake/webhook.rb +6 -3
- data/spec/lib/pusher-fake/channel/presence_spec.rb +84 -27
- data/spec/lib/pusher-fake/channel/private_spec.rb +37 -20
- data/spec/lib/pusher-fake/channel/public_spec.rb +29 -18
- data/spec/lib/pusher-fake/channel_spec.rb +43 -15
- data/spec/lib/pusher-fake/configuration_spec.rb +11 -3
- data/spec/lib/pusher-fake/connection_spec.rb +74 -20
- data/spec/lib/pusher-fake/server/application_spec.rb +72 -36
- data/spec/lib/pusher-fake/server_spec.rb +46 -23
- data/spec/lib/pusher-fake/webhook_spec.rb +7 -3
- data/spec/lib/pusher_fake_spec.rb +41 -10
- data/spec/spec_helper.rb +4 -2
- data/spec/support/have_configuration_option_matcher.rb +12 -39
- metadata +4 -18
@@ -4,7 +4,7 @@ describe PusherFake::Channel::Private do
|
|
4
4
|
subject { PusherFake::Channel::Private }
|
5
5
|
|
6
6
|
it "inherits from public channel" do
|
7
|
-
subject.ancestors.
|
7
|
+
expect(subject.ancestors).to include(PusherFake::Channel::Public)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
@@ -24,46 +24,52 @@ describe PusherFake::Channel::Private, "#add" do
|
|
24
24
|
|
25
25
|
it "authorizes the connection" do
|
26
26
|
subject.stubs(authorized?: nil)
|
27
|
+
|
27
28
|
subject.add(connection, data)
|
28
|
-
|
29
|
+
|
30
|
+
expect(subject).to have_received(:authorized?).with(connection, data)
|
29
31
|
end
|
30
32
|
|
31
33
|
it "adds the connection to the channel when authorized" do
|
32
34
|
subject.stubs(authorized?: true)
|
35
|
+
|
33
36
|
subject.add(connection, data)
|
34
|
-
|
37
|
+
|
38
|
+
expect(connections).to have_received(:push).with(connection)
|
35
39
|
end
|
36
40
|
|
37
41
|
it "successfully subscribes the connection when authorized" do
|
38
42
|
subject.stubs(authorized?: true)
|
43
|
+
|
39
44
|
subject.add(connection, data)
|
40
|
-
|
45
|
+
|
46
|
+
expect(connection).to have_received(:emit).with("pusher_internal:subscription_succeeded", {}, subject.name)
|
41
47
|
end
|
42
48
|
|
43
49
|
it "triggers channel occupied webhook for the first connection added when authorized" do
|
44
50
|
subject.unstub(:connections)
|
45
51
|
subject.stubs(authorized?: true)
|
46
52
|
|
47
|
-
subject.add(connection, data)
|
48
|
-
|
49
|
-
|
50
|
-
PusherFake::Webhook.should have_received(:trigger).with("channel_occupied", channel: name).once
|
53
|
+
2.times { subject.add(connection, data) }
|
54
|
+
|
55
|
+
expect(PusherFake::Webhook).to have_received(:trigger).with("channel_occupied", channel: name).once
|
51
56
|
end
|
52
57
|
|
53
58
|
it "unsuccessfully subscribes the connection when not authorized" do
|
54
59
|
subject.stubs(authorized?: false)
|
60
|
+
|
55
61
|
subject.add(connection, data)
|
56
|
-
|
62
|
+
|
63
|
+
expect(connection).to have_received(:emit).with("pusher_internal:subscription_error", {}, subject.name)
|
57
64
|
end
|
58
65
|
|
59
66
|
it "does not trigger channel occupied webhook when not authorized" do
|
60
67
|
subject.unstub(:connections)
|
61
68
|
subject.stubs(authorized?: false)
|
62
69
|
|
63
|
-
subject.add(connection, data)
|
64
|
-
|
65
|
-
|
66
|
-
PusherFake::Webhook.should have_received(:trigger).never
|
70
|
+
2.times { subject.add(connection, data) }
|
71
|
+
|
72
|
+
expect(PusherFake::Webhook).to have_received(:trigger).never
|
67
73
|
end
|
68
74
|
end
|
69
75
|
|
@@ -83,11 +89,15 @@ describe PusherFake::Channel::Private, "#authentication_for" do
|
|
83
89
|
|
84
90
|
it "generates a signature" do
|
85
91
|
subject.authentication_for(id)
|
86
|
-
|
92
|
+
|
93
|
+
expect(OpenSSL::HMAC).to have_received(:hexdigest)
|
94
|
+
.with(kind_of(OpenSSL::Digest::SHA256), configuration.secret, string)
|
87
95
|
end
|
88
96
|
|
89
97
|
it "returns the authentication string" do
|
90
|
-
subject.authentication_for(id)
|
98
|
+
string = subject.authentication_for(id)
|
99
|
+
|
100
|
+
expect(string).to eq("#{configuration.key}:#{signature}")
|
91
101
|
end
|
92
102
|
end
|
93
103
|
|
@@ -108,11 +118,15 @@ describe PusherFake::Channel::Private, "#authentication_for, with channel data"
|
|
108
118
|
|
109
119
|
it "generates a signature" do
|
110
120
|
subject.authentication_for(id, channel_data)
|
111
|
-
|
121
|
+
|
122
|
+
expect(OpenSSL::HMAC).to have_received(:hexdigest)
|
123
|
+
.with(kind_of(OpenSSL::Digest::SHA256), configuration.secret, string)
|
112
124
|
end
|
113
125
|
|
114
126
|
it "returns the authentication string" do
|
115
|
-
subject.authentication_for(id, channel_data)
|
127
|
+
string = subject.authentication_for(id, channel_data)
|
128
|
+
|
129
|
+
expect(string).to eq("#{configuration.key}:#{signature}")
|
116
130
|
end
|
117
131
|
end
|
118
132
|
|
@@ -132,16 +146,19 @@ describe PusherFake::Channel::Private, "#authorized?" do
|
|
132
146
|
|
133
147
|
it "generates authentication for the connection socket ID" do
|
134
148
|
subject.authorized?(connection, data)
|
135
|
-
|
149
|
+
|
150
|
+
expect(subject).to have_received(:authentication_for).with(socket.object_id, channel_data)
|
136
151
|
end
|
137
152
|
|
138
153
|
it "returns true if the authentication matches" do
|
139
154
|
subject.stubs(authentication_for: authentication)
|
140
|
-
|
155
|
+
|
156
|
+
expect(subject).to be_authorized(connection, data)
|
141
157
|
end
|
142
158
|
|
143
159
|
it "returns false if the authentication matches" do
|
144
160
|
subject.stubs(authentication_for: "")
|
145
|
-
|
161
|
+
|
162
|
+
expect(subject).to_not be_authorized(connection, data)
|
146
163
|
end
|
147
164
|
end
|
@@ -7,12 +7,14 @@ describe PusherFake::Channel::Public do
|
|
7
7
|
|
8
8
|
it "assigns the provided name" do
|
9
9
|
channel = subject.new(name)
|
10
|
-
|
10
|
+
|
11
|
+
expect(channel.name).to eq(name)
|
11
12
|
end
|
12
13
|
|
13
14
|
it "creates an empty connections array" do
|
14
15
|
channel = subject.new(name)
|
15
|
-
|
16
|
+
|
17
|
+
expect(channel.connections).to eq([])
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -30,21 +32,22 @@ describe PusherFake::Channel, "#add" do
|
|
30
32
|
|
31
33
|
it "adds the connection" do
|
32
34
|
subject.add(connection)
|
33
|
-
|
35
|
+
|
36
|
+
expect(connections).to have_received(:push).with(connection)
|
34
37
|
end
|
35
38
|
|
36
39
|
it "successfully subscribes the connection" do
|
37
40
|
subject.add(connection)
|
38
|
-
|
41
|
+
|
42
|
+
expect(connection).to have_received(:emit).with("pusher_internal:subscription_succeeded", {}, subject.name)
|
39
43
|
end
|
40
44
|
|
41
45
|
it "triggers channel occupied webhook for the first connection added" do
|
42
46
|
subject.unstub(:connections)
|
43
47
|
|
44
|
-
subject.add(connection)
|
45
|
-
|
46
|
-
|
47
|
-
PusherFake::Webhook.should have_received(:trigger).with("channel_occupied", channel: name).once
|
48
|
+
2.times { subject.add(connection) }
|
49
|
+
|
50
|
+
expect(PusherFake::Webhook).to have_received(:trigger).with("channel_occupied", channel: name).once
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
@@ -66,14 +69,16 @@ describe PusherFake::Channel, "#emit" do
|
|
66
69
|
|
67
70
|
it "emits the event for each connection in the channel" do
|
68
71
|
subject.emit(event, data)
|
69
|
-
|
70
|
-
|
72
|
+
|
73
|
+
expect(connection_1).to have_received(:emit).with(event, data, name)
|
74
|
+
expect(connection_2).to have_received(:emit).with(event, data, name)
|
71
75
|
end
|
72
76
|
|
73
77
|
it "ignores connection if socket_id matches the connections socket object_id" do
|
74
78
|
subject.emit(event, data, socket_id: socket_2.object_id)
|
75
|
-
|
76
|
-
|
79
|
+
|
80
|
+
expect(connection_1).to have_received(:emit).with(event, data, name)
|
81
|
+
expect(connection_2).to have_received(:emit).never
|
77
82
|
end
|
78
83
|
end
|
79
84
|
|
@@ -84,12 +89,14 @@ describe PusherFake::Channel, "#includes?" do
|
|
84
89
|
|
85
90
|
it "returns true if the connection is in the channel" do
|
86
91
|
subject.stubs(connections: [connection])
|
87
|
-
|
92
|
+
|
93
|
+
expect(subject).to be_includes(connection)
|
88
94
|
end
|
89
95
|
|
90
96
|
it "returns false if the connection is not in the channel" do
|
91
97
|
subject.stubs(connections: [])
|
92
|
-
|
98
|
+
|
99
|
+
expect(subject).to_not be_includes(connection)
|
93
100
|
end
|
94
101
|
end
|
95
102
|
|
@@ -107,14 +114,18 @@ describe PusherFake::Channel, "#remove" do
|
|
107
114
|
|
108
115
|
it "removes the connection from the channel" do
|
109
116
|
subject.remove(connection_1)
|
110
|
-
|
117
|
+
|
118
|
+
expect(subject.connections).to_not include(connection_1)
|
111
119
|
end
|
112
120
|
|
113
121
|
it "triggers channel vacated webhook when all connections are removed" do
|
114
122
|
subject.remove(connection_1)
|
115
|
-
|
123
|
+
|
124
|
+
expect(PusherFake::Webhook).to have_received(:trigger).never
|
125
|
+
|
116
126
|
subject.remove(connection_2)
|
117
|
-
|
127
|
+
|
128
|
+
expect(PusherFake::Webhook).to have_received(:trigger).with("channel_vacated", channel: name).once
|
118
129
|
end
|
119
130
|
end
|
120
131
|
|
@@ -122,6 +133,6 @@ describe PusherFake::Channel::Public, "#subscription_data" do
|
|
122
133
|
subject { PusherFake::Channel::Public.new("name") }
|
123
134
|
|
124
135
|
it "returns an empty hash" do
|
125
|
-
subject.subscription_data.
|
136
|
+
expect(subject.subscription_data).to eq({})
|
126
137
|
end
|
127
138
|
end
|
@@ -16,16 +16,23 @@ describe PusherFake::Channel, ".factory" do
|
|
16
16
|
|
17
17
|
it "caches the channel" do
|
18
18
|
PusherFake::Channel::Public.unstub(:new)
|
19
|
-
|
19
|
+
|
20
|
+
factory_1 = subject.factory(name)
|
21
|
+
factory_2 = subject.factory(name)
|
22
|
+
|
23
|
+
expect(factory_1).to eq(factory_2)
|
20
24
|
end
|
21
25
|
|
22
26
|
it "creates a public channel by name" do
|
23
27
|
subject.factory(name)
|
24
|
-
|
28
|
+
|
29
|
+
expect(PusherFake::Channel::Public).to have_received(:new).with(name)
|
25
30
|
end
|
26
31
|
|
27
32
|
it "returns the channel instance" do
|
28
|
-
subject.factory(name)
|
33
|
+
factory = subject.factory(name)
|
34
|
+
|
35
|
+
expect(factory).to eq(channel)
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
@@ -45,16 +52,23 @@ describe PusherFake::Channel, ".factory, for a private channel" do
|
|
45
52
|
|
46
53
|
it "caches the channel" do
|
47
54
|
PusherFake::Channel::Private.unstub(:new)
|
48
|
-
|
55
|
+
|
56
|
+
factory_1 = subject.factory(name)
|
57
|
+
factory_2 = subject.factory(name)
|
58
|
+
|
59
|
+
expect(factory_1).to eq(factory_2)
|
49
60
|
end
|
50
61
|
|
51
62
|
it "creates a private channel by name" do
|
52
63
|
subject.factory(name)
|
53
|
-
|
64
|
+
|
65
|
+
expect(PusherFake::Channel::Private).to have_received(:new).with(name)
|
54
66
|
end
|
55
67
|
|
56
68
|
it "returns the channel instance" do
|
57
|
-
subject.factory(name)
|
69
|
+
factory = subject.factory(name)
|
70
|
+
|
71
|
+
expect(factory).to eq(channel)
|
58
72
|
end
|
59
73
|
end
|
60
74
|
|
@@ -74,16 +88,23 @@ describe PusherFake::Channel, ".factory, for a presence channel" do
|
|
74
88
|
|
75
89
|
it "caches the channel" do
|
76
90
|
PusherFake::Channel::Presence.unstub(:new)
|
77
|
-
|
91
|
+
|
92
|
+
factory_1 = subject.factory(name)
|
93
|
+
factory_2 = subject.factory(name)
|
94
|
+
|
95
|
+
expect(factory_1).to eq(factory_2)
|
78
96
|
end
|
79
97
|
|
80
98
|
it "creates a presence channel by name" do
|
81
99
|
subject.factory(name)
|
82
|
-
|
100
|
+
|
101
|
+
expect(PusherFake::Channel::Presence).to have_received(:new).with(name)
|
83
102
|
end
|
84
103
|
|
85
104
|
it "returns the channel instance" do
|
86
|
-
subject.factory(name)
|
105
|
+
factory = subject.factory(name)
|
106
|
+
|
107
|
+
expect(factory).to eq(channel)
|
87
108
|
end
|
88
109
|
end
|
89
110
|
|
@@ -101,23 +122,29 @@ describe PusherFake::Channel, ".remove" do
|
|
101
122
|
|
102
123
|
it "removes the connection from all channels" do
|
103
124
|
subject.remove(connection)
|
104
|
-
|
105
|
-
|
125
|
+
|
126
|
+
expect(channel_1).to have_received(:remove).with(connection)
|
127
|
+
expect(channel_2).to have_received(:remove).with(connection)
|
106
128
|
end
|
107
129
|
|
108
130
|
it "deletes a channel with no connections remaining" do
|
109
131
|
subject.remove(connection)
|
110
|
-
|
132
|
+
|
133
|
+
expect(channels).to_not have_key(:channel_1)
|
111
134
|
end
|
112
135
|
|
113
136
|
it "does not delete a channel with connections remaining" do
|
114
137
|
subject.remove(connection)
|
115
|
-
|
138
|
+
|
139
|
+
expect(channels).to have_key(:channel_2)
|
116
140
|
end
|
117
141
|
|
118
142
|
it "handles channels not being defined" do
|
119
143
|
subject.stubs(channels: nil)
|
120
|
-
|
144
|
+
|
145
|
+
expect {
|
146
|
+
subject.remove(connection)
|
147
|
+
}.to_not raise_error
|
121
148
|
end
|
122
149
|
end
|
123
150
|
|
@@ -127,6 +154,7 @@ describe PusherFake::Channel, ".reset" do
|
|
127
154
|
it "empties the channel cache" do
|
128
155
|
subject.factory("example")
|
129
156
|
subject.reset
|
130
|
-
|
157
|
+
|
158
|
+
expect(subject.channels).to eq({})
|
131
159
|
end
|
132
160
|
end
|
@@ -3,22 +3,30 @@ require "spec_helper"
|
|
3
3
|
describe PusherFake::Configuration do
|
4
4
|
it { should have_configuration_option(:app_id).with_default("PUSHER_APP_ID") }
|
5
5
|
it { should have_configuration_option(:key).with_default("PUSHER_API_KEY") }
|
6
|
+
it { should have_configuration_option(:logger).with_default(STDOUT.to_io) }
|
6
7
|
it { should have_configuration_option(:secret).with_default("PUSHER_API_SECRET") }
|
7
8
|
it { should have_configuration_option(:socket_options).with_default({ host: "127.0.0.1", port: 8080 }) }
|
9
|
+
it { should have_configuration_option(:verbose).with_default(false) }
|
8
10
|
it { should have_configuration_option(:web_options).with_default({ host: "127.0.0.1", port: 8081 }) }
|
9
11
|
it { should have_configuration_option(:webhooks).with_default([]) }
|
10
12
|
end
|
11
13
|
|
12
14
|
describe PusherFake::Configuration, "#to_options" do
|
13
15
|
it "includes the socket host as wsHost" do
|
14
|
-
|
16
|
+
options = subject.to_options
|
17
|
+
|
18
|
+
expect(options).to include(wsHost: subject.socket_options[:host])
|
15
19
|
end
|
16
20
|
|
17
21
|
it "includes the socket port as wsPort" do
|
18
|
-
|
22
|
+
options = subject.to_options
|
23
|
+
|
24
|
+
expect(options).to include(wsPort: subject.socket_options[:port])
|
19
25
|
end
|
20
26
|
|
21
27
|
it "supports passing custom options" do
|
22
|
-
subject.to_options(custom: "option")
|
28
|
+
options = subject.to_options(custom: "option")
|
29
|
+
|
30
|
+
expect(options).to include(custom: "option")
|
23
31
|
end
|
24
32
|
end
|
@@ -7,7 +7,8 @@ describe PusherFake::Connection do
|
|
7
7
|
|
8
8
|
it "assigns the provided socket" do
|
9
9
|
connection = subject.new(socket)
|
10
|
-
|
10
|
+
|
11
|
+
expect(connection.socket).to eq(socket)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -24,12 +25,14 @@ describe PusherFake::Connection, "#emit" do
|
|
24
25
|
|
25
26
|
it "sends the event to the socket as JSON" do
|
26
27
|
subject.emit(event, data)
|
27
|
-
|
28
|
+
|
29
|
+
expect(socket).to have_received(:send).with(json)
|
28
30
|
end
|
29
31
|
|
30
32
|
it "sets a channel when provided" do
|
31
33
|
subject.emit(event, data, channel)
|
32
|
-
|
34
|
+
|
35
|
+
expect(socket).to have_received(:send).with(channel_json)
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
@@ -44,7 +47,8 @@ describe PusherFake::Connection, "#establish" do
|
|
44
47
|
|
45
48
|
it "emits the connection established event with the socket ID" do
|
46
49
|
subject.establish
|
47
|
-
|
50
|
+
|
51
|
+
expect(subject).to have_received(:emit)
|
48
52
|
.with("pusher:connection_established", socket_id: socket.object_id, activity_timeout: 120)
|
49
53
|
end
|
50
54
|
end
|
@@ -65,17 +69,20 @@ describe PusherFake::Connection, "#process, with a subscribe event" do
|
|
65
69
|
|
66
70
|
it "parses the JSON data" do
|
67
71
|
subject.process(json)
|
68
|
-
|
72
|
+
|
73
|
+
expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
|
69
74
|
end
|
70
75
|
|
71
76
|
it "creates a channel from the event data" do
|
72
77
|
subject.process(json)
|
73
|
-
|
78
|
+
|
79
|
+
expect(PusherFake::Channel).to have_received(:factory).with(name)
|
74
80
|
end
|
75
81
|
|
76
82
|
it "attempts to add the connection to the channel" do
|
77
83
|
subject.process(json)
|
78
|
-
|
84
|
+
|
85
|
+
expect(channel).to have_received(:add).with(subject, data)
|
79
86
|
end
|
80
87
|
end
|
81
88
|
|
@@ -94,17 +101,51 @@ describe PusherFake::Connection, "#process, with an unsubscribe event" do
|
|
94
101
|
|
95
102
|
it "parses the JSON data" do
|
96
103
|
subject.process(json)
|
97
|
-
|
104
|
+
|
105
|
+
expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
|
98
106
|
end
|
99
107
|
|
100
108
|
it "creates a channel from the event data" do
|
101
109
|
subject.process(json)
|
102
|
-
|
110
|
+
|
111
|
+
expect(PusherFake::Channel).to have_received(:factory).with(name)
|
103
112
|
end
|
104
113
|
|
105
114
|
it "removes the connection from the channel" do
|
106
115
|
subject.process(json)
|
107
|
-
|
116
|
+
|
117
|
+
expect(channel).to have_received(:remove).with(subject)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe PusherFake::Connection, "#process, with a ping event" do
|
122
|
+
let(:json) { stub }
|
123
|
+
let(:message) { { event: "pusher:ping", data: {} } }
|
124
|
+
|
125
|
+
subject { PusherFake::Connection.new(stub) }
|
126
|
+
|
127
|
+
before do
|
128
|
+
MultiJson.stubs(load: message)
|
129
|
+
PusherFake::Channel.stubs(:factory)
|
130
|
+
subject.stubs(:emit)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "parses the JSON data" do
|
134
|
+
subject.process(json)
|
135
|
+
|
136
|
+
expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "does not create a channel" do
|
140
|
+
subject.process(json)
|
141
|
+
|
142
|
+
expect(PusherFake::Channel).to have_received(:factory).never
|
143
|
+
end
|
144
|
+
|
145
|
+
it "emits a pong event" do
|
146
|
+
subject.process(json)
|
147
|
+
|
148
|
+
expect(subject).to have_received(:emit).with("pusher:pong")
|
108
149
|
end
|
109
150
|
end
|
110
151
|
|
@@ -125,40 +166,50 @@ describe PusherFake::Connection, "#process, with a client event" do
|
|
125
166
|
|
126
167
|
it "parses the JSON data" do
|
127
168
|
subject.process(json)
|
128
|
-
|
169
|
+
|
170
|
+
expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
|
129
171
|
end
|
130
172
|
|
131
173
|
it "creates a channel from the event data" do
|
132
174
|
subject.process(json)
|
133
|
-
|
175
|
+
|
176
|
+
expect(PusherFake::Channel).to have_received(:factory).with(name)
|
134
177
|
end
|
135
178
|
|
136
179
|
it "ensures the channel is private" do
|
137
180
|
subject.process(json)
|
138
|
-
|
181
|
+
|
182
|
+
expect(channel).to have_received(:is_a?).with(PusherFake::Channel::Private)
|
139
183
|
end
|
140
184
|
|
141
185
|
it "checks if the connection is in the channel" do
|
142
186
|
subject.process(json)
|
143
|
-
|
187
|
+
|
188
|
+
expect(channel).to have_received(:includes?).with(subject)
|
144
189
|
end
|
145
190
|
|
146
191
|
it "emits the event to the channel when the connection is in the channel" do
|
147
192
|
channel.stubs(includes?: true)
|
193
|
+
|
148
194
|
subject.process(json)
|
149
|
-
|
195
|
+
|
196
|
+
expect(channel).to have_received(:emit).with(event, data, socket_id: subject.socket.object_id)
|
150
197
|
end
|
151
198
|
|
152
199
|
it "does not emit the event to the channel when the channel is not private" do
|
153
200
|
channel.stubs(includes?: true, is_a?: false)
|
201
|
+
|
154
202
|
subject.process(json)
|
155
|
-
|
203
|
+
|
204
|
+
expect(channel).to have_received(:emit).never
|
156
205
|
end
|
157
206
|
|
158
207
|
it "does not emit the event to the channel when the connection is not in the channel" do
|
159
208
|
channel.stubs(includes?: false)
|
209
|
+
|
160
210
|
subject.process(json)
|
161
|
-
|
211
|
+
|
212
|
+
expect(channel).to have_received(:emit).never
|
162
213
|
end
|
163
214
|
end
|
164
215
|
|
@@ -179,16 +230,19 @@ describe PusherFake::Connection, "#process, with an unknown event" do
|
|
179
230
|
|
180
231
|
it "parses the JSON data" do
|
181
232
|
subject.process(json)
|
182
|
-
|
233
|
+
|
234
|
+
expect(MultiJson).to have_received(:load).with(json, symbolize_keys: true)
|
183
235
|
end
|
184
236
|
|
185
237
|
it "creates a channel from the event data" do
|
186
238
|
subject.process(json)
|
187
|
-
|
239
|
+
|
240
|
+
expect(PusherFake::Channel).to have_received(:factory).with(name)
|
188
241
|
end
|
189
242
|
|
190
243
|
it "does not emit the event" do
|
191
244
|
subject.process(json)
|
192
|
-
|
245
|
+
|
246
|
+
expect(channel).to have_received(:emit).never
|
193
247
|
end
|
194
248
|
end
|