mime-types 3.2.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,311 +1,307 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # -*- ruby encoding: utf-8 -*-
4
-
5
- require 'mime/types'
6
- require 'minitest_helper'
3
+ require "mime/types"
4
+ require "minitest_helper"
7
5
 
8
6
  describe MIME::Type do
9
- # it { fail }
10
-
11
7
  def mime_type(content_type)
12
8
  MIME::Type.new(content_type) { |mt| yield mt if block_given? }
13
9
  end
14
10
 
15
11
  let(:x_appl_x_zip) {
16
- mime_type('x-appl/x-zip') { |t| t.extensions = %w(zip zp) }
12
+ mime_type("x-appl/x-zip") { |t| t.extensions = %w[zip zp] }
17
13
  }
18
- let(:text_plain) { mime_type('text/plain') }
19
- let(:text_html) { mime_type('text/html') }
20
- let(:image_jpeg) { mime_type('image/jpeg') }
14
+ let(:text_plain) { mime_type("text/plain") }
15
+ let(:text_html) { mime_type("text/html") }
16
+ let(:image_jpeg) { mime_type("image/jpeg") }
21
17
  let(:application_javascript) {
22
- mime_type('application/javascript') do |js|
23
- js.friendly('en' => 'JavaScript')
18
+ mime_type("application/javascript") do |js|
19
+ js.friendly("en" => "JavaScript")
24
20
  js.xrefs = {
25
- 'rfc' => %w(rfc4239 rfc4239),
26
- 'template' => %w(application/javascript)
21
+ "rfc" => %w[rfc4239 rfc4239],
22
+ "template" => %w[application/javascript]
27
23
  }
28
- js.encoding = '8bit'
29
- js.extensions = %w(js sj)
24
+ js.encoding = "8bit"
25
+ js.extensions = %w[js sj]
30
26
  js.registered = true
31
27
  end
32
28
  }
33
29
  let(:text_x_yaml) {
34
- mime_type('text/x-yaml') do |yaml|
35
- yaml.extensions = %w(yaml yml)
36
- yaml.encoding = '8bit'
37
- yaml.friendly('en' => 'YAML Structured Document')
30
+ mime_type("text/x-yaml") do |yaml|
31
+ yaml.extensions = %w[yaml yml]
32
+ yaml.encoding = "8bit"
33
+ yaml.friendly("en" => "YAML Structured Document")
38
34
  end
39
35
  }
40
36
  let(:text_x_yaml_with_docs) {
41
37
  text_x_yaml.dup.tap do |yaml|
42
- yaml.docs = 'Test YAML'
38
+ yaml.docs = "Test YAML"
43
39
  end
44
40
  }
45
41
 
46
- describe '.simplified' do
47
- it 'leaves normal types alone' do
48
- assert_equal 'text/plain', MIME::Type.simplified('text/plain')
42
+ describe ".simplified" do
43
+ it "leaves normal types alone" do
44
+ assert_equal "text/plain", MIME::Type.simplified("text/plain")
49
45
  end
50
46
 
51
- it 'does not remove x- prefixes by default' do
52
- assert_equal 'application/x-msword',
53
- MIME::Type.simplified('application/x-msword')
54
- assert_equal 'x-xyz/abc', MIME::Type.simplified('x-xyz/abc')
47
+ it "does not remove x- prefixes by default" do
48
+ assert_equal "application/x-msword",
49
+ MIME::Type.simplified("application/x-msword")
50
+ assert_equal "x-xyz/abc", MIME::Type.simplified("x-xyz/abc")
55
51
  end
56
52
 
57
- it 'removes x- prefixes when requested' do
58
- assert_equal 'application/msword',
59
- MIME::Type.simplified('application/x-msword', remove_x_prefix: true)
60
- assert_equal 'xyz/abc',
61
- MIME::Type.simplified('x-xyz/abc', remove_x_prefix: true)
53
+ it "removes x- prefixes when requested" do
54
+ assert_equal "application/msword",
55
+ MIME::Type.simplified("application/x-msword", remove_x_prefix: true)
56
+ assert_equal "xyz/abc",
57
+ MIME::Type.simplified("x-xyz/abc", remove_x_prefix: true)
62
58
  end
63
59
 
64
- it 'lowercases mixed-case types' do
65
- assert_equal 'text/vcard', MIME::Type.simplified('text/vCard')
60
+ it "lowercases mixed-case types" do
61
+ assert_equal "text/vcard", MIME::Type.simplified("text/vCard")
66
62
  end
67
63
 
68
- it 'returns nil when the value provided is not a valid content type' do
69
- assert_nil MIME::Type.simplified('text')
64
+ it "returns nil when the value provided is not a valid content type" do
65
+ assert_nil MIME::Type.simplified("text")
70
66
  end
71
67
  end
72
68
 
