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