mime-types 1.17.2 → 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.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +35 -0
  3. data/.gitignore +17 -0
  4. data/.hoerc +20 -12
  5. data/Code-of-Conduct.rdoc +41 -0
  6. data/Contributing.rdoc +169 -0
  7. data/History.rdoc +531 -30
  8. data/Licence.rdoc +25 -0
  9. data/Manifest.txt +32 -34
  10. data/README.rdoc +198 -13
  11. data/Rakefile +181 -159
  12. data/lib/mime/type/columnar.rb +55 -0
  13. data/lib/mime/type.rb +566 -0
  14. data/lib/mime/types/cache.rb +56 -0
  15. data/lib/mime/types/columnar.rb +142 -0
  16. data/lib/mime/types/container.rb +30 -0
  17. data/lib/mime/types/deprecations.rb +32 -0
  18. data/lib/mime/types/full.rb +17 -0
  19. data/lib/mime/types/loader.rb +148 -0
  20. data/lib/mime/types/logger.rb +37 -0
  21. data/lib/mime/types/registry.rb +81 -0
  22. data/lib/mime/types.rb +199 -819
  23. data/lib/mime-types.rb +1 -0
  24. data/support/benchmarks/load.rb +65 -0
  25. data/support/benchmarks/load_allocations.rb +90 -0
  26. data/support/benchmarks/object_counts.rb +43 -0
  27. data/support/profile/columnar.rb +5 -0
  28. data/support/profile/columnar_full.rb +5 -0
  29. data/support/profile/full.rb +5 -0
  30. data/test/bad-fixtures/malformed +9 -0
  31. data/test/fixture/json.json +1 -0
  32. data/test/fixture/old-data +9 -0
  33. data/test/fixture/yaml.yaml +55 -0
  34. data/test/minitest_helper.rb +12 -0
  35. data/test/test_mime_type.rb +527 -242
  36. data/test/test_mime_types.rb +130 -68
  37. data/test/test_mime_types_cache.rb +100 -0
  38. data/test/test_mime_types_class.rb +155 -0
  39. data/test/test_mime_types_lazy.rb +43 -0
  40. data/test/test_mime_types_loader.rb +32 -0
  41. metadata +286 -229
  42. data/License.rdoc +0 -10
  43. data/lib/mime/types/application +0 -940
  44. data/lib/mime/types/application.mac +0 -2
  45. data/lib/mime/types/application.nonstandard +0 -114
  46. data/lib/mime/types/application.obsolete +0 -40
  47. data/lib/mime/types/audio +0 -131
  48. data/lib/mime/types/audio.nonstandard +0 -10
  49. data/lib/mime/types/audio.obsolete +0 -1
  50. data/lib/mime/types/image +0 -43
  51. data/lib/mime/types/image.nonstandard +0 -17
  52. data/lib/mime/types/image.obsolete +0 -5
  53. data/lib/mime/types/message +0 -19
  54. data/lib/mime/types/message.obsolete +0 -1
  55. data/lib/mime/types/model +0 -15
  56. data/lib/mime/types/multipart +0 -14
  57. data/lib/mime/types/multipart.nonstandard +0 -1
  58. data/lib/mime/types/multipart.obsolete +0 -7
  59. data/lib/mime/types/other.nonstandard +0 -8
  60. data/lib/mime/types/text +0 -54
  61. data/lib/mime/types/text.nonstandard +0 -5
  62. data/lib/mime/types/text.obsolete +0 -7
  63. data/lib/mime/types/text.vms +0 -1
  64. data/lib/mime/types/video +0 -68
  65. data/lib/mime/types/video.nonstandard +0 -11
  66. data/lib/mime/types/video.obsolete +0 -3
  67. data/mime-types.gemspec +0 -57
  68. data/type-lists/application.txt +0 -951
  69. data/type-lists/audio.txt +0 -132
  70. data/type-lists/image.txt +0 -43
  71. data/type-lists/message.txt +0 -20
  72. data/type-lists/model.txt +0 -15
  73. data/type-lists/multipart.txt +0 -14
  74. data/type-lists/text.txt +0 -57
  75. data/type-lists/video.txt +0 -67
