assembly-objectfile 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,20 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Assembly::ObjectFile do
6
+ let(:root_path) { File.expand_path("#{File.dirname(__dir__)}/..") }
7
+ let(:fixture_input_dir) { File.join(root_path, 'spec', 'fixtures', 'input') }
8
+ let(:tif_fixture_file) { File.join(fixture_input_dir, 'test.tif') }
9
+ let(:jp2_fixture_file) { File.join(fixture_input_dir, 'test.jp2') }
10
+ let(:tiff_no_color_fixture_file) { File.join(fixture_input_dir, 'test_no_color_profile.tif') }
11
+ let(:resource1_tif_fixture_file) { File.join(fixture_input_dir, 'res1_image1.tif') }
12
+ let(:resource1_text_fixture_file) { File.join(fixture_input_dir, 'res1_textfile.txt') }
13
+ let(:resource1_pdf_fixture_file) { File.join(fixture_input_dir, 'res1_transcript.pdf') }
14
+ let(:no_exif_fixture_file) { File.join(fixture_input_dir, 'file_with_no_exif.xml') }
15
+ let(:json_fixture_file) { File.join(fixture_input_dir, 'test.json') }
16
+ let(:obj_fixture_file) { File.join(fixture_input_dir, 'someobject.obj') }
17
+ let(:ply_fixture_file) { File.join(fixture_input_dir, 'someobject.ply') }
18
+ let(:vtt_fixture_file) { File.join(fixture_input_dir, 'test.vtt') }
19
+
6
20
  describe '.common_path' do
7
21
  context 'when common path is 2 nodes out of 4' do
8
22
  it 'returns the common directory' do
@@ -33,7 +47,6 @@ describe Assembly::ObjectFile do
33
47
  expect(object_file.path).to eq('/some/file.txt')
34
48
  expect(object_file.label).to be_nil
35
49
  expect(object_file.file_attributes).to be_nil
36
- expect(object_file.provider_sha1).to be_nil
37
50
  expect(object_file.provider_md5).to be_nil
38
51
  expect(object_file.relative_path).to be_nil
39
52
  end
@@ -52,7 +65,6 @@ describe Assembly::ObjectFile do
52
65
  expect(object_file.path).to eq('/some/file.txt')
53
66
  expect(object_file.label).to eq('some label')
54
67
  expect(object_file.file_attributes).to eq('shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no')
55
- expect(object_file.provider_sha1).to be_nil
56
68
  expect(object_file.provider_md5).to be_nil
57
69
  expect(object_file.relative_path).to eq('/tmp')
58
70
  end
@@ -69,29 +81,29 @@ describe Assembly::ObjectFile do
69
81
 
70
82
  describe '#filename' do
71
83
  it 'returns File.basename' do
72
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
84
+ object_file = described_class.new(tif_fixture_file)
73
85
  expect(object_file.filename).to eq('test.tif')
74
- expect(object_file.filename).to eq(File.basename(TEST_TIF_INPUT_FILE))
86
+ expect(object_file.filename).to eq(File.basename(tif_fixture_file))
75
87
  end
76
88
  end
77
89
 
78
90
  describe '#ext' do
79
91
  it 'returns the file extension' do
80
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
92
+ object_file = described_class.new(tif_fixture_file)
81
93
  expect(object_file.ext).to eq('.tif')
82
94
  end
83
95
  end
84
96
 
85
97
  describe '#dirname' do
86
98
  it 'returns the File.dirname' do
87
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
88
- expect(object_file.dirname).to eq(File.dirname(TEST_TIF_INPUT_FILE))
99
+ object_file = described_class.new(tif_fixture_file)
100
+ expect(object_file.dirname).to eq(File.dirname(tif_fixture_file))
89
101
  end
90
102
  end
91
103
 
92
104
  describe '#filename_without_ext' do
93
105
  it 'returns filename before extension' do
94
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
106
+ object_file = described_class.new(tif_fixture_file)
95
107
  expect(object_file.filename_without_ext).to eq('test')
96
108
  end
97
109
  end
@@ -100,13 +112,13 @@ describe Assembly::ObjectFile do
100
112
  subject { object_file.image? }
101
113
 
102
114
  context 'with tiff' do
