action-cable-testing 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +9 -3
- data/lib/action_cable/connection/test_case.rb +5 -3
- data/lib/action_cable/testing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee3c261b614627cd0d9d72bc9084cb4b7408bacaca953260d4c372da8774676c
|
4
|
+
data.tar.gz: bbdde5b4fdb2deb81571c23198443674733962100311b8f013311f4a5a778307
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ebdc170789756ee2885f503241048270ecf815b35881474a972373cc51697d25f47d823ebc8fa8b8f0a55f2f2ffa30d31fac3e19b6939e001058f72ad523ea0
|
7
|
+
data.tar.gz: 588e39d4f0c257b0786b966780be8b9ec8299ed87809a98da94fcf3e612c3d3abca5f5dfb861562abe60d9b5a3282cc0ce2439746c8da6f78b4cc8c64bd0d561
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
- Add session support for connection. ([@sponomarev][])
|
6
|
+
|
7
|
+
See https://github.com/palkan/action-cable-testing/pull/35
|
8
|
+
|
5
9
|
## 0.3.0
|
6
10
|
|
7
11
|
- Add connection unit-testing utilities. ([@palkan][])
|
@@ -34,3 +38,4 @@ See https://github.com/palkan/action-cable-testing/issues/4.
|
|
34
38
|
|
35
39
|
[@palkan]: https://github.com/palkan
|
36
40
|
[@thesmartnik]: https://github.com/thesmartnik
|
41
|
+
[@sponomarev]: https://github.com/sponomarev
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ class MyCableTest < ActionCable::TestCase
|
|
34
34
|
ActionCable.server.broadcast 'messages', { text: 'hello' }
|
35
35
|
assert_broadcasts 'messages', 1
|
36
36
|
|
37
|
-
# Check the number of messages broadcasted to the stream within a block
|
37
|
+
# Check the number of messages broadcasted to the stream within a block
|
38
38
|
assert_broadcasts('messages', 1) do
|
39
39
|
ActionCable.server.broadcast 'messages', { text: 'hello' }
|
40
40
|
end
|
@@ -115,7 +115,7 @@ class ChatChannelTest < ActionCable::Channel::TestCase
|
|
115
115
|
|
116
116
|
subscribe room_number: 1
|
117
117
|
|
118
|
-
|
118
|
+
assert_broadcast_on("messages_1", text: "I'm here!", from: "John") do
|
119
119
|
perform :speak, message: "I'm here!"
|
120
120
|
end
|
121
121
|
end
|
@@ -141,7 +141,7 @@ class ChatChannelTest < ActionCable::Channel::TestCase
|
|
141
141
|
# or
|
142
142
|
|
143
143
|
def test_broadcasted_data
|
144
|
-
|
144
|
+
assert_broadcast_on(@room, text: "I'm here!", from: "John") do
|
145
145
|
perform :speak, message: "I'm here!"
|
146
146
|
end
|
147
147
|
end
|
@@ -184,6 +184,12 @@ def test_connect_with_headers_and_query_string
|
|
184
184
|
|
185
185
|
assert_equal connection.user_id, "1"
|
186
186
|
end
|
187
|
+
|
188
|
+
def test_connect_with_session
|
189
|
+
connect "/cable", session: { users[:john].id }
|
190
|
+
|
191
|
+
assert_equal connection.user_id, "1"
|
192
|
+
end
|
187
193
|
```
|
188
194
|
|
189
195
|
### RSpec Usage
|
@@ -36,6 +36,7 @@ module ActionCable
|
|
36
36
|
|
37
37
|
class TestRequest < ActionDispatch::TestRequest
|
38
38
|
attr_reader :cookie_jar
|
39
|
+
attr_accessor :session
|
39
40
|
|
40
41
|
module CookiesStub
|
41
42
|
# Stub signed cookies
|
@@ -59,7 +60,7 @@ module ActionCable
|
|
59
60
|
module TestConnection
|
60
61
|
attr_reader :logger, :request
|
61
62
|
|
62
|
-
def initialize(path, cookies, headers)
|
63
|
+
def initialize(path, cookies, headers, session)
|
63
64
|
inner_logger = ActiveSupport::Logger.new(StringIO.new)
|
64
65
|
tagged_logging = ActiveSupport::TaggedLogging.new(inner_logger)
|
65
66
|
@logger = ActionCable::Connection::TaggedLoggerProxy.new(tagged_logging, tags: [])
|
@@ -72,6 +73,7 @@ module ActionCable
|
|
72
73
|
|
73
74
|
@request = TestRequest.create(env)
|
74
75
|
@request.cookie_jar = cookies.with_indifferent_access
|
76
|
+
@request.session = session.with_indifferent_access
|
75
77
|
end
|
76
78
|
|
77
79
|
def build_headers(headers)
|
@@ -174,10 +176,10 @@ module ActionCable
|
|
174
176
|
# Performs connection attempt (i.e. calls #connect method).
|
175
177
|
#
|
176
178
|
# Accepts request path as the first argument and cookies and headers as options.
|
177
|
-
def connect(path = "/cable", cookies: {}, headers: {})
|
179
|
+
def connect(path = "/cable", cookies: {}, headers: {}, session: {})
|
178
180
|
connection = self.class.connection_class.allocate
|
179
181
|
connection.singleton_class.include(TestConnection)
|
180
|
-
connection.send(:initialize, path, cookies, headers)
|
182
|
+
connection.send(:initialize, path, cookies, headers, session)
|
181
183
|
connection.connect if connection.respond_to?(:connect)
|
182
184
|
|
183
185
|
# Only set instance variable if connected successfully
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action-cable-testing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actioncable
|