Upfile tests + File#size is available since ruby 2.0 (AR 5 requires 2.2)

This commit is contained in:
Vasily Fedoseyev
2024-04-10 17:51:38 +03:00
parent e7ef0bf8a3
commit f2b6da2a69
2 changed files with 42 additions and 5 deletions

View File

@@ -39,11 +39,6 @@ module Paperclip
def original_filename
@original_filename ||= File.basename(path)
end
# Returns the size of the file.
def size
File.size(self)
end
end
end

42
test/upfile_test.rb Normal file
View File

@@ -0,0 +1,42 @@
# frozen_string_literal: true
require 'test_helper'
class UpfileTest < Test::Unit::TestCase
context "content_type_from_ext" do
{
'lala' => 'application/x-octet-stream',
'lala.foo' => 'application/x-foo',
'__.jpg' => "image/jpeg",
'_.jpeg' => "image/jpeg",
'__.tif' => "image/tiff",
'_.tiff' => "image/tiff",
'_.png' => "image/png",
'_.gif' => "image/gif",
'_.bmp' => "image/bmp",
"_.webp" => "image/webp",
# '_.pngfoo' => 'application/x-pngfoo', # ??
# '_.htmfoo' => 'application/x-htmfoo', # ?
'_.csv' => "text/csv",
'_.xml' => "text/xml",
'_.css' => "text/css",
'_.js' => "text/js", # ???
'_.html' => 'text/html',
'__.htm' => 'text/html',
"_.txt" => "text/plain",
"_.liquid" => "text/x-liquid",
'_.svg' => 'image/svg+xml',
'_.xls' => 'application/vnd.ms-excel',
}.each_pair do |example, result|
should "return #{result} for #{example}" do
assert_equal result, Paperclip::Upfile.content_type_from_ext(example)
end
end
end
end