mime-types 1.16 → 3.5.2
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/.standard.yml +4 -0
- data/Code-of-Conduct.md +73 -0
- data/Contributing.md +133 -0
- data/History.md +335 -0
- data/Licence.md +25 -0
- data/Manifest.txt +27 -7
- data/README.rdoc +194 -0
- data/Rakefile +191 -278
- data/lib/mime/type/columnar.rb +57 -0
- data/lib/mime/type.rb +660 -0
- data/lib/mime/types/_columnar.rb +137 -0
- data/lib/mime/types/cache.rb +54 -0
- data/lib/mime/types/columnar.rb +3 -0
- data/lib/mime/types/container.rb +96 -0
- data/lib/mime/types/deprecations.rb +36 -0
- data/lib/mime/types/full.rb +19 -0
- data/lib/mime/types/loader.rb +159 -0
- data/lib/mime/types/logger.rb +37 -0
- data/lib/mime/types/registry.rb +90 -0
- data/lib/mime/types.rb +197 -715
- data/lib/mime-types.rb +3 -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 +10 -0
- data/test/test_mime_type.rb +585 -284
- data/test/test_mime_types.rb +134 -83
- data/test/test_mime_types_cache.rb +118 -0
- data/test/test_mime_types_class.rb +164 -0
- data/test/test_mime_types_lazy.rb +49 -0
- data/test/test_mime_types_loader.rb +32 -0
- metadata +295 -110
- data/History.txt +0 -107
- data/Install.txt +0 -17
- data/Licence.txt +0 -15
- data/README.txt +0 -28
- data/lib/mime/types.rb.data +0 -1324
- data/mime-types.gemspec +0 -43
- data/setup.rb +0 -1585
- data.tar.gz.sig +0 -2
- metadata.gz.sig +0 -0
data/test/test_mime_types.rb
CHANGED
@@ -1,122 +1,173 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
text_plain_vms = MIME::Type.new('text/plain') do |t|
|
26
|
-
t.encoding = '8bit'
|
27
|
-
t.extensions = %w(doc)
|
28
|
-
t.system = 'vms'
|
29
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
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 { |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
|
+
}
|
23
|
+
end
|
30
24
|
|
31
|
-
|
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" })
|
32
28
|
end
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
37
34
|
|
38
|
-
|
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
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
44
|
+
end
|
43
45
|
|
44
|
-
|
45
|
-
|
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
|
46
51
|
end
|
47
52
|
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
51
56
|
end
|
52
57
|
|
53
|
-
|
54
|
-
|
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
|
55
61
|
end
|
56
62
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
t.encoding = "8bit"
|
62
|
-
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
|
63
67
|
|
64
|
-
|
65
|
-
|
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
|
76
|
+
|
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
|
66
86
|
|
67
|
-
|
87
|
+
it "properly returns an empty result on a regular expression miss" do
|
88
|
+
assert_empty mime_types[/^foo/]
|
89
|
+
assert_empty mime_types[/^foo/, registered: true]
|
90
|
+
assert_empty mime_types[/^foo/, complete: true]
|
68
91
|
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#add" do
|
95
|
+
let(:eruby) { MIME::Type.new("application/x-eruby") }
|
96
|
+
let(:jinja) { MIME::Type.new("application/jinja2") }
|
69
97
|
|
70
|
-
|
71
|
-
|
98
|
+
it "successfully adds a new type" do
|
99
|
+
mime_types.add(eruby)
|
100
|
+
assert_equal mime_types["application/x-eruby"], [eruby]
|
72
101
|
end
|
73
102
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
MIME::Types['image/gif'][0].system = RUBY_PLATFORM
|
103
|
+
it "complains about adding a duplicate type" do
|
104
|
+
mime_types.add(eruby)
|
105
|
+
assert_output "", /is already registered as a variant/ do
|
106
|
+
mime_types.add(eruby)
|
79
107
|
end
|
80
|
-
assert_equal
|
81
|
-
assert(MIME::Types.type_for('zzz').empty?)
|
108
|
+
assert_equal mime_types["application/x-eruby"], [eruby]
|
82
109
|
end
|
83
110
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
MIME::Types['image/gif'][0].system = RUBY_PLATFORM
|
111
|
+
it "does not complain about adding a duplicate type when quiet" do
|
112
|
+
mime_types.add(eruby)
|
113
|
+
assert_output "", "" do
|
114
|
+
mime_types.add(eruby, :silent)
|
89
115
|
end
|
90
|
-
assert_equal
|
91
|
-
assert(MIME::Types.of('zzz').empty?)
|
116
|
+
assert_equal mime_types["application/x-eruby"], [eruby]
|
92
117
|
end
|
93
118
|
|
94
|
-
|
95
|
-
|
119
|
+
it "successfully adds from an array" do
|
120
|
+
mime_types.add([eruby, jinja])
|
121
|
+
assert_equal mime_types["application/x-eruby"], [eruby]
|
122
|
+
assert_equal mime_types["application/jinja2"], [jinja]
|
96
123
|
end
|
97
124
|
|
98
|
-
|
99
|
-
|
125
|
+
it "successfully adds from another MIME::Types" do
|
126
|
+
mt = MIME::Types.new
|
127
|
+
mt.add(mime_types)
|
128
|
+
assert_equal mime_types.count, mt.count
|
129
|
+
|
130
|
+
mime_types.each do |type|
|
131
|
+
assert_equal mt[type.content_type], [type]
|
132
|
+
end
|
100
133
|
end
|
134
|
+
end
|
101
135
|
|
102
|
-
|
103
|
-
|
136
|
+
describe "#type_for" do
|
137
|
+
it "finds all types for a given extension" do
|
138
|
+
assert_equal %w[application/gzip application/x-gzip],
|
139
|
+
mime_types.type_for("gz")
|
104
140
|
end
|
105
141
|
|
106
|
-
|
107
|
-
|
142
|
+
it "separates the extension from filenames" do
|
143
|
+
assert_equal %w[image/jpeg], mime_types.of(["foo.jpeg", "bar.jpeg"])
|
108
144
|
end
|
109
145
|
|
110
|
-
|
111
|
-
|
146
|
+
it "finds multiple extensions" do
|
147
|
+
assert_equal %w[image/jpeg text/plain],
|
148
|
+
mime_types.type_for(%w[foo.txt foo.jpeg])
|
112
149
|
end
|
113
150
|
|
114
|
-
|
115
|
-
|
151
|
+
it "does not find unknown extensions" do
|
152
|
+
keys = mime_types.instance_variable_get(:@extension_index).keys
|
153
|
+
assert_empty mime_types.type_for("zzz")
|
154
|
+
assert_equal keys, mime_types.instance_variable_get(:@extension_index).keys
|
116
155
|
end
|
117
156
|
|
118
|
-
|
119
|
-
|
157
|
+
it "modifying type extensions causes reindexing" do
|
158
|
+
plain_text = mime_types["text/plain"].first
|
159
|
+
plain_text.add_extensions("xtxt")
|
160
|
+
assert_includes mime_types.type_for("xtxt"), "text/plain"
|
161
|
+
end
|
162
|
+
|
163
|
+
it "handles newline characters correctly" do
|
164
|
+
assert_includes mime_types.type_for("test.pdf\n.txt"), "text/plain"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "#count" do
|
169
|
+
it "can count the number of types inside" do
|
170
|
+
assert_equal 6, mime_types.count
|
120
171
|
end
|
121
172
|
end
|
122
173
|
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "mime/types"
|
4
|
+
require "minitest_helper"
|
5
|
+
|
6
|
+
MUTEX = Mutex.new
|
7
|
+
|
8
|
+
describe MIME::Types::Cache do
|
9
|
+
include Minitest::Hooks
|
10
|
+
|
11
|
+
def around
|
12
|
+
require "fileutils"
|
13
|
+
|
14
|
+
MUTEX.synchronize do
|
15
|
+
@cache_file = File.expand_path("../cache.tst", __FILE__)
|
16
|
+
ENV["RUBY_MIME_TYPES_CACHE"] = @cache_file
|
17
|
+
clear_cache_file
|
18
|
+
|
19
|
+
super
|
20
|
+
|
21
|
+
clear_cache_file
|
22
|
+
ENV.delete("RUBY_MIME_TYPES_CACHE")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def reset_mime_types
|
27
|
+
MIME::Types.instance_variable_set(:@__types__, nil)
|
28
|
+
MIME::Types.send(:load_default_mime_types)
|
29
|
+
end
|
30
|
+
|
31
|
+
def clear_cache_file
|
32
|
+
FileUtils.rm @cache_file if File.exist? @cache_file
|
33
|
+
end
|
34
|
+
|
35
|
+
describe ".load" do
|
36
|
+
it "does not use cache when RUBY_MIME_TYPES_CACHE is unset" do
|
37
|
+
ENV.delete("RUBY_MIME_TYPES_CACHE")
|
38
|
+
assert_nil MIME::Types::Cache.load
|
39
|
+
end
|
40
|
+
|
41
|
+
it "does not use cache when missing" do
|
42
|
+
assert_nil MIME::Types::Cache.load
|
43
|
+
end
|
44
|
+
|
45
|
+
it "registers the data to be updated by #add_extensions" do
|
46
|
+
MIME::Types::Cache.save
|
47
|
+
reset_mime_types
|
48
|
+
assert_equal([], MIME::Types.type_for("foo.additional"))
|
49
|
+
html = MIME::Types["text/html"][0]
|
50
|
+
html.add_extensions("additional")
|
51
|
+
assert_equal([html], MIME::Types.type_for("foo.additional"))
|
52
|
+
end
|
53
|
+
|
54
|
+
it "outputs an error when there is an invalid version" do
|
55
|
+
v = MIME::Types::Data::VERSION
|
56
|
+
MIME::Types::Data.send(:remove_const, :VERSION)
|
57
|
+
MIME::Types::Data.const_set(:VERSION, "0.0")
|
58
|
+
MIME::Types::Cache.save
|
59
|
+
MIME::Types::Data.send(:remove_const, :VERSION)
|
60
|
+
MIME::Types::Data.const_set(:VERSION, v)
|
61
|
+
MIME::Types.instance_variable_set(:@__types__, nil)
|
62
|
+
assert_output "", /MIME::Types cache: invalid version/ do
|
63
|
+
MIME::Types["text/html"]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it "outputs an error when there is a marshal file incompatibility" do
|
68
|
+
MIME::Types::Cache.save
|
69
|
+
data = File.binread(@cache_file).reverse
|
70
|
+
File.binwrite(@cache_file, data)
|
71
|
+
MIME::Types.instance_variable_set(:@__types__, nil)
|
72
|
+
assert_output "", /incompatible marshal file format/ do
|
73
|
+
MIME::Types["text/html"]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ".save" do
|
79
|
+
it "does not create cache when RUBY_MIME_TYPES_CACHE is unset" do
|
80
|
+
ENV.delete("RUBY_MIME_TYPES_CACHE")
|
81
|
+
assert_nil MIME::Types::Cache.save
|
82
|
+
end
|
83
|
+
|
84
|
+
it "creates the cache " do
|
85
|
+
assert_equal(false, File.exist?(@cache_file))
|
86
|
+
MIME::Types::Cache.save
|
87
|
+
assert_equal(true, File.exist?(@cache_file))
|
88
|
+
end
|
89
|
+
|
90
|
+
it "uses the cache" do
|
91
|
+
MIME::Types["text/html"].first.add_extensions("hex")
|
92
|
+
MIME::Types::Cache.save
|
93
|
+
MIME::Types.instance_variable_set(:@__types__, nil)
|
94
|
+
|
95
|
+
assert_includes MIME::Types["text/html"].first.extensions, "hex"
|
96
|
+
|
97
|
+
reset_mime_types
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe MIME::Types::Container do
|
103
|
+
it "marshals and unmarshals correctly" do
|
104
|
+
container = MIME::Types::Container.new
|
105
|
+
container.add("xyz", "abc")
|
106
|
+
|
107
|
+
# default proc should return Set[]
|
108
|
+
assert_equal(Set[], container["abc"])
|
109
|
+
assert_equal(Set["abc"], container["xyz"])
|
110
|
+
|
111
|
+
marshalled = Marshal.dump(container)
|
112
|
+
loaded_container = Marshal.load(marshalled)
|
113
|
+
|
114
|
+
# default proc should still return Set[]
|
115
|
+
assert_equal(Set[], loaded_container["abc"])
|
116
|
+
assert_equal(Set["abc"], container["xyz"])
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|
+
types = MIME::Types[/gzip$/].select { |t|
|
46
|
+
%w[application/gzip application/x-gzip multipart/x-gzip].include?(t)
|
47
|
+
}
|
48
|
+
# This is this way because of a new type ending with gzip that only
|
49
|
+
# appears in some data files.
|
50
|
+
assert_equal %w[application/gzip application/x-gzip multipart/x-gzip], types
|
51
|
+
assert_equal 3, types.size
|
52
|
+
end
|
53
|
+
|
54
|
+
it "can be searched with a string" do
|
55
|
+
assert_includes MIME::Types["text/plain"], "text/plain"
|
56
|
+
assert_equal 1, MIME::Types["text/plain"].size
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can be searched with the complete flag" do
|
60
|
+
assert_empty MIME::Types[
|
61
|
+
"application/x-www-form-urlencoded",
|
62
|
+
complete: true
|
63
|
+
]
|
64
|
+
assert_includes MIME::Types["text/plain", complete: true], "text/plain"
|
65
|
+
assert_equal 1, MIME::Types["text/plain", complete: true].size
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can be searched with the registered flag" do
|
69
|
+
assert_empty MIME::Types["application/x-wordperfect6.1", registered: true]
|
70
|
+
refute_empty MIME::Types[
|
71
|
+
"application/x-www-form-urlencoded",
|
72
|
+
registered: true
|
73
|
+
]
|
74
|
+
refute_empty MIME::Types[/gzip/, registered: true]
|
75
|
+
refute_equal MIME::Types[/gzip/], MIME::Types[/gzip/, registered: true]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe ".type_for" do
|
80
|
+
it "finds all types for a given extension" do
|
81
|
+
assert_equal %w[application/gzip application/x-gzip],
|
82
|
+
MIME::Types.type_for("gz")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "separates the extension from filenames" do
|
86
|
+
assert_equal %w[image/jpeg], MIME::Types.of(["foo.jpeg", "bar.jpeg"])
|
87
|
+
end
|
88
|
+
|
89
|
+
it "finds multiple extensions" do
|
90
|
+
assert_equal %w[image/jpeg text/plain],
|
91
|
+
MIME::Types.type_for(%w[foo.txt foo.jpeg])
|
92
|
+
end
|
93
|
+
|
94
|
+
it "does not find unknown extensions" do
|
95
|
+
assert_empty MIME::Types.type_for("zzz")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "modifying type extensions causes reindexing" do
|
99
|
+
plain_text = MIME::Types["text/plain"].first
|
100
|
+
plain_text.add_extensions("xtxt")
|
101
|
+
assert_includes MIME::Types.type_for("xtxt"), "text/plain"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "handles newline characters correctly" do
|
105
|
+
assert_includes MIME::Types.type_for("test.pdf\n.txt"), "text/plain"
|
106
|
+
assert_includes MIME::Types.type_for("test.txt\n.pdf"), "application/pdf"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe ".count" do
|
111
|
+
it "can count the number of types inside" do
|
112
|
+
assert MIME::Types.count > 999
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe ".add" do
|
117
|
+
def setup
|
118
|
+
MIME::Types.instance_variable_set(:@__types__, nil)
|
119
|
+
MIME::Types.send(:load_default_mime_types)
|
120
|
+
end
|
121
|
+
|
122
|
+
let(:eruby) { MIME::Type.new("application/x-eruby") }
|
123
|
+
let(:jinja) { MIME::Type.new("application/jinja2") }
|
124
|
+
|
125
|
+
it "successfully adds a new type" do
|
126
|
+
MIME::Types.add(eruby)
|
127
|
+
assert_equal MIME::Types["application/x-eruby"], [eruby]
|
128
|
+
end
|
129
|
+
|
130
|
+
it "complains about adding a duplicate type" do
|
131
|
+
MIME::Types.add(eruby)
|
132
|
+
assert_output "", /is already registered as a variant/ do
|
133
|
+
MIME::Types.add(eruby)
|
134
|
+
end
|
135
|
+
assert_equal MIME::Types["application/x-eruby"], [eruby]
|
136
|
+
end
|
137
|
+
|
138
|
+
it "does not complain about adding a duplicate type when quiet" do
|
139
|
+
MIME::Types.add(eruby)
|
140
|
+
assert_silent do
|
141
|
+
MIME::Types.add(eruby, :silent)
|
142
|
+
end
|
143
|
+
assert_equal MIME::Types["application/x-eruby"], [eruby]
|
144
|
+
end
|
145
|
+
|
146
|
+
it "successfully adds from an array" do
|
147
|
+
MIME::Types.add([eruby, jinja])
|
148
|
+
assert_equal MIME::Types["application/x-eruby"], [eruby]
|
149
|
+
assert_equal MIME::Types["application/jinja2"], [jinja]
|
150
|
+
end
|
151
|
+
|
152
|
+
it "successfully adds from another MIME::Types" do
|
153
|
+
old_count = MIME::Types.count
|
154
|
+
|
155
|
+
mt = MIME::Types.new
|
156
|
+
mt.add(eruby)
|
157
|
+
|
158
|
+
MIME::Types.add(mt)
|
159
|
+
assert_equal old_count + 1, MIME::Types.count
|
160
|
+
|
161
|
+
assert_equal MIME::Types[eruby.content_type], [eruby]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
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_output "", /RUBY_MIME_TYPES_LAZY_LOAD/ do
|
24
|
+
assert_equal true, MIME::Types.send(:lazy_load?)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is nil when RUBY_MIME_TYPES_LAZY_LOAD is unset" do
|
29
|
+
ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = nil
|
30
|
+
assert_output "", "" do
|
31
|
+
assert_nil MIME::Types.send(:lazy_load?)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it "is false when RUBY_MIME_TYPES_LAZY_LOAD is false" do
|
36
|
+
ENV["RUBY_MIME_TYPES_LAZY_LOAD"] = "false"
|
37
|
+
assert_output "", /RUBY_MIME_TYPES_LAZY_LOAD/ do
|
38
|
+
assert_equal false, MIME::Types.send(:lazy_load?)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "loads lazily when RUBY_MIME_TYPES_LAZY_LOAD is set" do
|
44
|
+
MIME::Types.instance_variable_set(:@__types__, nil)
|
45
|
+
assert_nil MIME::Types.instance_variable_get(:@__types__)
|
46
|
+
refute_nil MIME::Types["text/html"].first
|
47
|
+
refute_nil MIME::Types.instance_variable_get(:@__types__)
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
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
|