mime-types 2.99.3 → 3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.autotest +35 -0
 - data/.gemtest +0 -0
 - data/.gitignore +17 -0
 - data/.hoerc +20 -0
 - data/Code-of-Conduct.rdoc +27 -60
 - data/Contributing.rdoc +0 -1
 - data/History.rdoc +75 -36
 - data/Licence.rdoc +2 -16
 - data/Manifest.txt +10 -18
 - data/README.rdoc +46 -46
 - data/Rakefile +112 -58
 - data/lib/mime-types.rb +0 -2
 - data/lib/mime/type.rb +183 -415
 - data/lib/mime/type/columnar.rb +27 -62
 - data/lib/mime/types.rb +37 -135
 - data/lib/mime/types/cache.rb +49 -73
 - data/lib/mime/types/columnar.rb +42 -48
 - data/lib/mime/types/container.rb +30 -0
 - data/lib/mime/types/deprecations.rb +1 -22
 - data/lib/mime/types/full.rb +17 -0
 - data/lib/mime/types/loader.rb +10 -137
 - data/lib/mime/types/logger.rb +2 -0
 - data/lib/mime/types/registry.rb +81 -0
 - data/support/benchmarks/load.rb +27 -26
 - data/support/benchmarks/load_allocations.rb +14 -7
 - data/support/benchmarks/object_counts.rb +6 -4
 - data/support/profile/columnar.rb +5 -0
 - data/support/profile/columnar_full.rb +5 -0
 - data/support/profile/full.rb +5 -0
 - data/test/minitest_helper.rb +3 -12
 - data/test/test_mime_type.rb +461 -454
 - data/test/test_mime_types.rb +126 -86
 - data/test/test_mime_types_cache.rb +55 -45
 - data/test/test_mime_types_class.rb +113 -97
 - data/test/test_mime_types_lazy.rb +19 -23
 - data/test/test_mime_types_loader.rb +5 -32
 - metadata +67 -44
 - data/History-Types.rdoc +0 -454
 - data/data/mime-types.json +0 -1
 - data/data/mime.content_type.column +0 -1980
 - data/data/mime.docs.column +0 -1980
 - data/data/mime.encoding.column +0 -1980
 - data/data/mime.friendly.column +0 -1980
 - data/data/mime.obsolete.column +0 -1980
 - data/data/mime.registered.column +0 -1980
 - data/data/mime.signature.column +0 -1980
 - data/data/mime.use_instead.column +0 -1980
 - data/data/mime.xrefs.column +0 -1980
 - data/docs/COPYING.txt +0 -339
 - data/docs/artistic.txt +0 -127
 - data/lib/mime/types/loader_path.rb +0 -15
 - data/support/apache_mime_types.rb +0 -108
 - data/support/convert.rb +0 -158
 - data/support/convert/columnar.rb +0 -88
 - data/support/iana_registry.rb +0 -172
 
    
        data/test/test_mime_types.rb
    CHANGED
    
    | 
         @@ -3,119 +3,159 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'mime/types'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'minitest_helper'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
              def  
     | 
| 
       8 
     | 
    
         
            -
                @mime_types  
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
            describe MIME::Types do
         
     | 
| 
      
 7 
     | 
    
         
            +
              def mime_types
         
     | 
| 
      
 8 
     | 
    
         
            +
                @mime_types ||= MIME::Types.new.tap do |mt|
         
     | 
| 
      
 9 
     | 
    
         
            +
                  mt.add MIME::Type.new(['text/plain', %w(txt)]),
         
     | 
| 
      
 10 
     | 
    
         
            +
                    MIME::Type.new(['image/jpeg', %w(jpg jpeg)]),
         
     | 
| 
      
 11 
     | 
    
         
            +
                    MIME::Type.new('application/x-wordperfect6.1'),
         
     | 
| 
      
 12 
     | 
    
         
            +
                    MIME::Type.new(
         
     | 
| 
      
 13 
     | 
    
         
            +
                      'content-type' => 'application/x-www-form-urlencoded',
         
     | 
| 
      
 14 
     | 
    
         
            +
                      'registered' => true
         
     | 
| 
      
 15 
     | 
    
         
            +
                    ),
         
     | 
| 
      
 16 
     | 
    
         
            +
                    MIME::Type.new(['application/x-gzip', %w(gz)]),
         
     | 
| 
      
 17 
     | 
    
         
            +
                    MIME::Type.new(
         
     | 
| 
      
 18 
     | 
    
         
            +
                      'content-type' => 'application/gzip',
         
     | 
| 
      
 19 
     | 
    
         
            +
                      'extensions' => 'gz',
         
     | 
| 
      
 20 
     | 
    
         
            +
                      'registered' => true
         
     | 
| 
      
 21 
     | 
    
         
            +
                    )
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
       15 
23 
     | 
    
         
             
              end
         
     | 
| 
       16 
24 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
               
     | 
| 
       18 
     | 
    
         
            -
                 
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                 
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
              describe 'is enumerable' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                it 'correctly uses an Enumerable method like #any?' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                  assert mime_types.any? { |type| type.content_type == 'text/plain' }
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
       22 
