Skip to content

Commit 2f6be98

Browse files
committed
added tests for the posts controller's upload action
1 parent b6e8a60 commit 2f6be98

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"message": "this file should not be possible to upload",
3+
"answer": 42,
4+
"question": null
5+
}
30.5 KB
Loading

0 commit comments

Comments
 (0)