@@ -963,31 +963,24 @@ def a_callback
963
963
end
964
964
965
965
test "notification for process" do
966
- events = [ ]
967
- ActiveSupport ::Notifications . subscribe ( "process.action_mailer" ) { |event | events << event }
966
+ expected_payload = { mailer : "BaseMailer" , action : :welcome , args : [ { body : "Hello there" } ] }
968
967
969
- BaseMailer . welcome ( body : "Hello there" ) . deliver_now
970
-
971
- assert_equal 1 , events . length
972
- assert_equal "process.action_mailer" , events [ 0 ] . name
973
- assert_equal "BaseMailer" , events [ 0 ] . payload [ :mailer ]
974
- assert_equal :welcome , events [ 0 ] . payload [ :action ]
975
- assert_equal [ { body : "Hello there" } ] , events [ 0 ] . payload [ :args ]
976
- ensure
977
- ActiveSupport ::Notifications . unsubscribe "process.action_mailer"
968
+ assert_notifications_count ( "process.action_mailer" , 1 ) do
969
+ assert_notification ( "process.action_mailer" , expected_payload ) do
970
+ BaseMailer . welcome ( body : "Hello there" ) . deliver_now
971
+ end
972
+ end
978
973
end
979
974
980
975
test "notification for deliver" do
981
- events = [ ]
982
- ActiveSupport ::Notifications . subscribe ( "deliver.action_mailer" ) { |event | events << event }
983
-
984
- BaseMailer . welcome ( body : "Hello there" ) . deliver_now
976
+ event = capture_notifications ( "deliver.action_mailer" ) do
977
+ assert_notifications_count ( "deliver.action_mailer" , 1 ) do
978
+ BaseMailer . welcome ( body : "Hello there" ) . deliver_now
979
+ end
980
+ end . first
985
981
986
- assert_equal 1 , events . length
987
- assert_equal "deliver.action_mailer" , events [ 0 ] . name
988
- assert_not_nil events [ 0 ] . payload [ :message_id ]
989
- ensure
990
- ActiveSupport ::Notifications . unsubscribe "deliver.action_mailer"
982
+ assert_equal "deliver.action_mailer" , event . name
983
+ assert_not_nil event . payload [ :message_id ]
991
984
end
992
985
993
986
private
0 commit comments