73
- describe '.i18n_key' do
74
- it 'converts text/plain to text.plain' do
75
- assert_equal 'text.plain', MIME::Type.i18n_key('text/plain')
69
+ describe ".i18n_key" do
70
+ it "converts text/plain to text.plain" do
71
+ assert_equal "text.plain", MIME::Type.i18n_key("text/plain")
76
72
  end
77
73
 
78
- it 'does not remove x-prefixes' do
79
- assert_equal 'application.x-msword',
80
- MIME::Type.i18n_key('application/x-msword')
74
+ it "does not remove x-prefixes" do
75
+ assert_equal "application.x-msword",
76
+ MIME::Type.i18n_key("application/x-msword")
81
77
  end
82
78
 
83
- it 'converts text/vCard to text.vcard' do
84
- assert_equal 'text.vcard', MIME::Type.i18n_key('text/vCard')
79
+ it "converts text/vCard to text.vcard" do
80
+ assert_equal "text.vcard", MIME::Type.i18n_key("text/vCard")
85
81
  end
86
82
 
87
- it 'returns nil when the value provided is not a valid content type' do
88
- assert_nil MIME::Type.i18n_key('text')
83
+ it "returns nil when the value provided is not a valid content type" do
84
+ assert_nil MIME::Type.i18n_key("text")
89
85
  end
90
86
  end
91
87
 
92
- describe '.new' do
93
- it 'fails if an invalid content type is provided' do
88
+ describe ".new" do
89
+ it "fails if an invalid content type is provided" do
94
90
  exception = assert_raises MIME::Type::InvalidContentType do
95
- MIME::Type.new('apps')
91
+ MIME::Type.new("apps")
96
92
  end
97
93
  assert_equal 'Invalid Content-Type "apps"', exception.to_s
98
94
  end
99
95
 
100
- it 'creates a valid content type just from a string' do
101
- type = MIME::Type.new('text/x-yaml')
96
+ it "creates a valid content type just from a string" do
97
+ type = MIME::Type.new("text/x-yaml")
102
98
 
103
99
  assert_instance_of MIME::Type, type
104
- assert_equal 'text/x-yaml', type.content_type
100
+ assert_equal "text/x-yaml", type.content_type
105
101
  end
106
102
 
107
- it 'yields the content type in a block' do
108
- MIME::Type.new('text/x-yaml') do |type|
103
+ it "yields the content type in a block" do
104
+ MIME::Type.new("text/x-yaml") do |type|
109
105
  assert_instance_of MIME::Type, type
110
- assert_equal 'text/x-yaml', type.content_type
106
+ assert_equal "text/x-yaml", type.content_type
111
107
  end
112
108
  end
113
109
 
114
- it 'creates a valid content type from a hash' do
110
+ it "creates a valid content type from a hash" do
115
111
  type = MIME::Type.new(
116
- 'content-type' => 'text/x-yaml',
117
- 'obsolete' => true
112
+ "content-type" => "text/x-yaml",
113
+ "obsolete" => true
118
114
  )
119
115
  assert_instance_of MIME::Type, type
120
- assert_equal 'text/x-yaml', type.content_type
116
+ assert_equal "text/x-yaml", type.content_type
121
117
  assert type.obsolete?
122
118
  end
123
119
 
124
- it 'creates a valid content type from an array' do
125
- type = MIME::Type.new(%w(text/x-yaml yaml yml yz))
120
+ it "creates a valid content type from an array" do
121
+ type = MIME::Type.new(%w[text/x-yaml yaml yml yz])
126
122
  assert_instance_of MIME::Type, type
127
- assert_equal 'text/x-yaml', type.content_type
128
- assert_equal %w(yaml yml yz), type.extensions
123
+ assert_equal "text/x-yaml", type.content_type
124
+ assert_equal %w[yaml yml yz], type.extensions
129
125
  end
130
126
  end
131
127
 
132
- describe '#like?' do
133
- it 'compares two MIME::Types on #simplified values without x- prefixes' do
128
+ describe "#like?" do
129
+ it "compares two MIME::Types on #simplified values without x- prefixes" do
134
130
  assert text_plain.like?(text_plain)
135
131
  refute text_plain.like?(text_html)
136
132
  end
137
133
 
138
- it 'compares MIME::Type against string without x- prefixes' do
134
+ it "compares MIME::Type against string without x- prefixes" do
139
135
  assert text_plain.like?(text_plain.to_s)
140
136
  refute text_plain.like?(text_html.to_s)
141
137
  end
142
138
  end
143
139
 
144
- describe '#<=>' do
145
- it 'correctly compares identical types' do
140
+ describe "#<=>" do
141
+ it "correctly compares identical types" do
146
142
  assert_equal text_plain, text_plain
147
143
  end
148
144
 
