@@ -89,12 +89,19 @@ class PostTypesControllerTest < ActionController::TestCase
8989
9090 test 'can update post type' do
9191 sign_in users ( :global_admin )
92- data = { name : 'Test Type' , description : 'words' , icon_name : 'heart' ,
93- has_answers : true , has_license : true , has_category : true ,
94- answer_type_id : Answer . post_type_id , has_reactions : false ,
95- has_only_specific_reactions : true }
96- patch :update , params : { post_type : data ,
97- id : post_types ( :question ) . id }
92+
93+ data = { name : 'Test Type' ,
94+ description : 'words' ,
95+ icon_name : 'heart' ,
96+ has_answers : true ,
97+ has_license : true ,
98+ has_category : true ,
99+ answer_type_id : Answer . post_type_id ,
100+ has_reactions : false ,
101+ has_only_specific_reactions : true }
102+
103+ try_update_post_type ( post_types ( :question ) , **data )
104+
98105 assert_response ( :found )
99106 assert_redirected_to post_types_path
100107
@@ -106,17 +113,27 @@ class PostTypesControllerTest < ActionController::TestCase
106113 end
107114
108115 test 'update requires auth' do
109- patch :update , params : { post_type : { name : 'Test Type' , description : 'words' , icon_name : 'heart' ,
110- has_answers : 'true' , has_license : 'true' , has_category : 'true' } ,
111- id : post_types ( :question ) . id }
116+ try_update_post_type ( post_types ( :question ) )
112117 assert_redirected_to_sign_in
113118 end
114119
115120 test 'update requires global admin' do
116121 sign_in users ( :admin )
117- patch :update , params : { post_type : { name : 'Test Type' , description : 'words' , icon_name : 'heart' ,
118- has_answers : 'true' , has_license : 'true' , has_category : 'true' } ,
119- id : post_types ( :question ) . id }
122+ try_update_post_type ( post_types ( :question ) )
120123 assert_response ( :not_found )
121124 end
125+
126+ private
127+
128+ # @param post_type [PostType] post type to update
129+ # @param opts
130+ def try_update_post_type ( post_type , **opts )
131+ patch :update , params : { post_type : { name : 'Test Type' ,
132+ description : 'words' ,
133+ icon_name : 'heart' ,
134+ has_answers : 'true' ,
135+ has_license : 'true' ,
136+ has_category : 'true' } . merge ( opts ) ,
137+ id : post_type . id }
138+ end
122139end
0 commit comments