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.
- checksums.yaml +7 -0
- data/.autotest +35 -0
- data/.gitignore +17 -0
- data/.hoerc +20 -12
- data/Code-of-Conduct.rdoc +41 -0
- data/Contributing.rdoc +169 -0
- data/History.rdoc +531 -30
- data/Licence.rdoc +25 -0
- data/Manifest.txt +32 -34
- data/README.rdoc +198 -13
- data/Rakefile +181 -159
- data/lib/mime/type/columnar.rb +55 -0
- data/lib/mime/type.rb +566 -0
- data/lib/mime/types/cache.rb +56 -0
- data/lib/mime/types/columnar.rb +142 -0
- data/lib/mime/types/container.rb +30 -0
- data/lib/mime/types/deprecations.rb +32 -0
- data/lib/mime/types/full.rb +17 -0
- data/lib/mime/types/loader.rb +148 -0
- data/lib/mime/types/logger.rb +37 -0
- data/lib/mime/types/registry.rb +81 -0
- data/lib/mime/types.rb +199 -819
- data/lib/mime-types.rb +1 -0
- data/support/benchmarks/load.rb +65 -0
- data/support/benchmarks/load_allocations.rb +90 -0
- data/support/benchmarks/object_counts.rb +43 -0
- data/support/profile/columnar.rb +5 -0
- data/support/profile/columnar_full.rb +5 -0
- data/support/profile/full.rb +5 -0
- data/test/bad-fixtures/malformed +9 -0
- data/test/fixture/json.json +1 -0
- data/test/fixture/old-data +9 -0
- data/test/fixture/yaml.yaml +55 -0
- data/test/minitest_helper.rb +12 -0
- data/test/test_mime_type.rb +527 -242
- data/test/test_mime_types.rb +130 -68
- data/test/test_mime_types_cache.rb +100 -0
- data/test/test_mime_types_class.rb +155 -0
- data/test/test_mime_types_lazy.rb +43 -0
- data/test/test_mime_types_loader.rb +32 -0
- metadata +286 -229
- data/License.rdoc +0 -10
- data/lib/mime/types/application +0 -940
- data/lib/mime/types/application.mac +0 -2
- data/lib/mime/types/application.nonstandard +0 -114
- data/lib/mime/types/application.obsolete +0 -40
- data/lib/mime/types/audio +0 -131
- data/lib/mime/types/audio.nonstandard +0 -10
- data/lib/mime/types/audio.obsolete +0 -1
- data/lib/mime/types/image +0 -43
- data/lib/mime/types/image.nonstandard +0 -17
- data/lib/mime/types/image.obsolete +0 -5
- data/lib/mime/types/message +0 -19
- data/lib/mime/types/message.obsolete +0 -1
- data/lib/mime/types/model +0 -15
- data/lib/mime/types/multipart +0 -14
- data/lib/mime/types/multipart.nonstandard +0 -1
- data/lib/mime/types/multipart.obsolete +0 -7
- data/lib/mime/types/other.nonstandard +0 -8
- data/lib/mime/types/text +0 -54
- data/lib/mime/types/text.nonstandard +0 -5
- data/lib/mime/types/text.obsolete +0 -7
- data/lib/mime/types/text.vms +0 -1
- data/lib/mime/types/video +0 -68
- data/lib/mime/types/video.nonstandard +0 -11
- data/lib/mime/types/video.obsolete +0 -3
- data/mime-types.gemspec +0 -57
- data/type-lists/application.txt +0 -951
- data/type-lists/audio.txt +0 -132
- data/type-lists/image.txt +0 -43
- data/type-lists/message.txt +0 -20
- data/type-lists/model.txt +0 -15
- data/type-lists/multipart.txt +0 -14
- data/type-lists/text.txt +0 -57
- data/type-lists/video.txt +0 -67
data/test/test_mime_types.rb
CHANGED
@@ -1,99 +1,161 @@
|
|
1
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
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
|
-
|
42
|
-
eruby
|
43
|
-
|
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
|
-
|
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
|
-
|
50
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
73
|
-
|
124
|
+
mime_types.each do |type|
|
125
|
+
assert_equal mt[type.content_type], [ type ]
|
126
|
+
end
|
127
|
+
end
|
74
128
|
end
|
75
129
|
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
145
|
+
it 'does not find unknown extensions' do
|
146
|
+
assert_empty mime_types.type_for('zzz')
|
147
|
+
end
|
91
148
|
|
92
|
-
|
93
|
-
|
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
|
-
|
97
|
-
|
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
|