1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Uploads', 'routing' do
context 'for personal snippets' do
it 'allows creating uploads for personal snippets' do
expect(post('/uploads/personal_snippet?id=1')).to route_to(
controller: 'uploads',
action: 'create',
model: 'personal_snippet',
id: '1'
)
end
end
context 'for users' do
it 'allows creating uploads for users' do
expect(post('/uploads/user?id=1')).to route_to(
controller: 'uploads',
action: 'create',
model: 'user',
id: '1'
)
end
end
context 'for abuse reports' do
it 'allows fetching uploaded files for abuse reports' do
expect(get('/uploads/-/system/abuse_report/1/secret/test.png')).to route_to(
controller: 'uploads',
action: 'show',
model: 'abuse_report',
id: '1',
secret: 'secret',
filename: 'test.png'
)
end
it 'allows creating uploads for abuse reports' do
expect(post('/uploads/abuse_report?id=1')).to route_to(
controller: 'uploads',
action: 'create',
model: 'abuse_report',
id: '1'
)
end
it 'allows authorizing uploads for abuse reports' do
expect(post('/uploads/abuse_report/authorize')).to route_to(
controller: 'uploads',
action: 'authorize',
model: 'abuse_report'
)
end
it 'allows fetching abuse report screenshots' do
expect(get('/uploads/-/system/abuse_report/screenshot/1/test.jpg')).to route_to(
controller: 'uploads',
action: 'show',
model: 'abuse_report',
id: '1',
filename: 'test.jpg',
mounted_as: 'screenshot'
)
end
end
context 'for alert management' do
it 'allows fetching alert metric metric images' do
expect(get('/uploads/-/system/alert_management_metric_image/file/1/test.jpg')).to route_to(
controller: 'uploads',
action: 'show',
model: 'alert_management_metric_image',
id: '1',
filename: 'test.jpg',
mounted_as: 'file'
)
end
end
it 'does not allow creating uploads for other models' do
unroutable_models = UploadsController::MODEL_CLASSES.keys.compact - %w[personal_snippet user abuse_report]
unroutable_models.each do |model|
expect(post("/uploads/#{model}?id=1")).not_to be_routable
end
end
end
|