149
- it 'correctly compares equivalent types' do
150
- right = mime_type('text/Plain')
145
+ it "correctly compares equivalent types" do
146
+ right = mime_type("text/Plain")
151
147
  refute_same text_plain, right
152
148
  assert_equal text_plain, right
153
149
  end
154
150
 
155
- it 'correctly compares types that sort earlier' do
151
+ it "correctly compares types that sort earlier" do
156
152
  refute_equal text_html, text_plain
157
153
  assert_operator text_html, :<, text_plain
158
154
  end
159
155
 
160
- it 'correctly compares types that sort later' do
156
+ it "correctly compares types that sort later" do
161
157
  refute_equal text_plain, text_html
162
158
  assert_operator text_plain, :>, text_html
163
159
  end
164
160
 
165
- it 'correctly compares types against equivalent strings' do
166
- assert_equal text_plain, 'text/plain'
161
+ it "correctly compares types against equivalent strings" do
162
+ assert_equal text_plain, "text/plain"
167
163
  end
168
164
 
169
- it 'correctly compares types against strings that sort earlier' do
170
- refute_equal text_html, 'text/plain'
171
- assert_operator text_html, :<, 'text/plain'
165
+ it "correctly compares types against strings that sort earlier" do
166
+ refute_equal text_html, "text/plain"
167
+ assert_operator text_html, :<, "text/plain"
172
168
  end
173
169
 
174
- it 'correctly compares types against strings that sort later' do
175
- refute_equal text_plain, 'text/html'
176
- assert_operator text_plain, :>, 'text/html'
170
+ it "correctly compares types against strings that sort later" do
171
+ refute_equal text_plain, "text/html"
172
+ assert_operator text_plain, :>, "text/html"
177
173
  end
178
174
 
179
- it 'correctly compares against nil' do
175
+ it "correctly compares against nil" do
180
176
  refute_equal text_html, nil
181
177
  assert_operator text_plain, :<, nil
182
178
  end
183
179
  end
184
180
 
185
- describe '#ascii?' do
186
- it 'defaults to true for text/* types' do
181
+ describe "#ascii?" do
182
+ it "defaults to true for text/* types" do
187
183
  assert text_plain.ascii?
188
184
  end
189
185
 
190
- it 'defaults to false for non-text/* types' do
186
+ it "defaults to false for non-text/* types" do
191
187
  refute image_jpeg.ascii?
192
188
  end
193
189
  end
194
190
 
195
- describe '#binary?' do
196
- it 'defaults to false for text/* types' do
191
+ describe "#binary?" do
192
+ it "defaults to false for text/* types" do
197
193
  refute text_plain.binary?
198
194
  end
199
195
 
200
- it 'defaults to true for non-text/* types' do
196
+ it "defaults to true for non-text/* types" do
201
197
  assert image_jpeg.binary?
202
198
  end
203
199
  end
204
200
 
205
- describe '#complete?' do
206
- it 'is true when there are extensions' do
201
+ describe "#complete?" do
202
+ it "is true when there are extensions" do
207
203
  assert text_x_yaml.complete?
208
204
  end
209
205
 
210
- it 'is false when there are no extensions' do
211
- refute mime_type('text/plain').complete?
206
+ it "is false when there are no extensions" do
207
+ refute mime_type("text/plain").complete?
212
208
  end
213
209
  end
214
210
 
215
- describe '#content_type' do
216
- it 'preserves the original case' do
217
- assert_equal 'text/plain', text_plain.content_type
218
- assert_equal 'text/vCard', mime_type('text/vCard').content_type
211
+ describe "#content_type" do
212
+ it "preserves the original case" do
213
+ assert_equal "text/plain", text_plain.content_type
214
+ assert_equal "text/vCard", mime_type("text/vCard").content_type
219
215
  end
220
216
 
221
- it 'does not remove x- prefixes' do
222
- assert_equal 'x-appl/x-zip', x_appl_x_zip.content_type
217
+ it "does not remove x- prefixes" do
218
+ assert_equal "x-appl/x-zip", x_appl_x_zip.content_type
223
219
  end
224
220
  end
225
221
 
226
- describe '#default_encoding' do
227
- it 'is quoted-printable for text/* types' do
228
- assert_equal 'quoted-printable', text_plain.default_encoding
222
+ describe "#default_encoding" do
223
+ it "is quoted-printable for text/* types" do
224
+ assert_equal "quoted-printable", text_plain.default_encoding
229
225
  end
230
226
 
231
- it 'is base64 for non-text/* types' do
232
- assert_equal 'base64', image_jpeg.default_encoding
227
+ it "is base64 for non-text/* types" do
228
+ assert_equal "base64", image_jpeg.default_encoding
233
229
  end
234
230
  end
235
231
 
