@@ -199,67 +199,49 @@ def error_handler
199
199
end
200
200
201
201
test "notification for perform_action" do
202
- events = [ ]
203
- ActiveSupport ::Notifications . subscribe ( "perform_action.action_cable" ) { |event | events << event }
204
-
205
202
data = { "action" => :speak , "content" => "hello" }
206
- @channel . perform_action data
203
+ expected_payload = { channel_class : "ActionCable::Channel::BaseTest::ChatChannel" , action : :speak , data : }
207
204
208
- assert_equal 1 , events . length
209
- assert_equal "perform_action.action_cable" , events [ 0 ] . name
210
- assert_equal "ActionCable::Channel::BaseTest::ChatChannel" , events [ 0 ] . payload [ :channel_class ]
211
- assert_equal :speak , events [ 0 ] . payload [ :action ]
212
- assert_equal data , events [ 0 ] . payload [ :data ]
213
- ensure
214
- ActiveSupport ::Notifications . unsubscribe "perform_action.action_cable"
205
+ assert_notifications_count ( "perform_action.action_cable" , 1 ) do
206
+ assert_notification ( "perform_action.action_cable" , expected_payload ) do
207
+ @channel . perform_action data
208
+ end
209
+ end
215
210
end
216
211
217
212
test "notification for transmit" do
218
- events = [ ]
219
- ActiveSupport :: Notifications . subscribe ( "transmit.action_cable" ) { | event | events << event }
213
+ data = { data : "latest" }
214
+ expected_payload = { channel_class : "ActionCable::Channel::BaseTest::ChatChannel" , data : , via : nil }
220
215
221
- @channel . perform_action "action" => :get_latest
222
- expected_data = { data : "latest" }
223
-
224
- assert_equal 1 , events . length
225
- assert_equal "transmit.action_cable" , events [ 0 ] . name
226
- assert_equal "ActionCable::Channel::BaseTest::ChatChannel" , events [ 0 ] . payload [ :channel_class ]
227
- assert_equal expected_data , events [ 0 ] . payload [ :data ]
228
- assert_nil events [ 0 ] . payload [ :via ]
229
- ensure
230
- ActiveSupport ::Notifications . unsubscribe "transmit.action_cable"
216
+ assert_notifications_count ( "transmit.action_cable" , 1 ) do
217
+ assert_notification ( "transmit.action_cable" , expected_payload ) do
218
+ @channel . perform_action "action" => :get_latest
219
+ end
220
+ end
231
221
end
232
222
233
223
test "notification for transmit_subscription_confirmation" do
234
- @channel . subscribe_to_channel
235
-
236
- events = [ ]
237
- ActiveSupport ::Notifications . subscribe ( "transmit_subscription_confirmation.action_cable" ) { |e | events << e }
224
+ expected_payload = { channel_class : "ActionCable::Channel::BaseTest::ChatChannel" , identifier : "{id: 1}" }
238
225
239
- @channel . stub ( :subscription_confirmation_sent? , false ) do
240
- @channel . send ( :transmit_subscription_confirmation )
226
+ @channel . subscribe_to_channel
241
227
242
- assert_equal 1 , events . length
243
- assert_equal "transmit_subscription_confirmation.action_cable" , events [ 0 ] . name
244
- assert_equal "ActionCable::Channel::BaseTest::ChatChannel" , events [ 0 ] . payload [ :channel_class ]
245
- assert_equal "{id: 1}" , events [ 0 ] . payload [ :identifier ]
228
+ assert_notifications_count ( "transmit_subscription_confirmation.action_cable" , 1 ) do
229
+ assert_notification ( "transmit_subscription_confirmation.action_cable" , expected_payload ) do
230
+ @channel . stub ( :subscription_confirmation_sent? , false ) do
231
+ @channel . send ( :transmit_subscription_confirmation )
232
+ end
233
+ end
246
234
end
247
- ensure
248
- ActiveSupport ::Notifications . unsubscribe "transmit_subscription_confirmation.action_cable"
249
235
end
250
236
251
237
test "notification for transmit_subscription_rejection" do
252
- events = [ ]
253
- ActiveSupport ::Notifications . subscribe ( "transmit_subscription_rejection.action_cable" ) { |event | events << event }
238
+ expected_payload = { channel_class : "ActionCable::Channel::BaseTest::ChatChannel" , identifier : "{id: 1}" }
254
239
255
- @channel . send ( :transmit_subscription_rejection )
256
-
257
- assert_equal 1 , events . length
258
- assert_equal "transmit_subscription_rejection.action_cable" , events [ 0 ] . name
259
- assert_equal "ActionCable::Channel::BaseTest::ChatChannel" , events [ 0 ] . payload [ :channel_class ]
260
- assert_equal "{id: 1}" , events [ 0 ] . payload [ :identifier ]
261
- ensure
262
- ActiveSupport ::Notifications . unsubscribe "transmit_subscription_rejection.action_cable"
240
+ assert_notifications_count ( "transmit_subscription_rejection.action_cable" , 1 ) do
241
+ assert_notification ( "transmit_subscription_rejection.action_cable" , expected_payload ) do
242
+ @channel . send ( :transmit_subscription_rejection )
243
+ end
244
+ end
263
245
end
264
246
265
247
test "behaves like rescuable" do
0 commit comments