mime-types 3.3.1 → 3.4.1

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