29 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                 
     | 
| 
       27 
     | 
    
         
            -
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
                it 'implements each with no parameters to return an Enumerator' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  assert_kind_of Enumerator, mime_types.each
         
     | 
| 
      
 32 
     | 
    
         
            +
                  assert_kind_of Enumerator, mime_types.map
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
       28 
34 
     | 
    
         | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 35 
     | 
    
         
            +
                it 'will create a lazy enumerator' do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  assert_kind_of Enumerator::Lazy, mime_types.lazy
         
     | 
| 
      
 37 
     | 
    
         
            +
                  assert_kind_of Enumerator::Lazy, mime_types.map.lazy
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
       33 
39 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                it 'is countable with an enumerator' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                  assert_equal 6, mime_types.each.count
         
     | 
| 
      
 42 
     | 
    
         
            +
                  assert_equal 6, mime_types.lazy.count
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
       37 
44 
     | 
    
         
             
              end
         
     | 
| 
       38 
45 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
               
     | 
| 
       40 
     | 
    
         
            -
                 
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
              describe '#\[]' do
         
     | 
| 
      
 47 
     | 
    
         
            +
                it 'can be searched with a MIME::Type' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  text_plain = MIME::Type.new('text/plain')
         
     | 
| 
      
 49 
     | 
    
         
            +
                  assert_includes mime_types[text_plain], 'text/plain'
         
     | 
| 
      
 50 
     | 
    
         
            +
                  assert_equal 1, mime_types[text_plain].size
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
       43 
52 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                 
     | 
| 
       48 
     | 
    
         
            -
                                         registered: true])
         
     | 
| 
       49 
     | 
    
         
            -
                refute_empty(@mime_types['application/gzip', registered: true])
         
     | 
| 
       50 
     | 
    
         
            -
                refute_equal(@mime_types['application/gzip'].size,
         
     | 
| 
       51 
     | 
    
         
            -
                             @mime_types['application/gzip', registered: true])
         
     | 
| 
       52 
     | 
    
         
            -
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
                it 'can be searched with a regular expression' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                  assert_includes mime_types[/plain$/], 'text/plain'
         
     | 
| 
      
 55 
     | 
    
         
            +
                  assert_equal 1, mime_types[/plain$/].size
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
       53 
57 
     | 
    
         | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                   
     | 
| 
      
 58 
     | 
    
         
            +
                it 'sorts by priority with multiple matches' do
         
     | 
| 
      
 59 
     | 
    
         
            +
                  assert_equal %w(application/gzip application/x-gzip), mime_types[/gzip$/]
         
     | 
| 
      
 60 
     | 
    
         
            +
                  assert_equal 2, mime_types[/gzip$/].size
         
     | 
| 
       57 
61 
     | 
    
         
             
                end
         
     | 
| 
       58 
     | 
    
         
            -
              end
         
     | 
| 
       59 
62 
     | 
    
         | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
                   
     | 
| 
       63 
     | 
    
         
            -
                  t.encoding = '8bit'
         
     | 
| 
      
 63 
     | 
    
         
            +
                it 'can be searched with a string' do
         
     | 
| 
      
 64 
     | 
    
         
            +
                  assert_includes mime_types['text/plain'], 'text/plain'
         
     | 
| 
      
 65 
     | 
    
         
            +
                  assert_equal 1, mime_types['text/plain'].size
         
     | 
| 
       64 
66 
     | 
    
         
             
                end
         
     | 
| 
       65 
67 
     | 
    
         | 
| 
       66 
     | 
    
         
            -
                 
     | 
| 
      
 68 
     | 
    
         
            +
                it 'can be searched with the complete flag' do
         
     | 
