2019-05-02 06:13:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe 'Uploads', 'routing' do
|
2019-05-02 06:13:42 -04:00
|
|
|
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
|
|
|
|
|
2019-06-04 19:50:57 -04:00
|
|
|
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
|
|
|
|
|
2022-04-14 11:08:59 -04:00
|
|
|
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
|
|
|
|
|
2019-05-02 06:13:42 -04:00
|
|
|
it 'does not allow creating uploads for other models' do
|
2019-06-04 19:50:57 -04:00
|
|
|
unroutable_models = UploadsController::MODEL_CLASSES.keys.compact - %w(personal_snippet user)
|
2019-05-02 06:13:42 -04:00
|
|
|
|
2019-06-04 19:50:57 -04:00
|
|
|
unroutable_models.each do |model|
|
2019-05-02 06:13:42 -04:00
|
|
|
expect(post("/uploads/#{model}?id=1")).not_to be_routable
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|