@@ -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,20 @@ class ModWarningControllerTest < ActionController::TestCase
3030 end
3131 end
3232
33+ test ':create should correclty 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+ end
46+
3347 test 'suspended user should redirect to current warning page' do
3448 sign_in users ( :standard_user )
3549 mod_warnings ( :first_warning ) . update ( active : true )
@@ -83,4 +97,23 @@ class ModWarningControllerTest < ActionController::TestCase
8397 warning . reload
8498 assert_not warning . active
8599 end
100+
101+ private
102+
103+ # @param subject [User] to whom the mod warning is issued
104+ # @option opts :body [String]
105+ # @option opts :suspension_public_notice [String]
106+ # @option opts :is_suspension [Boolean]
107+ # @option opts :suspension_duration [Integer]
108+ def try_create_mod_warning ( subject , **opts )
109+ post :create , params : {
110+ user_id : subject . id ,
111+ mod_warning : {
112+ body : 'You have been suspended for science. Your sacrifice will not be forgotten' ,
113+ suspension_public_notice : 'Do not mind this suspension, nothing to see here, move along' ,
114+ is_suspension : true ,
115+ suspension_duration : 365
116+ } . merge ( opts )
117+ }
118+ end
86119end
0 commit comments