103
- let(:object_file) { described_class.new(TEST_TIF_INPUT_FILE) }
115
+ let(:object_file) { described_class.new(tif_fixture_file) }
104
116
 
105
117
  it { is_expected.to be true }
106
118
  end
107
119
 
108
120
  context 'with jp2' do
109
- let(:object_file) { described_class.new(TEST_JP2_INPUT_FILE) }
121
+ let(:object_file) { described_class.new(jp2_fixture_file) }
110
122
 
111
123
  it { is_expected.to be true }
112
124
  end
@@ -117,19 +129,19 @@ describe Assembly::ObjectFile do
117
129
  allow(object_file).to receive(:file_mimetype).and_return('image/x-tga')
118
130
  end
119
131
 
120
- let(:object_file) { described_class.new(TEST_JP2_INPUT_FILE) }
132
+ let(:object_file) { described_class.new(jp2_fixture_file) }
121
133
 
122
134
  it { is_expected.to be false }
123
135
  end
124
136
 
125
137
  context 'with ruby file' do
126
- let(:object_file) { described_class.new(File.join(PATH_TO_GEM, 'spec/assembly/object_file_spec.rb')) }
138
+ let(:object_file) { described_class.new(File.join(root_path, 'spec/assembly/object_file_spec.rb')) }
127
139
 
128
140
  it { is_expected.to be false }
129
141
  end
130
142
 
131
143
  context 'with xml' do
