cartodb-4.42/spec/lib/carto/assets/image_assets_service_spec.rb
2024-04-06 05:25:13 +00:00

44 lines
1.4 KiB
Ruby

require 'spec_helper_min'
require_relative '../../../../app/controllers/carto/controller_helper'
describe Carto::ImageAssetsService do
describe('#fetch_file') do
it 'reject files that are too big' do
max_size = Carto::ImageAssetsService.new.max_size_in_bytes
IO.stubs(:copy_stream).returns(max_size + 1)
expect {
Carto::ImageAssetsService.new.fetch_file(Tempfile.new(['manolo', '.png']))
}.to raise_error(Carto::UnprocesableEntityError, "resource is too big (> #{max_size} bytes)")
end
it 'validates file dimensions' do
file = File.new(Rails.root + 'spec/support/data/images/1025x1.jpg')
expect {
Carto::ImageAssetsService.new.fetch_file(file)
}.to raise_error(Carto::UnprocesableEntityError, "file is too big, 1024x1024 max")
end
it 'keeps original extension' do
file = Tempfile.new(['test', '.svg'])
file.write('wadus')
file.rewind
uploaded_file = Rack::Test::UploadedFile.new(file)
temp_file = Carto::ImageAssetsService.new.fetch_file(uploaded_file)
temp_file.path.should end_with '.svg'
end
it 'rejects invalid extensions' do
file = Tempfile.new(['test', '.exe'])
file.write('wadus')
file.rewind
uploaded_file = Rack::Test::UploadedFile.new(file)
expect {
Carto::ImageAssetsService.new.fetch_file(uploaded_file)
}.to raise_error(Carto::UnprocesableEntityError, "extension not accepted")
end
end
end