236
- describe '#encoding, #encoding=' do
237
- it 'returns #default_encoding if not set explicitly' do
238
- assert_equal 'quoted-printable', text_plain.encoding
239
- assert_equal 'base64', image_jpeg.encoding
232
+ describe "#encoding, #encoding=" do
233
+ it "returns #default_encoding if not set explicitly" do
234
+ assert_equal "quoted-printable", text_plain.encoding
235
+ assert_equal "base64", image_jpeg.encoding
240
236
  end
241
237
 
242
- it 'returns the set value when set' do
243
- text_plain.encoding = '8bit'
244
- assert_equal '8bit', text_plain.encoding
238
+ it "returns the set value when set" do
239
+ text_plain.encoding = "8bit"
240
+ assert_equal "8bit", text_plain.encoding
245
241
  end
246
242
 
247
- it 'resets to the default encoding when set to nil or :default' do
248
- text_plain.encoding = '8bit'
243
+ it "resets to the default encoding when set to nil or :default" do
244
+ text_plain.encoding = "8bit"
249
245
  text_plain.encoding = nil
250
246
  assert_equal text_plain.default_encoding, text_plain.encoding
251
247
  text_plain.encoding = :default
252
248
  assert_equal text_plain.default_encoding, text_plain.encoding
253
249
  end
254
250
 
255
- it 'raises a MIME::Type::InvalidEncoding for an invalid encoding' do
251
+ it "raises a MIME::Type::InvalidEncoding for an invalid encoding" do
256
252
  exception = assert_raises MIME::Type::InvalidEncoding do
257
- text_plain.encoding = 'binary'
253
+ text_plain.encoding = "binary"
258
254
  end
259
255
  assert_equal 'Invalid Encoding "binary"', exception.to_s
260
256
  end
261
257
  end
262
258
 
263
- describe '#eql?' do
264
- it 'is not true for a non-MIME::Type' do
265
- refute text_plain.eql?('text/plain')
259
+ describe "#eql?" do
260
+ it "is not true for a non-MIME::Type" do
261
+ refute text_plain.eql?("text/plain")
266
262
  end
267
263
 
268
- it 'is not true for a different MIME::Type' do
264
+ it "is not true for a different MIME::Type" do
269
265
  refute text_plain.eql?(image_jpeg)
270
266
  end
271
267
 
272
- it 'is true for an equivalent MIME::Type' do
273
- assert text_plain, mime_type('text/Plain')
268
+ it "is true for an equivalent MIME::Type" do
269
+ assert text_plain, mime_type("text/Plain")
274
270
  end
275
271
  end
276
272
 
277
- describe '#extensions, #extensions=' do
278
- it 'returns an array of extensions' do
279
- assert_equal %w(yaml yml), text_x_yaml.extensions
280
- assert_equal %w(zip zp), x_appl_x_zip.extensions
273
+ describe "#extensions, #extensions=" do
274
+ it "returns an array of extensions" do
275
+ assert_equal %w[yaml yml], text_x_yaml.extensions
276
+ assert_equal %w[zip zp], x_appl_x_zip.extensions
281
277
  end
282
278
 
283
- it 'sets a single extension when provided a single value' do
284
- text_x_yaml.extensions = 'yaml'
285
- assert_equal %w(yaml), text_x_yaml.extensions
279
+ it "sets a single extension when provided a single value" do
280
+ text_x_yaml.extensions = "yaml"
281
+ assert_equal %w[yaml], text_x_yaml.extensions
286
282
  end
287
283
 
288
- it 'deduplicates extensions' do
289
- text_x_yaml.extensions = %w(yaml yaml)
290
- assert_equal %w(yaml), text_x_yaml.extensions
284
+ it "deduplicates extensions" do
285
+ text_x_yaml.extensions = %w[yaml yaml]
286
+ assert_equal %w[yaml], text_x_yaml.extensions
291
287
  end
292
288
  end
293
289
 
294
- describe '#add_extensions' do
295
- it 'does not modify extensions when provided nil' do
290
+ describe "#add_extensions" do
291
+ it "does not modify extensions when provided nil" do
296
292
  text_x_yaml.add_extensions(nil)
297
- assert_equal %w(yaml yml), text_x_yaml.extensions
293
+ assert_equal %w[yaml yml], text_x_yaml.extensions
298
294
  end
299
295
 
300
- it 'remains deduplicated with duplicate values' do
301
- text_x_yaml.add_extensions('yaml')
302
- assert_equal %w(yaml yml), text_x_yaml.extensions
303
- text_x_yaml.add_extensions(%w(yaml yz))
304
- assert_equal %w(yaml yml yz), text_x_yaml.extensions
296
+ it "remains deduplicated with duplicate values" do
297
+ text_x_yaml.add_extensions("yaml")
298
+ assert_equal %w[yaml yml], text_x_yaml.extensions
299
+ text_x_yaml.add_extensions(%w[yaml yz])
300
+ assert_equal %w[yaml yml yz], text_x_yaml.extensions
305
301
  end