132
- let(:object_file) { described_class.new(File.join(PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')) }
144
+ let(:object_file) { described_class.new(File.join(fixture_input_dir, 'file_with_no_exif.xml')) }
133
145
 
134
146
  it { is_expected.to be false }
135
147
  end
@@ -138,21 +150,21 @@ describe Assembly::ObjectFile do
138
150
  describe '#object_type' do
139
151
  context 'with tiff' do
140
152
  it ':image' do
141
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
153
+ object_file = described_class.new(tif_fixture_file)
142
154
  expect(object_file.object_type).to eq(:image)
143
155
  end
144
156
  end
145
157
 
146
158
  context 'with jp2' do
147
159
  it ':image' do
148
- object_file = described_class.new(TEST_JP2_INPUT_FILE)
160
+ object_file = described_class.new(jp2_fixture_file)
149
161
  expect(object_file.object_type).to eq(:image)
150
162
  end
151
163
  end
152
164
 
153
165
  context 'with ruby file' do
154
166
  it ':text' do
155
- non_image_file = File.join(PATH_TO_GEM, 'spec/assembly/object_file_spec.rb')
167
+ non_image_file = File.join(root_path, 'spec/assembly/object_file_spec.rb')
156
168
  object_file = described_class.new(non_image_file)
157
169
  expect(object_file.object_type).to eq(:text)
158
170
  end
@@ -160,7 +172,7 @@ describe Assembly::ObjectFile do
160
172
 
161
173
  context 'with xml' do
162
174
  it ':application' do
163
- non_image_file = File.join(PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
175
+ non_image_file = File.join(fixture_input_dir, 'file_with_no_exif.xml')
164
176
  object_file = described_class.new(non_image_file)
165
177
  expect(object_file.object_type).to eq(:application)
166
178
  end
@@ -170,35 +182,35 @@ describe Assembly::ObjectFile do
170
182
  describe '#valid_image?' do
171
183
  context 'with tiff' do
172
184
  it 'true' do
173
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
185
+ object_file = described_class.new(tif_fixture_file)
174
186
  expect(object_file.valid_image?).to be(true)
175
187
  end
176
188
  end
177
189
 
178
190
  context 'with tiff resolution 1' do
179
191
  it 'true' do
180
- object_file = described_class.new(TEST_RES1_TIF1)
192
+ object_file = described_class.new(resource1_tif_fixture_file)
181
193
  expect(object_file.valid_image?).to be(true)
182
194
  end
183
195
  end
184
196
 
185
197
  context 'with tiff no color' do
186
198
  it 'true' do
187
- object_file = described_class.new(TEST_TIFF_NO_COLOR_FILE)
199
+ object_file = described_class.new(tiff_no_color_fixture_file)
188
200
  expect(object_file.valid_image?).to be(true)
189
201
  end
190
202
  end
191
203
 
192
204
  context 'with jp2' do
193
205
  it 'true' do
194
- object_file = described_class.new(TEST_JP2_INPUT_FILE)
206
+ object_file = described_class.new(jp2_fixture_file)
195
207
  expect(object_file.valid_image?).to be(true)
196
208
  end
197
209
  end
198
210
 
199
211
  context 'with ruby file' do
200
212
  it 'false' do
201
- non_image_file = File.join(PATH_TO_GEM, 'spec/assembly/object_file_spec.rb')
213
+ non_image_file = File.join(root_path, 'spec/assembly/object_file_spec.rb')
202
214
  object_file = described_class.new(non_image_file)
203
215
  expect(object_file.valid_image?).to be(false)
204
216
  end
@@ -206,7 +218,7 @@ describe Assembly::ObjectFile do
206
218
 
207
219
  context 'with xml' do
208
220
  it 'false' do
209
- non_image_file = File.join(PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
221
+ non_image_file = File.join(fixture_input_dir, 'file_with_no_exif.xml')
210
222
  object_file = described_class.new(non_image_file)
211
223
  expect(object_file.valid_image?).to be(false)
212
224
  end
@@ -217,14 +229,14 @@ describe Assembly::ObjectFile do
217
229
  # rubocop:disable RSpec/RepeatedExampleGroupBody
218
230
  context 'with .txt file' do
219
231
  it 'plain/text' do
220
- object_file = described_class.new(TEST_RES1_TEXT)
232
+ object_file = described_class.new(resource1_text_fixture_file)
221
233
  expect(object_file.mimetype).to eq('text/plain')
222
234
  end
223
235
  end
224
236
 
225
237
  context 'with .xml file' do
226
238
  it 'plain/text' do
227
- object_file = described_class.new(TEST_RES1_TEXT)
239
+ object_file = described_class.new(resource1_text_fixture_file)
228
240
  expect(object_file.mimetype).to eq('text/plain')
229
241
  end
230
242
  end
@@ -232,21 +244,21 @@ describe Assembly::ObjectFile do
232
244
 
233
245
  context 'with .tif file' do
234
246
  it 'image/tiff' do
235
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
247
+ object_file = described_class.new(tif_fixture_file)
236
248
  expect(object_file.mimetype).to eq('image/tiff')
237
249
  end
238
250
  end
239
251
 
240
252
  context 'with .jp2 file' do
241
253
  it 'image/jp2' do
242
- object_file = described_class.new(TEST_JP2_INPUT_FILE)
254
+ object_file = described_class.new(jp2_fixture_file)
243
255
  expect(object_file.mimetype).to eq('image/jp2')
244
256
  end
245
257
  end
246
258
 
247
259
  context 'with .pdf file' do
248
260
  it 'application/pdf' do
249
- object_file = described_class.new(TEST_RES1_PDF)
261
+ object_file = described_class.new(resource1_pdf_fixture_file)
250
262
  expect(object_file.mimetype).to eq('application/pdf')
251
263
  end
252
264
  end
@@ -254,21 +266,21 @@ describe Assembly::ObjectFile do
254
266
  context 'with .obj (3d) file' do
255
267
  context 'when default preference (unix file system command)' do
256
268
  it 'plain/text' do
257
- object_file = described_class.new(TEST_OBJ_FILE)
269
+ object_file = described_class.new(obj_fixture_file)
258
270
  expect(object_file.mimetype).to eq('text/plain')
259
271
  end
260
272
  end
261
273
 
262
274
  context 'when mimetype extension gem preferred over unix file system command' do
263
275
  it 'application/x-tgif' do
264
- object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[extension file exif])
276
+ object_file = described_class.new(obj_fixture_file, mime_type_order: %i[extension file exif])
265
277
  expect(object_file.mimetype).to eq('application/x-tgif')
266
278
  end
267
279
  end
268
280
 
269
281
  context 'when invalid first preference mimetype generation' do
270
282
  it 'ignores invalid mimetype generation method and respects valid method preference order' do
271
- object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[bogus extension file])
283
+ object_file = described_class.new(obj_fixture_file, mime_type_order: %i[bogus extension file])
272
284
  expect(object_file.mimetype).to eq('application/x-tgif')
273
285
  end
274
286
  end
@@ -276,14 +288,14 @@ describe Assembly::ObjectFile do
276
288
 
277
289
  context 'with .ply 3d file' do
278
290
  it 'text/plain' do
279
- object_file = described_class.new(TEST_PLY_FILE)
291
+ object_file = described_class.new(ply_fixture_file)
280
292
  expect(object_file.mimetype).to eq('text/plain')
281
293
  end
282
294
  end
283
295
 
284
296
  context 'when exif information is damaged' do
285
297
  it 'gives us the mimetype' do
286
- object_file = described_class.new(TEST_FILE_NO_EXIF)
298
+ object_file = described_class.new(no_exif_fixture_file)
287
299
  expect(object_file.filename).to eq('file_with_no_exif.xml')
288
300
  expect(object_file.ext).to eq('.xml')
289
301
  # we could get either of these mimetypes depending on the OS
@@ -293,25 +305,34 @@ describe Assembly::ObjectFile do
293
305
 
294
306
  context 'when .json file' do
295
307
  it 'uses the manual mapping to set the correct mimetype of application/json for a .json file' do
296
- object_file = described_class.new(TEST_JSON_FILE)
308
+ object_file = described_class.new(json_fixture_file)
297
309
  expect(object_file.send(:exif_mimetype)).to be_nil # exif
298
310
  expect(object_file.send(:file_mimetype)).to eq('text/plain') # unix file system command
299
311
  expect(object_file.mimetype).to eq('application/json') # our configured mapping overrides both
300
312
  end
301
313
  end
314
+
315
+ context 'when .vtt file' do
316
+ it 'uses the manual mapping to set the correct mimetype of text/vtt for a .vtt file' do
317
+ object_file = described_class.new(vtt_fixture_file)
318
+ expect(object_file.send(:exif_mimetype)).to be_nil # exif
319
+ expect(object_file.send(:file_mimetype)).to eq('text/plain') # unix file system command
320
+ expect(object_file.mimetype).to eq('text/vtt') # our configured mapping overrides both
321
+ end
322
+ end
302
323
  end
303
324
 
304
325
  describe '#file_mimetype (unix file system command)' do
305
326
  context 'when .json file' do
306
327
  it 'text/plain' do
307
- object_file = described_class.new(TEST_JSON_FILE)
328
+ object_file = described_class.new(json_fixture_file)
308
329
  expect(object_file.send(:file_mimetype)).to eq('text/plain')
309
330
  end
310
331
  end
311
332
 
312
333
  context 'when .tif file' do
313
334
  it 'image/tiff' do
314
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
335
+ object_file = described_class.new(tif_fixture_file)
315
336
  expect(object_file.send(:file_mimetype)).to eq('image/tiff')
316
337
  end
317
338
  end
@@ -320,21 +341,21 @@ describe Assembly::ObjectFile do
320
341
  describe '#jp2able?' do
321
342
  context 'with jp2 file' do
322
343
  it 'false' do
323
- object_file = described_class.new(TEST_JP2_INPUT_FILE)
344
+ object_file = described_class.new(jp2_fixture_file)
324
345
  expect(object_file.jp2able?).to be(false)
325
346
  end
326
347
  end
327
348
 
328
349
  context 'with tiff resolution 1 file' do
329
350
  it 'true' do
330
- object_file = described_class.new(TEST_RES1_TIF1)
351
+ object_file = described_class.new(resource1_tif_fixture_file)
331
352
  expect(object_file.jp2able?).to be(true)
332
353
  end
333
354
  end
334
355
 
335
356
  context 'with tiff no color file' do
336
357
  it 'true' do
337
- object_file = described_class.new(TEST_TIFF_NO_COLOR_FILE)
358
+ object_file = described_class.new(tiff_no_color_fixture_file)
338
359
  expect(object_file.jp2able?).to be(true)
339
360
  end
340
361
  end
@@ -342,7 +363,7 @@ describe Assembly::ObjectFile do
342
363
 
343
364
  describe '#md5' do
344
365
  it 'computes md5 for an image file' do
345
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
366
+ object_file = described_class.new(tif_fixture_file)
346
367
  expect(object_file.md5).to eq('a2400500acf21e43f5440d93be894101')
347
368
  end
348
369
 
@@ -354,7 +375,7 @@ describe Assembly::ObjectFile do
354
375
 
355
376
  describe '#sha1' do
356
377
  it 'computes sha1 for an image file' do
357
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
378
+ object_file = described_class.new(tif_fixture_file)
358
379
  expect(object_file.sha1).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
359
380
  end
360
381
 
@@ -366,7 +387,7 @@ describe Assembly::ObjectFile do
366
387
 
367
388
  describe '#file_exists?' do
368
389
  it 'false when a valid directory is specified instead of a file' do
369
- path = PATH_TO_GEM
390
+ path = root_path
370
391
  object_file = described_class.new(path)
371
392
  expect(File.exist?(path)).to be true
372
393
  expect(File.directory?(path)).to be true
@@ -374,7 +395,7 @@ describe Assembly::ObjectFile do
374
395
  end
375
396
 
376
397
  it 'false when a non-existent file is specified' do
377
- path = File.join(PATH_TO_GEM, 'file_not_there.txt')
398
+ path = File.join(root_path, 'file_not_there.txt')
378
399
  object_file = described_class.new(path)
379
400
  expect(File.exist?(path)).to be false
380
401
  expect(File.directory?(path)).to be false
@@ -384,7 +405,7 @@ describe Assembly::ObjectFile do
384
405
 
385
406
  describe '#filesize' do
386
407
  it 'tells us the size of an input file' do
387
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
408
+ object_file = described_class.new(tif_fixture_file)
388
409
  expect(object_file.filesize).to eq(63_542)
389
410
  end
390
411
 
@@ -397,12 +418,12 @@ describe Assembly::ObjectFile do
397
418
  describe '#exif' do
398
419
  subject(:exif) { object_file.exif }
399
420
 
400
- let(:object_file) { described_class.new(TEST_TIF_INPUT_FILE) }
421
+ let(:object_file) { described_class.new(tif_fixture_file) }
401
422
 
402
- it { is_expected.to be_kind_of MiniExiftool }
423
+ it { is_expected.to be_a MiniExiftool }
403
424
 
404
425
  context 'when exiftool raises an error initializing the file' do
405
- let(:object_file) { described_class.new('spec/test_data/empty.txt') }
426
+ let(:object_file) { described_class.new('spec/fixtures/empty.txt') }
406
427
 
407
428
  it { is_expected.to be_nil }
408
429
  end
@@ -412,30 +433,44 @@ describe Assembly::ObjectFile do
412
433
  # mime-types gem, based on a file extension lookup
413
434
  context 'with .obj file' do
414
435
  it 'application/x-tgif' do
415
- object_file = described_class.new(TEST_OBJ_FILE)
436
+ object_file = described_class.new(obj_fixture_file)
416
437
  expect(object_file.send(:extension_mimetype)).to eq('application/x-tgif')
417
438
  end
418
439
  end
419
440
 
420
441
  context 'with .tif file' do
421
442
  it 'image/tiff' do
422
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
443
+ object_file = described_class.new(tif_fixture_file)
423
444
  expect(object_file.send(:extension_mimetype)).to eq('image/tiff')
424
445
  end
425
446
  end
447
+
448
+ context 'with .vtt file' do
449
+ it 'text/plain' do
450
+ object_file = described_class.new(vtt_fixture_file)
451
+ expect(object_file.send(:extension_mimetype)).to eq('text/vtt')
452
+ end
453
+ end
426
454
  end
427
455
 
428
456
  describe '#exif_mimetype' do
429
457
  context 'with .tif file' do
430
458
  it 'image/tiff' do
431
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
459
+ object_file = described_class.new(tif_fixture_file)
432
460
  expect(object_file.send(:exif_mimetype)).to eq('image/tiff')
433
461
  end
434
462
  end
435
463
 
436
464
  context 'when .json file' do
437
465
  it 'nil' do
438
- object_file = described_class.new(TEST_JSON_FILE)
466
+ object_file = described_class.new(json_fixture_file)
467
+ expect(object_file.send(:exif_mimetype)).to be_nil
468
+ end
469
+ end
470
+
471
+ context 'when .vtt file' do
472
+ it 'nil' do
473
+ object_file = described_class.new(vtt_fixture_file)
439
474
  expect(object_file.send(:exif_mimetype)).to be_nil
440
475
  end
441
476
  end