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