@@ -21,7 +21,7 @@ class ModWarningControllerTest < ActionController::TestCase
2121
2222 test 'mods or admins should be able to access pages' do
2323 [ users ( :moderator ) , users ( :admin ) ] . each do |user |
24- sign_in user
24+ sign_in ( user )
2525
2626 [ :log , :new ] . each do |path |
2727 get path , params : { user_id : users ( :standard_user ) . id }
@@ -30,6 +30,21 @@ class ModWarningControllerTest < ActionController::TestCase
3030 end
3131 end
3232
33+ test ':create should correctly create mod warnings' do
34+ user = users ( :moderator )
35+ subject = users ( :standard_user )
36+
37+ sign_in ( user )
38+
39+ try_create_mod_warning ( subject )
40+
41+ assert_redirected_to ( user_path ( subject ) )
42+ warning = assigns ( :warning )
43+ assert_not_nil warning
44+ assert_audit_log ( 'warning_create' , related : warning )
45+ assert_audit_log ( 'suspension_create' , related : warning )
46+ end
47+
3348 test 'suspended user should redirect to current warning page' do
3449 sign_in users ( :standard_user )
3550 mod_warnings ( :first_warning ) . update ( active : true )
@@ -75,12 +90,39 @@ class ModWarningControllerTest < ActionController::TestCase
7590
7691 std = users ( :standard_user )
7792 warning = mod_warnings ( :third_warning )
78-
7993 warning . update ( active : true )
80- post :lift , params : { user_id : std . id }
94+
95+ try_lift_suspension ( std )
8196
8297 assert_response ( :found )
8398 warning . reload
8499 assert_not warning . active
100+
101+ assert_audit_log ( 'warning_lift' , related : warning )
102+ assert_audit_log ( 'suspension_lift' , related : warning )
103+ end
104+
105+ private
106+
107+ # @param subject [User] to whom the mod warning is issued
108+ # @option opts :body [String]
109+ # @option opts :suspension_public_notice [String]
110+ # @option opts :is_suspension [Boolean]
111+ # @option opts :suspension_duration [Integer]
112+ def try_create_mod_warning ( subject , **opts )
113+ post :create , params : {
114+ user_id : subject . id ,
115+ mod_warning : {
116+ body : 'You have been suspended for science. Your sacrifice will not be forgotten' ,
117+ suspension_public_notice : 'Do not mind this suspension, nothing to see here, move along' ,
118+ is_suspension : true ,
119+ suspension_duration : 365
120+ } . merge ( opts )
121+ }
122+ end
123+
124+ # @param subject [User] for whome to lift the suspension
125+ def try_lift_suspension ( subject )
126+ post :lift , params : { user_id : subject . id }
85127 end
86128end
0 commit comments