File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ require 'test_helper'
2+
3+ class PostsControllerTest < ActionController ::TestCase
4+ include Devise ::Test ::ControllerHelpers
5+
6+ test 'upload should correctly check file types' do
7+ sign_in users ( :standard_user )
8+
9+ try_upload_file ( 'not_uploadable.json' , 'application/json' )
10+
11+ assert_response ( :bad_request )
12+ assert_valid_json_response
13+ assert_not_nil JSON . parse ( response . body ) [ 'message' ]
14+
15+ try_upload_file ( 'uploadable_png.png' , 'image/png' )
16+
17+ assert_json_success
18+ assert_not_nil JSON . parse ( response . body ) [ 'link' ]
19+ end
20+
21+ private
22+
23+ def try_upload_file ( path , mime )
24+ post :upload , params : {
25+ file : file_fixture_upload ( path , mime )
26+ }
27+ end
28+ end
Original file line number Diff line number Diff line change 1+ {
2+ "message" : " this file should not be possible to upload" ,
3+ "answer" : 42 ,
4+ "question" : null
5+ }
You can’t perform that action at this time.
0 commit comments