@@ -1,99 +1,161 @@
1
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
1
+ # -*- ruby encoding: utf-8 -*-
2
2
 
3
3
  require 'mime/types'
4
+ require 'minitest_helper'
5
+
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
23
+ end
4
24
 
5
- class TestMIME_Types < MiniTest::Unit::TestCase #:nodoc:
6
- def test_class_index_1
7
- text_plain = MIME::Type.new('text/plain') do |t|
8
- t.encoding = '8bit'
9
- t.extensions = %w(asc txt c cc h hh cpp hpp dat hlp)
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' }
10
28
  end
11
- text_plain_vms = MIME::Type.new('text/plain') do |t|
12
- t.encoding = '8bit'
13
- t.extensions = %w(doc)
14
- t.system = 'vms'
29
+
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
34
+
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
15
38
  end
16
39
 
17
- assert_equal(MIME::Types['text/plain'], [text_plain, text_plain_vms])
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
18
44
  end
19
45
 
20
- def test_class_index_2
21
- tst_bmp = MIME::Types["image/x-bmp"] +
22
- MIME::Types["image/vnd.wap.wbmp"] + MIME::Types["image/x-win-bmp"]
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
23
52
 
24
- assert_equal(tst_bmp.sort, MIME::Types[/bmp$/].sort)
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
25
57
 
26
- MIME::Types['image/bmp'][0].system = RUBY_PLATFORM
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
61
+ end
27
62
 
28
- assert_equal([MIME::Type.from_array('image/x-bmp', ['bmp'])],
29
- MIME::Types[/bmp$/, { :platform => true }])
30
- end
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
66
+ end
31
67
 
32
- def test_class_index_3
33
- assert(MIME::Types['text/vnd.fly', { :complete => true }].empty?)
34
- assert(!MIME::Types['text/plain', { :complete => true} ].empty?)
35
- end
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
36
76
 
37
- def _test_class_index_extensions
38
- raise NotImplementedError, 'Need to write test_class_index_extensions'
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
39
86
  end
40
87
 
41
- def test_class_add
42
- eruby = MIME::Type.new("application/x-eruby") do |t|
43
- t.extensions = "rhtml"
44
- t.encoding = "8bit"
45
- end
88
+ describe '#add' do
89
+ let(:eruby) { MIME::Type.new('application/x-eruby') }
90
+ let(:jinja) { MIME::Type.new('application/jinja2' )}
46
91
 
47
- MIME::Types.add(eruby)
92
+ it 'successfully adds a new type' do
93
+ mime_types.add(eruby)
94
+ assert_equal mime_types['application/x-eruby'], [ eruby ]
95
+ end
48
96
 
49
- assert_equal(MIME::Types['application/x-eruby'], [eruby])
50
- end
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]
103
+ end
51
104
 
52
- def _test_class_add_type_variant
53
- raise NotImplementedError, 'Need to write test_class_add_type_variant'
54
- end
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
55
112
 
56
- def test_class_type_for
57
- assert_equal(MIME::Types.type_for('xml').sort, [ MIME::Types['text/xml'], MIME::Types['application/xml'] ].sort)
58
- assert_equal(MIME::Types.type_for('gif'), MIME::Types['image/gif'])
59
- MIME::Types['image/gif'][0].system = RUBY_PLATFORM
60
- assert_equal(MIME::Types.type_for('gif', true), MIME::Types['image/gif'])
61
- assert(MIME::Types.type_for('zzz').empty?)
62
- end
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 ]
117
+ end
63
118
 
64
- def test_class_of
65
- assert_equal(MIME::Types.of('xml').sort, [ MIME::Types['text/xml'], MIME::Types['application/xml'] ].sort)
66
- assert_equal(MIME::Types.of('gif'), MIME::Types['image/gif'])
67
- MIME::Types['image/gif'][0].system = RUBY_PLATFORM
68
- assert_equal(MIME::Types.of('gif', true), MIME::Types['image/gif'])
69
- assert(MIME::Types.of('zzz').empty?)
70
- end
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
71
123
 