306
302
  end
307
303
 
308
- describe '#priority_compare' do
304
+ describe "#priority_compare" do
309
305
  def assert_priority_less(left, right)
310
306
  assert_equal(-1, left.priority_compare(right))
311
307
  end
@@ -324,15 +320,15 @@ describe MIME::Type do
324
320
  assert_priority_more right, left
325
321
  end
326
322
 
327
- let(:text_1) { mime_type('text/1') }
328
- let(:text_1p) { mime_type('text/1') }
329
- let(:text_2) { mime_type('text/2') }
323
+ let(:text_1) { mime_type("text/1") }
324
+ let(:text_1p) { mime_type("text/1") }
325
+ let(:text_2) { mime_type("text/2") }
330
326
 
331
- it 'sorts (1) based on the simplified type' do
327
+ it "sorts (1) based on the simplified type" do
332
328
  assert_priority text_1, text_1p, text_2
333
329
  end
334
330
 
335
- it 'sorts (2) based on extensions' do
331
+ it "sorts (2) based on extensions" do
336
332
  text_1.extensions = ["foo", "bar"]
337
333
  text_2.extensions = ["foo"]
338
334
 
@@ -343,271 +339,282 @@ describe MIME::Type do
343
339
  assert_priority_more text_1, text_2
344
340
  end
345
341
 
346
- it 'sorts (3) based on the registration state' do
342
+ it "sorts (3) based on the registration state" do
347
343
  text_1.registered = text_1p.registered = true
348
344
  text_1b = mime_type(text_1) { |t| t.registered = false }
349
345
 
350
346
  assert_priority text_1, text_1p, text_1b
351
347
  end
352
348
 
353
- it 'sorts (4) based on the completeness' do
354
- text_1.extensions = text_1p.extensions = '1'
349
+ it "sorts (4) based on the completeness" do
350
+ text_1.extensions = text_1p.extensions = "1"
355
351
  text_1b = mime_type(text_1) { |t| t.extensions = nil }
356
352
 
357
353
  assert_priority text_1, text_1p, text_1b
358
354
  end
359
355
 
360
- it 'sorts (5) based on obsolete status' do
356
+ it "sorts (5) based on obsolete status" do
361
357
  text_1.obsolete = text_1p.obsolete = false
362
358
  text_1b = mime_type(text_1) { |t| t.obsolete = true }
363
359
 
364
360
  assert_priority text_1, text_1p, text_1b
365
361
  end
366
362
 
367
- it 'sorts (5) based on the use-instead value' do
363
+ it "sorts (5) based on the use-instead value" do
368
364
  text_1.obsolete = text_1p.obsolete = true
369
- text_1.use_instead = text_1p.use_instead = 'abc/xyz'
365
+ text_1.use_instead = text_1p.use_instead = "abc/xyz"
370
366
  text_1b = mime_type(text_1) { |t| t.use_instead = nil }
371
367
 
372
368
  assert_priority text_1, text_1p, text_1b
373
369
 
374
- text_1b.use_instead = 'abc/zzz'
370
+ text_1b.use_instead = "abc/zzz"
375
371
 
376
372
  assert_priority text_1, text_1p, text_1b
377
373
  end
378
374
  end
379
375
 
380
- describe '#raw_media_type' do
381
- it 'extracts the media type as case-preserved' do
382
- assert_equal 'Text', mime_type('Text/plain').raw_media_type
376
+ describe "#raw_media_type" do
377
+ it "extracts the media type as case-preserved" do
378
+ assert_equal "Text", mime_type("Text/plain").raw_media_type
383
379
  end
384
380
 
385
- it 'does not remove x- prefixes' do
386
- assert_equal('x-appl', x_appl_x_zip.raw_media_type)
381
+ it "does not remove x- prefixes" do
382
+ assert_equal("x-appl", x_appl_x_zip.raw_media_type)
387
383
  end
388
384
  end
389
385
 
390
- describe '#media_type' do
391
- it 'extracts the media type as lowercase' do
392
- assert_equal 'text', text_plain.media_type
386
+ describe "#media_type" do
387
+ it "extracts the media type as lowercase" do
388
+ assert_equal "text", text_plain.media_type
393
389
  end
394
390
 
395
- it 'does not remove x- prefixes' do
396
- assert_equal('x-appl', x_appl_x_zip.media_type)
391
+ it "does not remove x- prefixes" do
392
+ assert_equal("x-appl", x_appl_x_zip.media_type)
397
393
  end
398
394
  end
399
395
 
400
- describe '#raw_media_type' do
401
- it 'extracts the media type as case-preserved' do
402
- assert_equal 'Text', mime_type('Text/plain').raw_media_type
396
+ describe "#raw_media_type" do
397
+ it "extracts the media type as case-preserved" do
398
+ assert_equal "Text", mime_type("Text/plain").raw_media_type
403
399
  end
