File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change
1
+ * Add two new assertion methods for ActionCable test cases: ` assert_not_has_stream `
2
+ and ` assert_not_has_stream_for ` . These methods can be used to assert that a
3
+ stream has been stopped, e.g. via ` stop_stream ` or ` stop_stream_for ` . They complement
4
+ the already existing ` assert_has_stream ` and ` assert_has_stream_for ` methods.
5
+
6
+ ``` ruby
7
+ assert_not_has_stream " messages"
8
+ assert_not_has_stream_for User .find(42 )
9
+ ```
10
+
11
+ * Sebastian P öll*
1
12
2
13
Please check [7 - 1 - stable](https: // github.com/ rails/ rails/ blob/ 7 - 1 - stable/ actioncable/ CHANGELOG .md) for previous changes.
Original file line number Diff line number Diff line change @@ -312,6 +312,28 @@ def assert_has_stream_for(object)
312
312
assert_has_stream ( broadcasting_for ( object ) )
313
313
end
314
314
315
+ # Asserts that the specified stream has not been started.
316
+ #
317
+ # def test_assert_not_started_stream
318
+ # subscribe
319
+ # assert_not_has_stream 'messages'
320
+ # end
321
+ #
322
+ def assert_not_has_stream ( stream )
323
+ assert subscription . streams . exclude? ( stream ) , "Stream #{ stream } has been started"
324
+ end
325
+
326
+ # Asserts that the specified stream for a model has not started.
327
+ #
328
+ # def test_assert_not_started_stream_for
329
+ # subscribe id: 41
330
+ # assert_not_has_stream_for User.find(42)
331
+ # end
332
+ #
333
+ def assert_not_has_stream_for ( object )
334
+ assert_not_has_stream ( broadcasting_for ( object ) )
335
+ end
336
+
315
337
private
316
338
def check_subscribed!
317
339
raise "Must be subscribed!" if subscription . nil? || subscription . rejected?
Original file line number Diff line number Diff line change @@ -107,6 +107,20 @@ def test_stream_with_params
107
107
assert_has_stream "test_42"
108
108
end
109
109
110
+ def test_not_stream_without_params
111
+ subscribe
112
+ unsubscribe
113
+
114
+ assert_not_has_stream "test_0"
115
+ end
116
+
117
+ def test_not_stream_with_params
118
+ subscribe id : 42
119
+ perform :unsubscribed , id : 42
120
+
121
+ assert_not_has_stream "test_42"
122
+ end
123
+
110
124
def test_unsubscribe_from_stream
111
125
subscribe
112
126
unsubscribe
@@ -119,6 +133,10 @@ class StreamsForTestChannel < ActionCable::Channel::Base
119
133
def subscribed
120
134
stream_for User . new ( params [ :id ] )
121
135
end
136
+
137
+ def unsubscribed
138
+ stop_stream_for User . new ( params [ :id ] )
139
+ end
122
140
end
123
141
124
142
class StreamsForTestChannelTest < ActionCable ::Channel ::TestCase
@@ -127,6 +145,13 @@ def test_stream_with_params
127
145
128
146
assert_has_stream_for User . new ( 42 )
129
147
end
148
+
149
+ def test_not_stream_with_params
150
+ subscribe id : 42
151
+ perform :unsubscribed , id : 42
152
+
153
+ assert_not_has_stream_for User . new ( 42 )
154
+ end
130
155
end
131
156
132
157
class NoStreamsTestChannel < ActionCable ::Channel ::Base
You can’t perform that action at this time.
0 commit comments