72
- def _test_add
73
- raise NotImplementedError, 'Need to write test_add'
124
+ mime_types.each do |type|
125
+ assert_equal mt[type.content_type], [ type ]
126
+ end
127
+ end
74
128
  end
75
129
 
76
- def _test_add_type_variant
77
- raise NotImplementedError, 'Need to write test_add_type_variant'
78
- end
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
79
135
 
80
- def _test_data_version
81
- raise NotImplementedError, 'Need to write test_data_version'
82
- end
136
+ it 'separates the extension from filenames' do
137
+ assert_equal %w(image/jpeg), mime_types.of(['foo.jpeg', 'bar.jpeg'])
138
+ end
83
139
 
84
- def _test_index
85
- raise NotImplementedError, 'Need to write test_index'
86
- end
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
87
144
 
88
- def _test_index_extensions
89
- raise NotImplementedError, 'Need to write test_index_extensions'
90
- end
145
+ it 'does not find unknown extensions' do
146
+ assert_empty mime_types.type_for('zzz')
147
+ end
91
148
 
92
- def _test_of
93
- raise NotImplementedError, 'Need to write test_of'
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
94
154
  end
95
155
 
96
- def _test_type_for
97
- raise NotImplementedError, 'Need to write test_type_for'
156
+ describe '#count' do
157
+ it 'can count the number of types inside' do
158
+ assert_equal 6, mime_types.count
159
+ end
98
160
  end
99
161
  end