404
400
 
405
- it 'does not remove x- prefixes' do
406
- assert_equal('x-appl', x_appl_x_zip.raw_media_type)
401
+ it "does not remove x- prefixes" do
402
+ assert_equal("x-appl", x_appl_x_zip.raw_media_type)
407
403
  end
408
404
  end
409
405
 
410
- describe '#sub_type' do
411
- it 'extracts the sub type as lowercase' do
412
- assert_equal 'plain', text_plain.sub_type
406
+ describe "#sub_type" do
407
+ it "extracts the sub type as lowercase" do
408
+ assert_equal "plain", text_plain.sub_type
413
409
  end
414
410
 
415
- it 'does not remove x- prefixes' do
416
- assert_equal('x-zip', x_appl_x_zip.sub_type)
411
+ it "does not remove x- prefixes" do
412
+ assert_equal("x-zip", x_appl_x_zip.sub_type)
417
413
  end
418
414
  end
419
415
 
420
- describe '#raw_sub_type' do
421
- it 'extracts the sub type as case-preserved' do
422
- assert_equal 'Plain', mime_type('text/Plain').raw_sub_type
416
+ describe "#raw_sub_type" do
417
+ it "extracts the sub type as case-preserved" do
418
+ assert_equal "Plain", mime_type("text/Plain").raw_sub_type
423
419
  end
424
420
 
425
- it 'does not remove x- prefixes' do
426
- assert_equal('x-zip', x_appl_x_zip.raw_sub_type)
421
+ it "does not remove x- prefixes" do
422
+ assert_equal("x-zip", x_appl_x_zip.raw_sub_type)
427
423
  end
428
424
  end
429
425
 
430
- describe '#to_h' do
431
- let(:t) { mime_type('a/b') }
426
+ describe "#to_h" do
427
+ let(:t) { mime_type("a/b") }
432
428
 
433
- it 'has the required keys (content-type, registered, encoding)' do
434
- assert_has_keys t.to_h, %w(content-type registered encoding)
429
+ it "has the required keys (content-type, registered, encoding)" do
430
+ assert_has_keys t.to_h, %w[content-type registered encoding]
435
431
  end
436
432
 
437
- it 'has the docs key if there are documents' do
438
- assert_has_keys mime_type(t) { |v| v.docs = 'a' }.to_h, %w(docs)
433
+ it "has the docs key if there are documents" do
434
+ assert_has_keys mime_type(t) { |v| v.docs = "a" }.to_h, %w[docs]
439
435
  end
440
436
 
441
- it 'has the extensions key if set' do
442
- assert_has_keys mime_type(t) { |v| v.extensions = 'a' }.to_h,
443
- 'extensions'
437
+ it "has the extensions key if set" do
438
+ assert_has_keys mime_type(t) { |v| v.extensions = "a" }.to_h,
439
+ "extensions"
444
440
  end
445
441
 
446
- it 'has the preferred-extension key if set' do
447
- assert_has_keys mime_type(t) { |v| v.preferred_extension = 'a' }.to_h,
448
- 'preferred-extension'
442
+ it "has the preferred-extension key if set" do
443
+ assert_has_keys mime_type(t) { |v| v.preferred_extension = "a" }.to_h,
444
+ "preferred-extension"
449
445
  end
450
446
 
451
- it 'has the obsolete key if set' do
452
- assert_has_keys mime_type(t) { |v| v.obsolete = true }.to_h, 'obsolete'
447
+ it "has the obsolete key if set" do
448
+ assert_has_keys mime_type(t) { |v| v.obsolete = true }.to_h, "obsolete"
453
449
  end
454
450
 
455
- it 'has the obsolete and use-instead keys if set' do
451
+ it "has the obsolete and use-instead keys if set" do
456
452
  assert_has_keys mime_type(t) { |v|
457
453
  v.obsolete = true
458
- v.use_instead = 'c/d'
459
- }.to_h, %w(obsolete use-instead)
454
+ v.use_instead = "c/d"
455
+ }.to_h, %w[obsolete use-instead]
460
456
  end
461
457
 
462
- it 'has the signature key if set' do
463
- assert_has_keys mime_type(t) { |v| v.signature = true }.to_h, 'signature'
458
+ it "has the signature key if set" do
459
+ assert_has_keys mime_type(t) { |v| v.signature = true }.to_h, "signature"
464
460
  end
465
461
  end
466
462
 
