Sha256: b848b0d06dce3d48180f23fe737d23b3714e94fe5694884dde427c7c32e3d9d9

Contents?: true

Size: 1.73 KB

Versions: 21

Compression:

Stored size: 1.73 KB

Contents

require './test/helper'

class UpfileTest < Test::Unit::TestCase
  { %w(jpg jpe jpeg) => 'image/jpeg',
    %w(tif tiff)     => 'image/tiff',
    %w(png)          => 'image/png',
    %w(gif)          => 'image/gif',
    %w(bmp)          => 'image/bmp',
    %w(svg)          => 'image/svg+xml',
    %w(txt)          => 'text/plain',
    %w(htm html)     => 'text/html',
    %w(csv)          => 'text/csv',
    %w(xml)          => 'application/xml',
    %w(css)          => 'text/css',
    %w(js)           => 'application/javascript',
    %w(foo)          => 'application/x-foo'
  }.each do |extensions, content_type|
    extensions.each do |extension|
      should "return a content_type of #{content_type} for a file with extension .#{extension}" do
        file = stub('file', :path => "basename.#{extension}")
        class << file
          include Paperclip::Upfile
        end

        assert_equal content_type, file.content_type
      end
    end
  end

  should "return a content_type of text/plain on a real file whose content_type is determined with the file command" do
    file = File.new(File.join(File.dirname(__FILE__), "..", "LICENSE"))
    class << file
      include Paperclip::Upfile
    end
    assert_equal 'text/plain', file.content_type
  end

  { '5k.png'       => 'image/png',
    'animated.gif' => 'image/gif',
    'text.txt'     => 'text/plain',
    'twopage.pdf'  => 'application/pdf'
  }.each do |filename, content_type|
    should "return a content type of #{content_type} from a file command for file #{filename}" do
      file = File.new(File.join(File.dirname(__FILE__), "fixtures", filename))
      class << file
        include Paperclip::Upfile
      end

      assert_equal content_type, file.type_from_file_command
    end
  end

end

Version data entries

21 entries across 21 versions & 5 rubygems

Version Path
paperclip-v2_7-patched-ruby-1_8_6-2.7.5 test/upfile_test.rb
paperclip-2.7.5 test/upfile_test.rb
paperclip-2.7.4 test/upfile_test.rb
paperclip-2.7.2 test/upfile_test.rb
paperclip-2.8.0 test/upfile_test.rb
paperclip-2.7.1 test/upfile_test.rb
cloudfuji_paperclip-2.4.6 test/upfile_test.rb
paperclip-2.7.0 test/upfile_test.rb
paperclip-2.6.0 test/upfile_test.rb
paperclip-2.5.2 test/upfile_test.rb
paperclip-2.5.1 test/upfile_test.rb
paperclip-2.5.0 test/upfile_test.rb
mender_paperclip-2.4.3.1 test/upfile_test.rb
jmcnevin-paperclip-2.4.5.1 test/upfile_test.rb
jmcnevin-paperclip-2.4.5 test/upfile_test.rb
paperclip-2.4.5 test/upfile_test.rb
mender_paperclip-2.4.3 test/upfile_test.rb
paperclip-2.4.4 test/upfile_test.rb
paperclip-2.4.3 test/upfile_test.rb
paperclip-2.4.2 test/upfile_test.rb