@@ -0,0 +1,100 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+
3
+ require 'mime/types'
4
+ require 'minitest_helper'
5
+
6
+ describe MIME::Types::Cache do
7
+ def setup
8
+ require 'fileutils'
9
+ @cache_file = File.expand_path('../cache.tst', __FILE__)
10
+ ENV['RUBY_MIME_TYPES_CACHE'] = @cache_file
11
+ clear_cache_file
12
+ end
13
+
14
+ def teardown
15
+ clear_cache_file
16
+ ENV.delete('RUBY_MIME_TYPES_CACHE')
17
+ end
18
+
19
+ def reset_mime_types
20
+ MIME::Types.instance_variable_set(:@__types__, nil)
21
+ MIME::Types.send(:load_default_mime_types)
22
+ end
23
+
24
+ def clear_cache_file
25
+ FileUtils.rm @cache_file if File.exist? @cache_file
26
+ end
27
+
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
33
+
34
+ it 'does not use cache when missing' do
35
+ assert_equal(nil, MIME::Types::Cache.load)
36
+ end
37
+
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
48
+
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
58
+ end
59
+
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
65
+
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
71
+
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)
76
+
77
+ assert_includes MIME::Types['text/html'].first.extensions, 'hex'
78
+
79
+ reset_mime_types
80
+ end
81
+ end
82
+ end
83
+
84
+ describe MIME::Types::Container do
85
+ it 'marshals and unmarshals correctly' do
86
+ container = MIME::Types::Container.new
87
+ container['xyz'] << 'abc'
88
+
89
+ # default proc should return Set[]
90
+ assert_equal(Set[], container['abc'])
91
+ assert_equal(Set['abc'], container['xyz'])
92
+
93
+ marshalled = Marshal.dump(container)
94
+ loaded_container = Marshal.load(marshalled)
95
+
96
+ # default proc should still return Set[]
97
+ assert_equal(Set[], loaded_container['abc'])
98
+ assert_equal(Set['abc'], container['xyz'])
99
+ end
100
+ end
@@ -0,0 +1,155 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+
3
+ require 'mime/types'
4
+ require 'minitest_helper'
5
+
6
+ describe MIME::Types, 'registry' do
7
+ def setup
8
+ MIME::Types.send(:load_default_mime_types)
9
+ end
10
+
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
15
+
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
19
+ end
20
+
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
25
+
26
+ it 'is countable with an enumerator' do
27
+ assert MIME::Types.each.count > 999
28
+ assert MIME::Types.lazy.count > 999
29
+ end
30
+ end
31
+
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
38
+
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
43
+
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
49
+
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
53
+ end
54
+
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
62
+ end
63
+
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
73
+ end
74
+
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')
79
+ end
80
+
81
+ it 'separates the extension from filenames' do
82
+ assert_equal %w(image/jpeg), MIME::Types.of(['foo.jpeg', 'bar.jpeg'])
83
+ end
84
+
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
89
+
90
+ it 'does not find unknown extensions' do
91
+ assert_empty MIME::Types.type_for('zzz')
92
+ end
93
+
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
99
+ end
100
+
101
+ describe '.count' do
102
+ it 'can count the number of types inside' do
103
+ assert MIME::Types.count > 999
104
+ end
105
+ end
106
+
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 ]
119
+ end
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]
127
+ end
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 ]
135
+ end
136
+
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 ]
141
+ end
142
+
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 ]
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,43 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+
3
+ require 'mime/types'
4
+ require 'minitest_helper'
5
+
6
+ describe MIME::Types, 'lazy loading' do
7
+ def setup
8
+ ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'true'
9
+ end
10
+
11
+ def teardown
12
+ reset_mime_types
13
+ ENV.delete('RUBY_MIME_TYPES_LAZY_LOAD')
14
+ end
15
+
16
+ def reset_mime_types
17
+ MIME::Types.instance_variable_set(:@__types__, nil)
18
+ MIME::Types.send(:load_default_mime_types)
19
+ end
20
+
21
+ describe '.lazy_load?' do
22
+ it 'is true when RUBY_MIME_TYPES_LAZY_LOAD is set' do
23
+ assert_equal true, MIME::Types.send(:lazy_load?)
24
+ end
25
+
26
+ it 'is nil when RUBY_MIME_TYPES_LAZY_LOAD is unset' do
27
+ ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = nil
28
+ assert_equal nil, MIME::Types.send(:lazy_load?)
29
+ end
30
+
31
+ it 'is false when RUBY_MIME_TYPES_LAZY_LOAD is false' do
32
+ ENV['RUBY_MIME_TYPES_LAZY_LOAD'] = 'false'
33
+ assert_equal false, MIME::Types.send(:lazy_load?)
34
+ end
35
+ end
36
+
37
+ it 'loads lazily when RUBY_MIME_TYPES_LAZY_LOAD is set' do
38
+ MIME::Types.instance_variable_set(:@__types__, nil)
39
+ assert_nil MIME::Types.instance_variable_get(:@__types__)
40
+ refute_nil MIME::Types['text/html'].first
41
+ refute_nil MIME::Types.instance_variable_get(:@__types__)
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ # -*- ruby encoding: utf-8 -*-
2
+
3
+ require 'mime/types'
4
+ require 'minitest_helper'
5
+
6
+ describe MIME::Types::Loader do
7
+ def setup
8
+ @path = File.expand_path('../fixture', __FILE__)
9
+ @loader = MIME::Types::Loader.new(@path)
10
+ @bad_path = File.expand_path('../bad-fixtures', __FILE__)
11
+ end
12
+
13
+ def assert_correctly_loaded(types)
14
+ assert_includes(types, 'application/1d-interleaved-parityfec')
15
+ assert_equal(%w(webm), types['audio/webm'].first.extensions)
16
+ refute(types['audio/webm'].first.registered?)
17
+
18
+ assert_equal('Fixes a bug with IE6 and progressive JPEGs',
19
+ types['image/pjpeg'].first.docs)
20
+
21
+ assert(types['audio/vnd.qcelp'].first.obsolete?)
22
+ assert_equal('audio/QCELP', types['audio/vnd.qcelp'].first.use_instead)
23
+ end
24
+
25
+ it 'loads YAML files correctly' do
26
+ assert_correctly_loaded @loader.load_yaml
27
+ end
28
+
29
+ it 'loads JSON files correctly' do
30
+ assert_correctly_loaded @loader.load_json
31
+ end
32
+ end