467
- describe '#to_json' do
468
- let(:expected) {
463
+ describe "#to_json" do
464
+ let(:expected_1) {
469
465
  '{"content-type":"a/b","encoding":"base64","registered":false}'
470
466
  }
467
+ let(:expected_2) {
468
+ '{"content-type":"a/b","encoding":"base64","registered":true,"provisional":true}'
469
+ }
471
470
 
472
- it 'converts to JSON when requested' do
473
- assert_equal expected, mime_type('a/b').to_json
471
+ it "converts to JSON when requested" do
472
+ assert_equal expected_1, mime_type("a/b").to_json
473
+ end
474
+
475
+ it "converts to JSON with provisional when requested" do
476
+ type = mime_type("a/b") do |t|
477
+ t.registered = true
478
+ t.provisional = true
479
+ end
480
+ assert_equal expected_2, type.to_json
474
481
  end
475
482
  end
476
483
 
477
- describe '#to_s, #to_str' do
478
- it 'represents itself as a string of the canonical content_type' do
479
- assert_equal 'text/plain', "#{text_plain}"
484
+ describe "#to_s, #to_str" do
485
+ it "represents itself as a string of the canonical content_type" do
486
+ assert_equal "text/plain", text_plain.to_s
480
487
  end
481
488
 
482
- it 'acts like a string of the canonical content_type for comparison' do
483
- assert_equal text_plain, 'text/plain'
489
+ it "acts like a string of the canonical content_type for comparison" do
490
+ assert_equal text_plain, "text/plain"
484
491
  end
485
492
 
486
- it 'acts like a string for other purposes' do
487
- assert_equal 'stringy', 'text/plain'.sub(text_plain, 'stringy')
493
+ it "acts like a string for other purposes" do
494
+ assert_equal "stringy", "text/plain".sub(text_plain, "stringy")
488
495
  end
489
496
  end
490
497
 
491
- describe '#xrefs, #xrefs=' do
498
+ describe "#xrefs, #xrefs=" do
492
499
  let(:expected) {
493
- MIME::Types::Container.new({ 'rfc' => Set[*%w(rfc1234 rfc5678)] })
500
+ MIME::Types::Container.new("rfc" => Set["rfc1234", "rfc5678"])
494
501
  }
495
502
 
496
- it 'returns the expected results' do
503
+ it "returns the expected results" do
497
504
  application_javascript.xrefs = {
498
- 'rfc' => %w(rfc5678 rfc1234 rfc1234)
505
+ "rfc" => %w[rfc5678 rfc1234 rfc1234]
499
506
  }
500
507
 
501
508
  assert_equal expected, application_javascript.xrefs
502
509
  end
503
510
  end
504
511
 
505
- describe '#xref_urls' do
512
+ describe "#xref_urls" do
506
513
  let(:expected) {
507
514
  [
508
- 'http://www.iana.org/go/draft1',
509
- 'http://www.iana.org/assignments/media-types/a/b',
510
- 'http://www.iana.org/assignments/media-types/media-types.xhtml#p-1',
511
- 'http://www.iana.org/go/rfc-1',
512
- 'http://www.rfc-editor.org/errata_search.php?eid=err-1',
513
- 'http://example.org',
514
- 'text'
515
+ "http://www.iana.org/go/draft1",
516
+ "http://www.iana.org/assignments/media-types/a/b",
517
+ "http://www.iana.org/assignments/media-types/media-types.xhtml#p-1",
518
+ "http://www.iana.org/go/rfc-1",
519
+ "http://www.rfc-editor.org/errata_search.php?eid=err-1",
520
+ "http://example.org",
521
+ "text"
515
522
  ]
516
523
  }
517
524
 
518
525
  let(:type) {
519
- mime_type('a/b').tap do |t|
526
+ mime_type("a/b").tap do |t|
520
527
  t.xrefs = {
521
- 'draft' => [ 'RFC1' ],
522
- 'template' => [ 'a/b' ],
523
- 'person' => [ 'p-1' ],
524
- 'rfc' => [ 'rfc-1' ],
525
- 'rfc-errata' => [ 'err-1' ],
526
- 'uri' => [ 'http://example.org' ],
527
- 'text' => [ 'text' ]
528
+ "draft" => ["RFC1"],
529
+ "template" => ["a/b"],
530
+ "person" => ["p-1"],
531
+ "rfc" => ["rfc-1"],
532
+ "rfc-errata" => ["err-1"],
533
+ "uri" => ["http://example.org"],
534
+ "text" => ["text"]
528
535
  }
529
536
  end
530
537
  }
531
538
 
532
- it 'translates according to given rules' do
539
+ it "translates according to given rules" do
533
540
  assert_equal expected, type.xref_urls
534
541
  end
535
542
  end
536
543
 
537
- describe '#use_instead' do
538
- it 'is nil unless the type is obsolete' do
544
+ describe "#use_instead" do
545
+ it "is nil unless the type is obsolete" do
539
546
  assert_nil text_plain.use_instead
540
547
  end
541
548
 
542
- it 'is nil if not set and the type is obsolete' do
549
+ it "is nil if not set and the type is obsolete" do
543
550
  text_plain.obsolete = true
544
551
  assert_nil text_plain.use_instead
545
552
  end
546
553
 
547
- it 'is a different type if set and the type is obsolete' do
554
+ it "is a different type if set and the type is obsolete" do
548
555
  text_plain.obsolete = true
549
- text_plain.use_instead = 'text/html'
550
- assert_equal 'text/html', text_plain.use_instead
556
+ text_plain.use_instead = "text/html"
557
+ assert_equal "text/html", text_plain.use_instead
551
558
  end
552
559
  end
553
560
 
554
- describe '#preferred_extension, #preferred_extension=' do
555
- it 'is nil when not set and there are no extensions' do
561
+ describe "#preferred_extension, #preferred_extension=" do
562
+ it "is nil when not set and there are no extensions" do
556
563
  assert_nil text_plain.preferred_extension
557
564
  end
558
565
 
559
- it 'is the first extension when not set but there are extensions' do
560
- assert_equal 'yaml', text_x_yaml.preferred_extension
566
+ it "is the first extension when not set but there are extensions" do
567
+ assert_equal "yaml", text_x_yaml.preferred_extension
561
568
  end
562
569
 
563
- it 'is the extension provided when set' do
564
- text_x_yaml.preferred_extension = 'yml'
565
- assert_equal 'yml', text_x_yaml.preferred_extension
570
+ it "is the extension provided when set" do
571
+ text_x_yaml.preferred_extension = "yml"
572
+ assert_equal "yml", text_x_yaml.preferred_extension
566
573
  end
567
574
 
568
- it 'is adds the preferred extension if it does not exist' do
569
- text_x_yaml.preferred_extension = 'yz'
570
- assert_equal 'yz', text_x_yaml.preferred_extension
571
- assert_includes text_x_yaml.extensions, 'yz'
575
+ it "is adds the preferred extension if it does not exist" do
576
+ text_x_yaml.preferred_extension = "yz"
577
+ assert_equal "yz", text_x_yaml.preferred_extension
578
+ assert_includes text_x_yaml.extensions, "yz"
572
579
  end
573
580
  end
574
581
 
575
- describe '#friendly' do
576
- it 'returns English by default' do
577
- assert_equal 'YAML Structured Document', text_x_yaml.friendly
582
+ describe "#friendly" do
583
+ it "returns English by default" do
584
+ assert_equal "YAML Structured Document", text_x_yaml.friendly
578
585
  end
579
586
 
580
- it 'returns English when requested' do
581
- assert_equal 'YAML Structured Document', text_x_yaml.friendly('en')
582
- assert_equal 'YAML Structured Document', text_x_yaml.friendly(:en)
587
+ it "returns English when requested" do
588
+ assert_equal "YAML Structured Document", text_x_yaml.friendly("en")
589
+ assert_equal "YAML Structured Document", text_x_yaml.friendly(:en)
583
590
  end
584
591
 
585
- it 'returns nothing for an unknown language' do
586
- assert_nil text_x_yaml.friendly('zz')
592
+ it "returns nothing for an unknown language" do
593
+ assert_nil text_x_yaml.friendly("zz")
587
594
  end
588
595
 
589
- it 'merges new values from an array parameter' do
590
- expected = { 'en' => 'Text files' }
591
- assert_equal expected, text_plain.friendly([ 'en', 'Text files' ])
592
- expected.update('fr' => 'des fichiers texte')
596
+ it "merges new values from an array parameter" do
597
+ expected = {"en" => "Text files"}
598
+ assert_equal expected, text_plain.friendly(["en", "Text files"])
599
+ expected.update("fr" => "des fichiers texte")
593
600
  assert_equal expected,
594
- text_plain.friendly([ 'fr', 'des fichiers texte' ])
601
+ text_plain.friendly(["fr", "des fichiers texte"])
595
602
  end
596
603
 
597
- it 'merges new values from a hash parameter' do
598
- expected = { 'en' => 'Text files' }
604
+ it "merges new values from a hash parameter" do
605
+ expected = {"en" => "Text files"}
599
606
  assert_equal expected, text_plain.friendly(expected)
600
- french = { 'fr' => 'des fichiers texte' }
607
+ french = {"fr" => "des fichiers texte"}
601
608
  expected.update(french)
602
609
  assert_equal expected, text_plain.friendly(french)
603
610
  end
604
611
 
605
- it 'raises an ArgumentError if an unknown value is provided' do
612
+ it "raises an ArgumentError if an unknown value is provided" do
606
613
  exception = assert_raises ArgumentError do
607
614
  text_plain.friendly(1)
608
615
  end
609
616
 
610
- assert_equal 'Expected a language or translation set, not 1',
617
+ assert_equal "Expected a language or translation set, not 1",
611
618
  exception.message
612
619
  end
613
620
  end