| 
      
 69 
     | 
    
         
            +
                  assert_empty mime_types[
         
     | 
| 
      
 70 
     | 
    
         
            +
                    'application/x-www-form-urlencoded',
         
     | 
| 
      
 71 
     | 
    
         
            +
                    complete: true
         
     | 
| 
      
 72 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 73 
     | 
    
         
            +
                  assert_includes mime_types['text/plain', complete: true], 'text/plain'
         
     | 
| 
      
 74 
     | 
    
         
            +
                  assert_equal 1, mime_types['text/plain', complete: true].size
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
       67 
76 
     | 
    
         | 
| 
       68 
     | 
    
         
            -
                 
     | 
| 
      
 77 
     | 
    
         
            +
                it 'can be searched with the registered flag' do
         
     | 
| 
      
 78 
     | 
    
         
            +
                  assert_empty mime_types['application/x-wordperfect6.1', registered: true]
         
     | 
| 
      
 79 
     | 
    
         
            +
                  refute_empty mime_types[
         
     | 
| 
      
 80 
     | 
    
         
            +
                    'application/x-www-form-urlencoded',
         
     | 
| 
      
 81 
     | 
    
         
            +
                    registered: true
         
     | 
| 
      
 82 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 83 
     | 
    
         
            +
                  refute_empty mime_types[/gzip/, registered: true]
         
     | 
| 
      
 84 
     | 
    
         
            +
                  refute_equal mime_types[/gzip/], mime_types[/gzip/, registered: true]
         
     | 
| 
      
 85 
     | 
    
         
            +
                end
         
     | 
| 
       69 
86 
     | 
    
         
             
              end
         
     | 
| 
       70 
87 
     | 
    
         | 
| 
       71 
     | 
    
         
            -
               
     | 
| 
       72 
     | 
    
         
            -
                 
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                 
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                  assert_equal(@mime_types.of('gif', true), @mime_types['image/gif'])
         
     | 
| 
      
 88 
     | 
    
         
            +
              describe '#add' do
         
     | 
| 
      
 89 
     | 
    
         
            +
                let(:eruby) { MIME::Type.new('application/x-eruby') }
         
     | 
| 
      
 90 
     | 
    
         
            +
                let(:jinja) { MIME::Type.new('application/jinja2' )}
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                it 'successfully adds a new type' do
         
     | 
| 
      
 93 
     | 
    
         
            +
                  mime_types.add(eruby)
         
     | 
| 
      
 94 
     | 
    
         
            +
                  assert_equal mime_types['application/x-eruby'], [ eruby ]
         
     | 
| 
       79 
95 
     | 
    
         
             
                end
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                 
     | 
| 
       82 
     | 
    
         
            -
                   
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                it 'complains about adding a duplicate type' do
         
     | 
| 
      
 98 
     | 
    
         
            +
                  mime_types.add(eruby)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  assert_output '', /is already registered as a variant/ do
         
     | 
| 
      
 100 
     | 
    
         
            +
                    mime_types.add(eruby)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  end
         
     | 
| 
      
 102 
     | 
    
         
            +
                  assert_equal mime_types['application/x-eruby'], [eruby]
         
     | 
| 
       83 
103 
     | 
    
         
             
                end
         
     | 
| 
       84 
     | 
    
         
            -
                assert_empty(@mime_types.type_for('zzz'))
         
     | 
| 
       85 
     | 
    
         
            -
              end
         
     | 
| 
       86 
104 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
      
 105 
     | 
    
         
            +
                it 'does not complain about adding a duplicate type when quiet' do
         
     | 
| 
      
 106 
     | 
    
         
            +
                  mime_types.add(eruby)
         
     | 
| 
      
 107 
     | 
    
         
            +
                  assert_output '', '' do
         
     | 
| 
      
 108 
     | 
    
         
            +
                    mime_types.add(eruby, :silent)
         
     | 
| 
      
 109 
     | 
    
         
            +
                  end
         
     | 
| 
      
 110 
     | 
    
         
            +
                  assert_equal mime_types['application/x-eruby'], [ eruby ]
         
     | 
| 
      
 111 
     | 
    
         
            +
                end
         
     | 
| 
       90 
112 
     | 
    
         | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                  @mime_types.add_type_variant(xtxp)
         
     | 
| 
      
 113 
     | 
    
         
            +
                it 'successfully adds from an array' do
         
     | 
| 
      
 114 
     | 
    
         
            +
                  mime_types.add([ eruby, jinja ])
         
     | 
| 
      
 115 
     | 
    
         
            +
                  assert_equal mime_types['application/x-eruby'], [ eruby ]
         
     | 
| 
      
 116 
     | 
    
         
            +
                  assert_equal mime_types['application/jinja2'], [ jinja ]
         
     | 
| 
       96 
117 
     | 
    
         
             
                end
         
     | 
| 
       97 
     | 
    
         
            -
                assert_includes(@mime_types['text/plain'], xtxp)
         
     | 
| 
       98 
     | 
    
         
            -
              end
         
     | 
| 
       99 
118 
     | 
    
         | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
      
 119 
     | 
    
         
            +
                it 'successfully adds from another MIME::Types' do
         
     | 
| 
      
 120 
     | 
    
         
            +
                  mt = MIME::Types.new
         
     | 
| 
      
 121 
     | 
    
         
            +
                  mt.add(mime_types)
         
     | 
| 
      
 122 
     | 
    
         
            +
                  assert_equal mime_types.count, mt.count
         
     | 
| 
       103 
123 
     | 
    
         | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
                assert_deprecated('MIME::Types#index_extensions', 'and will be private') do
         
     | 
| 
       108 
     | 
    
         
            -
                  @mime_types.index_extensions(xtxp)
         
     | 
| 
      
 124 
     | 
    
         
            +
                  mime_types.each do |type|
         
     | 
| 
      
 125 
     | 
    
         
            +
                    assert_equal mt[type.content_type], [ type ]
         
     | 
| 
      
 126 
     | 
    
         
            +
                  end
         
     | 
| 
       109 
127 
     | 
    
         
             
                end
         
     | 
| 
       110 
     | 
    
         
            -
                assert_includes(@mime_types.of('tzt'), xtxp)
         
     | 
| 
       111 
128 
     | 
    
         
             
              end
         
     | 
| 
       112 
129 
     | 
    
         | 
| 
       113 
     | 
    
         
            -
               
     | 
| 
       114 
     | 
    
         
            -
                 
     | 
| 
       115 
     | 
    
         
            -
                   
     | 
| 
      
 130 
     | 
    
         
            +
              describe '#type_for' do
         
     | 
| 
      
 131 
     | 
    
         
            +
                it 'finds all types for a given extension' do
         
     | 
| 
      
 132 
     | 
    
         
            +
                  assert_equal %w(application/gzip application/x-gzip),
         
     | 
| 
      
 133 
     | 
    
         
            +
                    mime_types.type_for('gz')
         
     | 
| 
      
 134 
     | 
    
         
            +
                end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                it 'separates the extension from filenames' do
         
     | 
| 
      
 137 
     | 
    
         
            +
                  assert_equal %w(image/jpeg), mime_types.of(['foo.jpeg', 'bar.jpeg'])
         
     | 
| 
       116 
138 
     | 
    
         
             
                end
         
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                it 'finds multiple extensions' do
         
     | 
| 
      
 141 
     | 
    
         
            +
                  assert_equal %w(image/jpeg text/plain),
         
     | 
| 
      
 142 
     | 
    
         
            +
                    mime_types.type_for(%w(foo.txt foo.jpeg))
         
     | 
| 
      
 143 
     | 
    
         
            +
                end
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
                it 'does not find unknown extensions' do
         
     | 
| 
      
 146 
     | 
    
         
            +
                  assert_empty mime_types.type_for('zzz')
         
     | 
| 
      
 147 
     | 
    
         
            +
                end
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                it 'modifying type extensions causes reindexing' do
         
     | 
| 
      
 150 
     | 
    
         
            +
                  plain_text = mime_types['text/plain'].first
         
     | 
| 
      
 151 
     | 
    
         
            +
                  plain_text.add_extensions('xtxt')
         
     | 
| 
      
 152 
     | 
    
         
            +
                  assert_includes mime_types.type_for('xtxt'), 'text/plain'
         
     | 
| 
      
 153 
     | 
    
         
            +
                end
         
     | 
| 
      
 154 
     | 
    
         
            +
              end
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
              describe '#count' do
         
     | 
| 
      
 157 
     | 
    
         
            +
                it 'can count the number of types inside' do
         
     | 
| 
      
 158 
     | 
    
         
            +
                  assert_equal 6, mime_types.count
         
     | 
| 
       119 
159 
     | 
    
         
             
                end
         
     | 
| 
       120 
160 
     | 
    
         
             
              end
         
     | 
| 
       121 
161 
     | 
    
         
             
            end
         
     | 
| 
         @@ -3,7 +3,7 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'mime/types'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'minitest_helper'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
            describe MIME::Types::Cache do
         
     | 
| 
       7 
7 
     | 
    
         
             
              def setup
         
     | 
| 
       8 
8 
     | 
    
         
             
                require 'fileutils'
         
     | 
| 
       9 
9 
     | 
    
         
             
                @cache_file = File.expand_path('../cache.tst', __FILE__)
         
     | 
| 
         @@ -25,66 +25,76 @@ class TestMIMETypesCache < Minitest::Test 
     | 
|
| 
       25 
25 
     | 
    
         
             
                FileUtils.rm @cache_file if File.exist? @cache_file
         
     | 
| 
       26 
26 
     | 
    
         
             
              end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
               
     | 
| 
       29 
     | 
    
         
            -
                 
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 28 
     | 
    
         
            +
              describe '.load' do
         
     | 
| 
      
 29 
     | 
    
         
            +
                it 'does not use cache when RUBY_MIME_TYPES_CACHE is unset' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                  ENV.delete('RUBY_MIME_TYPES_CACHE')
         
     | 
| 
      
 31 
     | 
    
         
            +
                  assert_equal(nil, MIME::Types::Cache.load)
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
      
 34 
     | 
    
         
            +
                it 'does not use cache when missing' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                  assert_equal(nil, MIME::Types::Cache.load)
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
      
 38 
     | 
    
         
            +
                it 'outputs an error when there is an invalid version' do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  v = MIME::Types::Data::VERSION.dup
         
     | 
| 
      
 40 
     | 
    
         
            +
                  MIME::Types::Data::VERSION.gsub!(/.*/, '0.0')
         
     | 
| 
      
 41 
     | 
    
         
            +
                  MIME::Types::Cache.save
         
     | 
| 
      
 42 
     | 
    
         
            +
                  MIME::Types::Data::VERSION.gsub!(/.*/, v)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  MIME::Types.instance_variable_set(:@__types__, nil)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  assert_output '', /MIME::Types cache: invalid version/ do
         
     | 
| 
      
 45 
     | 
    
         
            +
                    MIME::Types['text/html']
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
       41 
48 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
      
 49 
     | 
    
         
            +
                it 'outputs an error when there is a marshal file incompatibility' do
         
     | 
| 
      
 50 
     | 
    
         
            +
                  MIME::Types::Cache.save
         
     | 
| 
      
 51 
     | 
    
         
            +
                  data = File.binread(@cache_file).reverse
         
     | 
| 
      
 52 
     | 
    
         
            +
                  File.open(@cache_file, 'wb') { |f| f.write(data) }
         
     | 
| 
      
 53 
     | 
    
         
            +
                  MIME::Types.instance_variable_set(:@__types__, nil)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  assert_output '', /incompatible marshal file format/ do
         
     | 
| 
      
 55 
     | 
    
         
            +
                    MIME::Types['text/html']
         
     | 
| 
      
 56 
     | 
    
         
            +
                  end
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
       46 
58 
     | 
    
         
             
              end
         
     | 
| 
       47 
59 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
               
     | 
| 
       49 
     | 
    
         
            -
                 
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
              describe '.save' do
         
     | 
| 
      
 61 
     | 
    
         
            +
                it 'does not create cache when RUBY_MIME_TYPES_CACHE is unset' do
         
     | 
| 
      
 62 
     | 
    
         
            +
                  ENV.delete('RUBY_MIME_TYPES_CACHE')
         
     | 
| 
      
 63 
     | 
    
         
            +
                  assert_equal(nil, MIME::Types::Cache.save)
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
       52 
65 
     | 
    
         | 
| 
       53 
     | 
    
         
            -
                 
     | 
| 
      
 66 
     | 
    
         
            +
                it 'creates the cache ' do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  assert_equal(false, File.exist?(@cache_file))
         
     | 
| 
      
 68 
     | 
    
         
            +
                  MIME::Types::Cache.save
         
     | 
| 
      
 69 
     | 
    
         
            +
                  assert_equal(true, File.exist?(@cache_file))
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
       54 
71 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
                 
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
                it 'uses the cache' do
         
     | 
| 
      
 73 
     | 
    
         
            +
                  MIME::Types['text/html'].first.add_extensions('hex')
         
     | 
| 
      
 74 
     | 
    
         
            +
                  MIME::Types::Cache.save
         
     | 
| 
      
 75 
     | 
    
         
            +
                  MIME::Types.instance_variable_set(:@__types__, nil)
         
     | 
| 
       57 
76 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                v = MIME::Types::VERSION.dup
         
     | 
| 
       60 
     | 
    
         
            -
                MIME::Types::VERSION.gsub!(/.*/, '0.0')
         
     | 
| 
       61 
     | 
    
         
            -
                MIME::Types::Cache.save
         
     | 
| 
       62 
     | 
    
         
            -
                MIME::Types::VERSION.gsub!(/.*/, v)
         
     | 
| 
       63 
     | 
    
         
            -
                MIME::Types.instance_variable_set(:@__types__, nil)
         
     | 
| 
       64 
     | 
    
         
            -
                assert_output(nil, /MIME::Types cache: invalid version/) do
         
     | 
| 
       65 
     | 
    
         
            -
                  MIME::Types['text/html']
         
     | 
| 
       66 
     | 
    
         
            -
                end
         
     | 
| 
       67 
     | 
    
         
            -
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
                  assert_includes MIME::Types['text/html'].first.extensions, 'hex'
         
     | 
| 
       68 
78 
     | 
    
         | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                MIME::Types::Cache.save
         
     | 
| 
       71 
     | 
    
         
            -
                data = File.binread(@cache_file).reverse
         
     | 
| 
       72 
     | 
    
         
            -
                File.open(@cache_file, 'wb') { |f| f.write(data) }
         
     | 
| 
       73 
     | 
    
         
            -
                MIME::Types.instance_variable_set(:@__types__, nil)
         
     | 
| 
       74 
     | 
    
         
            -
                assert_output(nil, /Could not load MIME::Types cache: incompatible marshal file format/) do
         
     | 
| 
       75 
     | 
    
         
            -
                  MIME::Types['text/html']
         
     | 
| 
      
 79 
     | 
    
         
            +
                  reset_mime_types
         
     | 
| 
       76 
80 
     | 
    
         
             
                end
         
     | 
| 
       77 
81 
     | 
    
         
             
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
            end
         
     | 
| 
       78 
83 
     | 
    
         | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
      
 84 
     | 
    
         
            +
            describe MIME::Types::Container do
         
     | 
| 
      
 85 
     | 
    
         
            +
              it 'marshals and unmarshals correctly' do
         
     | 
| 
       80 
86 
     | 
    
         
             
                container = MIME::Types::Container.new
         
     | 
| 
       81 
     | 
    
         
            -
                 
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
      
 87 
     | 
    
         
            +
                container['xyz'] << 'abc'
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                # default proc should return Set[]
         
     | 
| 
      
 90 
     | 
    
         
            +
                assert_equal(Set[], container['abc'])
         
     | 
| 
      
 91 
     | 
    
         
            +
                assert_equal(Set['abc'], container['xyz'])
         
     | 
| 
       83 
92 
     | 
    
         | 
| 
       84 
93 
     | 
    
         
             
                marshalled = Marshal.dump(container)
         
     | 
| 
       85 
94 
     | 
    
         
             
                loaded_container = Marshal.load(marshalled)
         
     | 
| 
       86 
95 
     | 
    
         | 
| 
       87 
     | 
    
         
            -
                # default proc should still return []
         
     | 
| 
       88 
     | 
    
         
            -
                assert_equal([], loaded_container[' 
     | 
| 
      
 96 
     | 
    
         
            +
                # default proc should still return Set[]
         
     | 
| 
      
 97 
     | 
    
         
            +
                assert_equal(Set[], loaded_container['abc'])
         
     | 
| 
      
 98 
     | 
    
         
            +
                assert_equal(Set['abc'], container['xyz'])
         
     | 
| 
       89 
99 
     | 
    
         
             
              end
         
     | 
| 
       90 
100 
     | 
    
         
             
            end
         
     | 
| 
         @@ -3,137 +3,153 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            require 'mime/types'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require 'minitest_helper'
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
            describe MIME::Types, 'registry' do
         
     | 
| 
       7 
7 
     | 
    
         
             
              def setup
         
     | 
| 
       8 
8 
     | 
    
         
             
                MIME::Types.send(:load_default_mime_types)
         
     | 
| 
       9 
9 
     | 
    
         
             
              end
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
       12 
     | 
    
         
            -
                 
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                 
     | 
| 
       15 
     | 
    
         
            -
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
              describe 'is enumerable' do
         
     | 
| 
      
 12 
     | 
    
         
            +
                it 'correctly uses an Enumerable method like #any?' do
         
     | 
| 
      
 13 
     | 
    
         
            +
                  assert MIME::Types.any? { |type| type.content_type == 'text/plain' }
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
       16 
15 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                  MIME::Types.load_from_file(fn)
         
     | 
| 
      
 16 
     | 
    
         
            +
                it 'implements each with no parameters to return an Enumerator' do
         
     | 
| 
      
 17 
     | 
    
         
            +
                  assert_kind_of Enumerator, MIME::Types.each
         
     | 
| 
      
 18 
     | 
    
         
            +
                  assert_kind_of Enumerator, MIME::Types.map
         
     | 
| 
       21 
19 
     | 
    
         
             
                end
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
20 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
                 
     | 
| 
       28 
     | 
    
         
            -
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
                it 'will create a lazy enumerator' do
         
     | 
| 
      
 22 
     | 
    
         
            +
                  assert_kind_of Enumerator::Lazy, MIME::Types.lazy
         
     | 
| 
      
 23 
     | 
    
         
            +
                  assert_kind_of Enumerator::Lazy, MIME::Types.map.lazy
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
       29 
25 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
      
 26 
     | 
    
         
            +
                it 'is countable with an enumerator' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                  assert MIME::Types.each.count > 999
         
     | 
| 
      
 28 
     | 
    
         
            +
                  assert MIME::Types.lazy.count > 999
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
       33 
30 
     | 
    
         
             
              end
         
     | 
| 
       34 
31 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
               
     | 
| 
       36 
     | 
    
         
            -
                 
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
              describe '.\[]' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                it 'can be searched with a MIME::Type' do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  text_plain = MIME::Type.new('text/plain')
         
     | 
| 
      
 35 
     | 
    
         
            +
                  assert_includes MIME::Types[text_plain], 'text/plain'
         
     | 
| 
      
 36 
     | 
    
         
            +
                  assert_equal 1, MIME::Types[text_plain].size
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
       39 
38 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
                it 'can be searched with a regular expression' do
         
     | 
| 
      
 40 
     | 
    
         
            +
                  assert_includes MIME::Types[/plain$/], 'text/plain'
         
     | 
| 
      
 41 
     | 
    
         
            +
                  assert_equal 1, MIME::Types[/plain$/].size
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
       44 
43 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                refute_empty(MIME::Types['application/gzip', registered: true])
         
     | 
| 
       51 
     | 
    
         
            -
                refute_equal(MIME::Types['application/gzip'].size,
         
     | 
| 
       52 
     | 
    
         
            -
                             MIME::Types['application/gzip', registered: true])
         
     | 
| 
       53 
     | 
    
         
            -
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
                it 'sorts by priority with multiple matches' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                  assert_equal %w(application/gzip application/x-gzip multipart/x-gzip),
         
     | 
| 
      
 46 
     | 
    
         
            +
                    MIME::Types[/gzip$/]
         
     | 
| 
      
 47 
     | 
    
         
            +
                  assert_equal 3, MIME::Types[/gzip$/].size
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
       54 
49 
     | 
    
         | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                   
     | 
| 
      
 50 
     | 
    
         
            +
                it 'can be searched with a string' do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  assert_includes MIME::Types['text/plain'], 'text/plain'
         
     | 
| 
      
 52 
     | 
    
         
            +
                  assert_equal 1, MIME::Types['text/plain'].size
         
     | 
| 
       58 
53 
     | 
    
         
             
                end
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
54 
     | 
    
         | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
       67 
     | 
    
         
            -
                   
     | 
| 
      
 55 
     | 
    
         
            +
                it 'can be searched with the complete flag' do
         
     | 
| 
      
 56 
     | 
    
         
            +
                  assert_empty MIME::Types[
         
     | 
| 
      
 57 
     | 
    
         
            +
                    'application/x-www-form-urlencoded',
         
     | 
| 
      
 58 
     | 
    
         
            +
                    complete: true
         
     | 
| 
      
 59 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 60 
     | 
    
         
            +
                  assert_includes MIME::Types['text/plain', complete: true], 'text/plain'
         
     | 
| 
      
 61 
     | 
    
         
            +
                  assert_equal 1, MIME::Types['text/plain', complete: true].size
         
     | 
| 
       68 
62 
     | 
    
         
             
                end
         
     | 
| 
       69 
     | 
    
         
            -
                assert_empty(MIME::Types.type_for('zzz'))
         
     | 
| 
       70 
     | 
    
         
            -
              end
         
     | 
| 
       71 
63 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
      
 64 
     | 
    
         
            +
                it 'can be searched with the registered flag' do
         
     | 
| 
      
 65 
     | 
    
         
            +
                  assert_empty MIME::Types['application/x-wordperfect6.1', registered: true]
         
     | 
| 
      
 66 
     | 
    
         
            +
                  refute_empty MIME::Types[
         
     | 
| 
      
 67 
     | 
    
         
            +
                    'application/x-www-form-urlencoded',
         
     | 
| 
      
 68 
     | 
    
         
            +
                    registered: true
         
     | 
| 
      
 69 
     | 
    
         
            +
                  ]
         
     | 
| 
      
 70 
     | 
    
         
            +
                  refute_empty MIME::Types[/gzip/, registered: true]
         
     | 
| 
      
 71 
     | 
    
         
            +
                  refute_equal MIME::Types[/gzip/], MIME::Types[/gzip/, registered: true]
         
     | 
| 
      
 72 
     | 
    
         
            +
                end
         
     | 
| 
       75 
73 
     | 
    
         
             
              end
         
     | 
| 
       76 
74 
     | 
    
         | 
| 
       77 
     | 
    
         
            -
               
     | 
| 
       78 
     | 
    
         
            -
                 
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 75 
     | 
    
         
            +
              describe '.type_for' do
         
     | 
| 
      
 76 
     | 
    
         
            +
                it 'finds all types for a given extension' do
         
     | 
| 
      
 77 
     | 
    
         
            +
                  assert_equal %w(application/gzip application/x-gzip),
         
     | 
| 
      
 78 
     | 
    
         
            +
                    MIME::Types.type_for('gz')
         
     | 
| 
       81 
79 
     | 
    
         
             
                end
         
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                 
     | 
| 
       84 
     | 
    
         
            -
                   
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                it 'separates the extension from filenames' do
         
     | 
| 
      
 82 
     | 
    
         
            +
                  assert_equal %w(image/jpeg), MIME::Types.of(['foo.jpeg', 'bar.jpeg'])
         
     | 
| 
       85 
83 
     | 
    
         
             
                end
         
     | 
| 
       86 
     | 
    
         
            -
              end
         
     | 
| 
       87 
     | 
    
         
            -
            end
         
     | 
| 
       88 
84 
     | 
    
         | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
                 
     | 
| 
       93 
     | 
    
         
            -
              end
         
     | 
| 
      
 85 
     | 
    
         
            +
                it 'finds multiple extensions' do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  assert_equal %w(image/jpeg text/plain),
         
     | 
| 
      
 87 
     | 
    
         
            +
                    MIME::Types.type_for(%w(foo.txt foo.jpeg))
         
     | 
| 
      
 88 
     | 
    
         
            +
                end
         
     | 
| 
       94 
89 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                 
     | 
| 
       98 
     | 
    
         
            -
              end
         
     | 
| 
      
 90 
     | 
    
         
            +
                it 'does not find unknown extensions' do
         
     | 
| 
      
 91 
     | 
    
         
            +
                  assert_empty MIME::Types.type_for('zzz')
         
     | 
| 
      
 92 
     | 
    
         
            +
                end
         
     | 
| 
       99 
93 
     | 
    
         | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
                 
     | 
| 
      
 94 
     | 
    
         
            +
                it 'modifying type extensions causes reindexing' do
         
     | 
| 
      
 95 
     | 
    
         
            +
                  plain_text = MIME::Types['text/plain'].first
         
     | 
| 
      
 96 
     | 
    
         
            +
                  plain_text.add_extensions('xtxt')
         
     | 
| 
      
 97 
     | 
    
         
            +
                  assert_includes MIME::Types.type_for('xtxt'), 'text/plain'
         
     | 
| 
      
 98 
     | 
    
         
            +
                end
         
     | 
| 
       105 
99 
     | 
    
         
             
              end
         
     | 
| 
       106 
100 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
               
     | 
| 
       108 
     | 
    
         
            -
                 
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
      
 101 
     | 
    
         
            +
              describe '.count' do
         
     | 
| 
      
 102 
     | 
    
         
            +
                it 'can count the number of types inside' do
         
     | 
| 
      
 103 
     | 
    
         
            +
                  assert MIME::Types.count > 999
         
     | 
| 
      
 104 
     | 
    
         
            +
                end
         
     | 
| 
       110 
105 
     | 
    
         
             
              end
         
     | 
| 
       111 
106 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
               
     | 
| 
       113 
     | 
    
         
            -
                 
     | 
| 
       114 
     | 
    
         
            -
                  MIME::Types. 
     | 
| 
      
 107 
     | 
    
         
            +
              describe '.add' do
         
     | 
| 
      
 108 
     | 
    
         
            +
                def setup
         
     | 
| 
      
 109 
     | 
    
         
            +
                  MIME::Types.instance_variable_set(:@__types__, nil)
         
     | 
| 
      
 110 
     | 
    
         
            +
                  MIME::Types.send(:load_default_mime_types)
         
     | 
| 
      
 111 
     | 
    
         
            +
                end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                let(:eruby) { MIME::Type.new('application/x-eruby') }
         
     | 
| 
      
 114 
     | 
    
         
            +
                let(:jinja) { MIME::Type.new('application/jinja2' )}
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                it 'successfully adds a new type' do
         
     | 
| 
      
 117 
     | 
    
         
            +
                  MIME::Types.add(eruby)
         
     | 
| 
      
 118 
     | 
    
         
            +
                  assert_equal MIME::Types['application/x-eruby'], [ eruby ]
         
     | 
| 
       115 
119 
     | 
    
         
             
                end
         
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                it 'complains about adding a duplicate type' do
         
     | 
| 
      
 122 
     | 
    
         
            +
                  MIME::Types.add(eruby)
         
     | 
| 
      
 123 
     | 
    
         
            +
                  assert_output '', /is already registered as a variant/ do
         
     | 
| 
      
 124 
     | 
    
         
            +
                    MIME::Types.add(eruby)
         
     | 
| 
      
 125 
     | 
    
         
            +
                  end
         
     | 
| 
      
 126 
     | 
    
         
            +
                  assert_equal MIME::Types['application/x-eruby'], [eruby]
         
     | 
| 
       118 
127 
     | 
    
         
             
                end
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
      
 128 
     | 
    
         
            +
             
     | 
| 
      
 129 
     | 
    
         
            +
                it 'does not complain about adding a duplicate type when quiet' do
         
     | 
| 
      
 130 
     | 
    
         
            +
                  MIME::Types.add(eruby)
         
     | 
| 
      
 131 
     | 
    
         
            +
                  assert_silent do
         
     | 
| 
      
 132 
     | 
    
         
            +
                    MIME::Types.add(eruby, :silent)
         
     | 
| 
      
 133 
     | 
    
         
            +
                  end
         
     | 
| 
      
 134 
     | 
    
         
            +
                  assert_equal MIME::Types['application/x-eruby'], [ eruby ]
         
     | 
| 
       121 
135 
     | 
    
         
             
                end
         
     | 
| 
       122 
     | 
    
         
            -
              end
         
     | 
| 
       123 
136 
     | 
    
         | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
                  MIME::Types 
     | 
| 
      
 137 
     | 
    
         
            +
                it 'successfully adds from an array' do
         
     | 
| 
      
 138 
     | 
    
         
            +
                  MIME::Types.add([ eruby, jinja ])
         
     | 
| 
      
 139 
     | 
    
         
            +
                  assert_equal MIME::Types['application/x-eruby'], [ eruby ]
         
     | 
| 
      
 140 
     | 
    
         
            +
                  assert_equal MIME::Types['application/jinja2'], [ jinja ]
         
     | 
| 
       128 
141 
     | 
    
         
             
                end
         
     | 
| 
       129 
     | 
    
         
            -
                assert_includes(MIME::Types['text/plain'], xtxp)
         
     | 
| 
       130 
     | 
    
         
            -
              end
         
     | 
| 
       131 
142 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
                  MIME::Types. 
     | 
| 
      
 143 
     | 
    
         
            +
                it 'successfully adds from another MIME::Types' do
         
     | 
| 
      
 144 
     | 
    
         
            +
                  old_count = MIME::Types.count
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                  mt = MIME::Types.new
         
     | 
| 
      
 147 
     | 
    
         
            +
                  mt.add(eruby)
         
     | 
| 
      
 148 
     | 
    
         
            +
             
     | 
| 
      
 149 
     | 
    
         
            +
                  MIME::Types.add(mt)
         
     | 
| 
      
 150 
     | 
    
         
            +
                  assert_equal old_count + 1, MIME::Types.count
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                  assert_equal MIME::Types[eruby.content_type], [ eruby ]
         
     | 
| 
       136 
153 
     | 
    
         
             
                end
         
     | 
| 
       137 
     | 
    
         
            -
                assert_includes(MIME::Types.of('tzt'), xtxp)
         
     | 
| 
       138 
154 
     | 
    
         
             
              end
         
     | 
| 
       139 
155 
     | 
    
         
             
            end
         
     |