assembly-objectfile 1.13.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.rubocop.yml +1 -1
  4. data/.rubocop_todo.yml +14 -80
  5. data/Gemfile.lock +106 -0
  6. data/assembly-objectfile.gemspec +1 -3
  7. data/lib/assembly-objectfile/object_file.rb +253 -3
  8. data/lib/assembly-objectfile/version.rb +1 -1
  9. data/lib/assembly-objectfile.rb +0 -5
  10. data/spec/object_file_spec.rb +411 -172
  11. data/spec/spec_helper.rb +2 -31
  12. metadata +19 -107
  13. data/lib/assembly-objectfile/content_metadata/config.rb +0 -26
  14. data/lib/assembly-objectfile/content_metadata/file.rb +0 -63
  15. data/lib/assembly-objectfile/content_metadata/file_set.rb +0 -73
  16. data/lib/assembly-objectfile/content_metadata/file_set_builder.rb +0 -65
  17. data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +0 -57
  18. data/lib/assembly-objectfile/content_metadata.rb +0 -117
  19. data/lib/assembly-objectfile/object_fileable.rb +0 -275
  20. data/spec/content_metadata_spec.rb +0 -809
  21. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif +0 -0
  22. data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif +0 -0
  23. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2 +0 -0
  24. data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2 +0 -0
  25. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf +0 -1
  26. data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf +0 -1
  27. data/spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf +0 -1
  28. data/spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif +0 -0
  29. data/spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf +0 -1
  30. data/spec/test_data/input/res1_image1.jp2 +0 -0
  31. data/spec/test_data/input/res1_image2.jp2 +0 -0
  32. data/spec/test_data/input/res1_image2.tif +0 -0
  33. data/spec/test_data/input/res1_teifile.txt +0 -1
  34. data/spec/test_data/input/res2_image1.jp2 +0 -0
  35. data/spec/test_data/input/res2_image1.tif +0 -0
  36. data/spec/test_data/input/res2_image2.jp2 +0 -0
  37. data/spec/test_data/input/res2_image2.tif +0 -0
  38. data/spec/test_data/input/res2_teifile.txt +0 -1
  39. data/spec/test_data/input/res2_textfile.txt +0 -1
  40. data/spec/test_data/input/res3_image1.jp2 +0 -0
  41. data/spec/test_data/input/res3_image1.tif +0 -0
  42. data/spec/test_data/input/res3_teifile.txt +0 -1
  43. data/spec/test_data/input/test.pdf +0 -1
  44. data/spec/test_data/input/test.svg +0 -2
  45. data/spec/test_data/input/test2.jp2 +0 -0
  46. data/spec/test_data/input/test2.tif +0 -0
@@ -3,220 +3,459 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Assembly::ObjectFile do
6
- it 'does not run if no input file is passed in' do
7
- object_file = described_class.new('')
8
- expect { object_file.filesize }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
9
- expect { object_file.sha1 }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
10
- expect { object_file.md5 }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
6
+ describe '.common_path' do
7
+ context 'when common path is 2 nodes out of 4' do
8
+ it 'returns the common directory' do
9
+ expect(described_class.common_path(['/Users/peter/00/test.tif', '/Users/peter/05/test.jp2'])).to eq('/Users/peter/')
10
+ end
11
+ end
12
+
13
+ context 'when common path is 3 nodes out of 4' do
14
+ it 'returns the common directory' do
15
+ expect(described_class.common_path(['/Users/peter/00/test.tif', '/Users/peter/00/test.jp2'])).to eq('/Users/peter/00/')
16
+ end
17
+ end
18
+
19
+ context 'when all in list terminate in diff directories' do
20
+ it 'returns the common directory' do
21
+ expect(described_class.common_path(['/Users/peter/00', '/Users/peter/05'])).to eq('/Users/peter/')
22
+ end
23
+ end
11
24
  end
12
25
 
13
- it 'returns the common directory of a set of filenames passed into it, where the common part does not terminate on a directory' do
14
- expect(described_class.common_path(['/Users/peter/00/test.tif', '/Users/peter/05/test.jp2'])).to eq('/Users/peter/')
26
+ describe '#new' do
27
+ context 'without params' do
28
+ it 'does not set attributes' do
29
+ object_file = described_class.new('/some/file.txt')
30
+ expect(object_file.path).to eq('/some/file.txt')
31
+ expect(object_file.label).to be_nil
32
+ expect(object_file.file_attributes).to be_nil
33
+ expect(object_file.provider_sha1).to be_nil
34
+ expect(object_file.provider_md5).to be_nil
35
+ expect(object_file.relative_path).to be_nil
36
+ end
37
+ end
38
+
39
+ context 'with params' do
40
+ it 'sets attributes to passed params' do
41
+ object_file = described_class.new('/some/file.txt', label: 'some label', file_attributes: { 'shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no' }, relative_path: '/tmp')
42
+ expect(object_file.path).to eq('/some/file.txt')
43
+ expect(object_file.label).to eq('some label')
44
+ expect(object_file.file_attributes).to eq('shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no')
45
+ expect(object_file.provider_sha1).to be_nil
46
+ expect(object_file.provider_md5).to be_nil
47
+ expect(object_file.relative_path).to eq('/tmp')
48
+ end
49
+
50
+ it 'sets provider_md5 to passed param' do
51
+ object_file = described_class.new('/some/file.txt', provider_md5: 'XYZ')
52
+ expect(object_file.provider_md5).to eq('XYZ')
53
+ end
54
+ end
15
55
  end
16
56
 
17
- it 'returns the common directory of a set of filenames passed into it, where the common part does not terminate on a directory' do
18
- expect(described_class.common_path(['/Users/peter/00/test.tif', '/Users/peter/00/test.jp2'])).to eq('/Users/peter/00/')
57
+ describe '#filename' do
58
+ it 'returns File.basename' do
59
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
60
+ expect(object_file.filename).to eq('test.tif')
61
+ expect(object_file.filename).to eq(File.basename(TEST_TIF_INPUT_FILE))
62
+ end
19
63
  end
20
64
 
21
- it 'tells us if an input file is an image' do
22
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
23
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
24
- expect(object_file.image?).to be(true)
25
- expect(object_file.exif).not_to be_nil
26
- expect(object_file.mimetype).to eq('image/tiff')
27
- expect(object_file.file_mimetype).to eq('image/tiff')
28
- expect(object_file.extension_mimetype).to eq('image/tiff')
29
- expect(object_file.exif_mimetype).to eq('image/tiff')
30
- expect(object_file.object_type).to eq(:image)
31
- expect(object_file.valid_image?).to be(true)
32
- expect(object_file.jp2able?).to be(true)
65
+ describe '#ext' do
66
+ it 'returns the file extension' do
67
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
68
+ expect(object_file.ext).to eq('.tif')
69
+ end
33
70
  end
34
71
 
35
- it 'tells us information about the input file' do
36
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
37
- expect(object_file.filename).to eq('test.tif')
38
- expect(object_file.ext).to eq('.tif')
39
- expect(object_file.filename_without_ext).to eq('test')
40
- expect(object_file.dirname).to eq(File.dirname(TEST_TIF_INPUT_FILE))
72
+ describe '#dirname' do
73
+ it 'returns the File.dirname' do
74
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
75
+ expect(object_file.dirname).to eq(File.dirname(TEST_TIF_INPUT_FILE))
76
+ end
41
77
  end
42
78
 
43
- it 'sets the correct mimetype of plain/text for .txt files' do
44
- object_file = described_class.new(TEST_RES1_TEXT)
45
- expect(object_file.mimetype).to eq('text/plain')
79
+ describe '#filename_without_ext' do
80
+ it 'returns filename before extension' do
81
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
82
+ expect(object_file.filename_without_ext).to eq('test')
83
+ end
46
84
  end
47
85
 
48
- it 'sets the correct mimetype of plain/text for .xml files' do
49
- object_file = described_class.new(TEST_RES1_TEXT)
50
- expect(object_file.mimetype).to eq('text/plain')
86
+ describe '#image?' do
87
+ context 'with tiff' do
88
+ it 'true' do
89
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
90
+ expect(object_file.image?).to be(true)
91
+ end
92
+ end
93
+
94
+ context 'with jp2' do
95
+ it 'true' do
96
+ object_file = described_class.new(TEST_JP2_INPUT_FILE)
97
+ expect(object_file.image?).to be(true)
98
+ end
99
+ end
100
+
101
+ context 'with ruby file' do
102
+ it 'false' do
103
+ non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/object_file_spec.rb')
104
+ object_file = described_class.new(non_image_file)
105
+ expect(object_file.image?).to be(false)
106
+ end
107
+ end
108
+
109
+ context 'with xml' do
110
+ it 'false' do
111
+ non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
112
+ object_file = described_class.new(non_image_file)
113
+ expect(object_file.image?).to be(false)
114
+ end
115
+ end
51
116
  end
52
117
 
53
- it 'sets the correct mimetype of plain/text for .obj 3d files' do
54
- object_file = described_class.new(TEST_OBJ_FILE)
55
- expect(object_file.mimetype).to eq('text/plain')
118
+ describe '#object_type' do
119
+ context 'with tiff' do
120
+ it ':image' do
121
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
122
+ expect(object_file.object_type).to eq(:image)
123
+ end
124
+ end
125
+
126
+ context 'with jp2' do
127
+ it ':image' do
128
+ object_file = described_class.new(TEST_JP2_INPUT_FILE)
129
+ expect(object_file.object_type).to eq(:image)
130
+ end
131
+ end
132
+
133
+ context 'with ruby file' do
134
+ it ':text' do
135
+ non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/object_file_spec.rb')
136
+ object_file = described_class.new(non_image_file)
137
+ expect(object_file.object_type).to eq(:text)
138
+ end
139
+ end
140
+
141
+ context 'with xml' do
142
+ it ':application' do
143
+ non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
144
+ object_file = described_class.new(non_image_file)
145
+ expect(object_file.object_type).to eq(:application)
146
+ end
147
+ end
56
148
  end
57
149
 
58
- it 'sets a mimetype of application/x-tgif for .obj 3d files if we prefer the mimetype extension gem over unix file system command' do
59
- object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[extension file exif])
60
- expect(object_file.mimetype).to eq('application/x-tgif')
150
+ describe '#valid_image?' do
151
+ context 'with tiff' do
152
+ it 'true' do
153
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
154
+ expect(object_file.valid_image?).to be(true)
155
+ end
156
+ end
157
+
158
+ context 'with tiff resolution 1' do
159
+ it 'true' do
160
+ object_file = described_class.new(TEST_RES1_TIF1)
161
+ expect(object_file.valid_image?).to be(true)
162
+ end
163
+ end
164
+
165
+ context 'with tiff no color' do
166
+ it 'true' do
167
+ object_file = described_class.new(TEST_TIFF_NO_COLOR_FILE)
168
+ expect(object_file.valid_image?).to be(true)
169
+ end
170
+ end
171
+
172
+ context 'with jp2' do
173
+ it 'true' do
174
+ object_file = described_class.new(TEST_JP2_INPUT_FILE)
175
+ expect(object_file.valid_image?).to be(true)
176
+ end
177
+ end
178
+
179
+ context 'with ruby file' do
180
+ it 'false' do
181
+ non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/object_file_spec.rb')
182
+ object_file = described_class.new(non_image_file)
183
+ expect(object_file.valid_image?).to be(false)
184
+ end
185
+ end
186
+
187
+ context 'with xml' do
188
+ it 'false' do
189
+ non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
190
+ object_file = described_class.new(non_image_file)
191
+ expect(object_file.valid_image?).to be(false)
192
+ end
193
+ end
61
194
  end
62
195
 
63
- it 'ignores invald mimetype generation methods and still sets a mimetype of application/x-tgif for .obj 3d files if we prefer the mimetype extension gem over unix file system command' do
64
- object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[bogus extension file])
65
- expect(object_file.mimetype).to eq('application/x-tgif')
196
+ describe '#mimetype' do
197
+ # rubocop:disable RSpec/RepeatedExampleGroupBody
198
+ context 'with .txt file' do
199
+ it 'plain/text' do
200
+ object_file = described_class.new(TEST_RES1_TEXT)
201
+ expect(object_file.mimetype).to eq('text/plain')
202
+ end
203
+ end
204
+
205
+ context 'with .xml file' do
206
+ it 'plain/text' do
207
+ object_file = described_class.new(TEST_RES1_TEXT)
208
+ expect(object_file.mimetype).to eq('text/plain')
209
+ end
210
+ end
211
+ # rubocop:enable RSpec/RepeatedExampleGroupBody
212
+
213
+ context 'with .tif file' do
214
+ it 'image/tiff' do
215
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
216
+ expect(object_file.mimetype).to eq('image/tiff')
217
+ end
218
+ end
219
+
220
+ context 'with .jp2 file' do
221
+ it 'image/jp2' do
222
+ object_file = described_class.new(TEST_JP2_INPUT_FILE)
223
+ expect(object_file.mimetype).to eq('image/jp2')
224
+ end
225
+ end
226
+
227
+ context 'with .pdf file' do
228
+ it 'application/pdf' do
229
+ object_file = described_class.new(TEST_RES1_PDF)
230
+ expect(object_file.mimetype).to eq('application/pdf')
231
+ end
232
+ end
233
+
234
+ context 'with .obj (3d) file' do
235
+ context 'when default preference (unix file system command)' do
236
+ it 'plain/text' do
237
+ object_file = described_class.new(TEST_OBJ_FILE)
238
+ expect(object_file.mimetype).to eq('text/plain')
239
+ end
240
+ end
241
+
242
+ context 'when mimetype extension gem preferred over unix file system command' do
243
+ it 'application/x-tgif' do
244
+ object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[extension file exif])
245
+ expect(object_file.mimetype).to eq('application/x-tgif')
246
+ end
247
+ end
248
+
249
+ context 'when invalid first preference mimetype generation' do
250
+ it 'ignores invalid mimetype generation method and respects valid method preference order' do
251
+ object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[bogus extension file])
252
+ expect(object_file.mimetype).to eq('application/x-tgif')
253
+ end
254
+ end
255
+ end
256
+
257
+ context 'with .ply 3d file' do
258
+ it 'text/plain' do
259
+ object_file = described_class.new(TEST_PLY_FILE)
260
+ expect(object_file.mimetype).to eq('text/plain')
261
+ end
262
+ end
263
+
264
+ context 'when exif information is damaged' do
265
+ it 'gives us the mimetype' do
266
+ object_file = described_class.new(TEST_FILE_NO_EXIF)
267
+ expect(object_file.filename).to eq('file_with_no_exif.xml')
268
+ expect(object_file.ext).to eq('.xml')
269
+ # we could get either of these mimetypes depending on the OS
270
+ expect(['text/html', 'application/xml'].include?(object_file.mimetype)).to be true
271
+ end
272
+ end
273
+
274
+ context 'when .json file' do
275
+ it 'uses the manual mapping to set the correct mimetype of application/json for a .json file' do
276
+ object_file = described_class.new(TEST_JSON_FILE)
277
+ expect(object_file.send(:exif_mimetype)).to be_nil # exif
278
+ expect(object_file.send(:file_mimetype)).to eq('text/plain') # unix file system command
279
+ expect(object_file.mimetype).to eq('application/json') # our configured mapping overrides both
280
+ end
281
+ end
66
282
  end
67
283
 
68
- it 'sets the correct mimetype of plain/text for .ply 3d files' do
69
- object_file = described_class.new(TEST_PLY_FILE)
70
- expect(object_file.mimetype).to eq('text/plain')
284
+ describe '#file_mimetype (unix file system command)' do
285
+ context 'when .json file' do
286
+ it 'text/plain' do
287
+ object_file = described_class.new(TEST_JSON_FILE)
288
+ expect(object_file.send(:file_mimetype)).to eq('text/plain')
289
+ end
290
+ end
291
+
292
+ context 'when .tif file' do
293
+ it 'image/tiff' do
294
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
295
+ expect(object_file.send(:file_mimetype)).to eq('image/tiff')
296
+ end
297
+ end
71
298
  end
72
299
 
73
- it 'overrides the mimetype generators and uses the manual mapping to set the correct mimetype of application/json for a .json file' do
74
- object_file = described_class.new(TEST_JSON_FILE)
75
- expect(object_file.exif_mimetype).to be_nil # exif returns nil
76
- expect(object_file.file_mimetype).to eq('text/plain') # unix file system command returns plain text
77
- expect(object_file.mimetype).to eq('application/json') # but our configured mapping overrides both and returns application/json
300
+ describe '#jp2able?' do
301
+ context 'with jp2 file' do
302
+ it 'false' do
303
+ object_file = described_class.new(TEST_JP2_INPUT_FILE)
304
+ expect(object_file.jp2able?).to be(false)
305
+ end
306
+ end
307
+
308
+ context 'with tiff resolution 1 file' do
309
+ it 'true' do
310
+ object_file = described_class.new(TEST_RES1_TIF1)
311
+ expect(object_file.jp2able?).to be(true)
312
+ end
313
+ end
314
+
315
+ context 'with tiff no color file' do
316
+ it 'true' do
317
+ object_file = described_class.new(TEST_TIFF_NO_COLOR_FILE)
318
+ expect(object_file.jp2able?).to be(true)
319
+ end
320
+ end
78
321
  end
79
322
 
80
- it 'sets the correct mimetype of image/tiff for .tif files' do
81
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
82
- expect(object_file.mimetype).to eq('image/tiff')
323
+ describe '#has_color_profile?' do
324
+ context 'with jp2 file' do
325
+ it 'true' do
326
+ object_file = described_class.new(TEST_JP2_INPUT_FILE)
327
+ expect(object_file.has_color_profile?).to be(true)
328
+ end
329
+ end
330
+
331
+ context 'with tiff file' do
332
+ it 'true' do
333
+ object_file = described_class.new(TEST_RES1_TIF1)
334
+ expect(object_file.has_color_profile?).to be(true)
335
+ end
336
+ end
337
+
338
+ context 'with tiff no color file' do
339
+ it 'false' do
340
+ object_file = described_class.new(TEST_TIFF_NO_COLOR_FILE)
341
+ expect(object_file.has_color_profile?).to be(false)
342
+ end
343
+ end
83
344
  end
84
345
 
85
- it 'sets the correct mimetype of image/jp2 for .jp2 files' do
86
- object_file = described_class.new(TEST_JP2_INPUT_FILE)
87
- expect(object_file.mimetype).to eq('image/jp2')
88
- end
346
+ describe '#md5' do
347
+ it 'computes md5 for an image file' do
348
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
349
+ expect(object_file.md5).to eq('a2400500acf21e43f5440d93be894101')
350
+ end
89
351
 
90
- it 'sets the correct mimetype of application/pdf for .pdf files' do
91
- object_file = described_class.new(TEST_RES1_PDF)
92
- expect(object_file.mimetype).to eq('application/pdf')
352
+ it 'raises RuntimeError if no input file is passed in' do
353
+ object_file = described_class.new('')
354
+ expect { object_file.md5 }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
355
+ end
93
356
  end
94
357
 
95
- it 'gives us the mimetype of a file even if the exif information is damaged' do
96
- object_file = described_class.new(TEST_FILE_NO_EXIF)
97
- expect(object_file.filename).to eq('file_with_no_exif.xml')
98
- expect(object_file.ext).to eq('.xml')
99
- expect(['text/html', 'application/xml'].include?(object_file.mimetype)).to be true # we could get either of these mimetypes depending on the OS
100
- end
358
+ describe '#sha1' do
359
+ it 'computes sha1 for an image file' do
360
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
361
+ expect(object_file.sha1).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
362
+ end
101
363
 
102
- it 'gives us the DPG base name for a file' do
103
- test_file = File.join(TEST_INPUT_DIR, 'oo000oo0001_00_001.tif')
104
- object_file = described_class.new(test_file)
105
- expect(object_file.dpg_basename).to eq('oo000oo0001_001')
364
+ it 'raises RuntimeError if no input file is passed in' do
365
+ object_file = described_class.new('')
366
+ expect { object_file.sha1 }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
367
+ end
106
368
  end
107
369
 
108
- it 'gives us the DPG subfolder name for a file' do
109
- test_file = File.join(TEST_INPUT_DIR, 'oo000oo0001_05_001.tif')
110
- object_file = described_class.new(test_file)
111
- expect(object_file.dpg_folder).to eq('05')
370
+ describe '#file_exists?' do
371
+ it 'false when a valid directory is specified instead of a file' do
372
+ path = Assembly::PATH_TO_GEM
373
+ object_file = described_class.new(path)
374
+ expect(File.exist?(path)).to be true
375
+ expect(File.directory?(path)).to be true
376
+ expect(object_file.file_exists?).to be false
377
+ end
378
+
379
+ it 'false when a non-existent file is specified' do
380
+ path = File.join(Assembly::PATH_TO_GEM, 'file_not_there.txt')
381
+ object_file = described_class.new(path)
382
+ expect(File.exist?(path)).to be false
383
+ expect(File.directory?(path)).to be false
384
+ expect(object_file.file_exists?).to be false
385
+ end
112
386
  end
113
387
 
114
- it 'tells us that a jp2 file is not jp2able but does have a color profile' do
115
- expect(File.exist?(TEST_JP2_INPUT_FILE)).to be true
116
- object_file = described_class.new(TEST_JP2_INPUT_FILE)
117
- expect(object_file.image?).to be(true)
118
- expect(object_file.object_type).to eq(:image)
119
- expect(object_file.valid_image?).to be(true)
120
- expect(object_file.jp2able?).to be(false)
121
- expect(object_file.has_color_profile?).to be(true)
122
- end
123
-
124
- it 'tells us that a tiff file is jp2able and has a color profile' do
125
- expect(File.exist?(TEST_RES1_TIF1)).to be true
126
- object_file = described_class.new(TEST_RES1_TIF1)
127
- expect(object_file.image?).to be(true)
128
- expect(object_file.object_type).to eq(:image)
129
- expect(object_file.valid_image?).to be(true)
130
- expect(object_file.jp2able?).to be(true)
131
- expect(object_file.has_color_profile?).to be(true)
132
- end
388
+ describe '#filesize' do
389
+ it 'tells us the size of an input file' do
390
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
391
+ expect(object_file.filesize).to eq(63_542)
392
+ end
133
393
 
134
- it 'tells us that a tiff file is not jp2able and is not valid since it has no profile' do
135
- expect(File.exist?(TEST_TIFF_NO_COLOR_FILE)).to be true
136
- object_file = described_class.new(TEST_TIFF_NO_COLOR_FILE)
137
- expect(object_file.image?).to be(true)
138
- expect(object_file.object_type).to eq(:image)
139
- expect(object_file.valid_image?).to be(true)
140
- expect(object_file.jp2able?).to be(true)
141
- expect(object_file.has_color_profile?).to be(false)
394
+ it 'raises RuntimeError if no file is passed in' do
395
+ object_file = described_class.new('')
396
+ expect { object_file.filesize }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
397
+ end
142
398
  end
143
399
 
144
- it 'computes checksums for an image file' do
145
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
146
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
147
- expect(object_file.md5).to eq('a2400500acf21e43f5440d93be894101')
148
- expect(object_file.sha1).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
400
+ describe '#encoding' do
401
+ context 'with .tif file' do
402
+ it 'binary' do
403
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
404
+ expect(object_file.send(:encoding)).to eq('binary')
405
+ end
406
+ end
407
+
408
+ context 'with .txt file' do
409
+ it 'binary' do
410
+ object_file = described_class.new(TEST_RES1_TEXT)
411
+ expect(object_file.send(:encoding)).to eq('us-ascii')
412
+ end
413
+ end
149
414
  end
150
415
 
151
- it 'indicates that the file is not found when a valid directory is supplied instead of a file or when an invalid file path is specified' do
152
- path = Assembly::PATH_TO_GEM
153
- object_file = described_class.new(path)
154
- expect(File.exist?(path)).to be true
155
- expect(File.directory?(path)).to be true
156
- expect(object_file.file_exists?).to be false
157
-
158
- path = File.join(Assembly::PATH_TO_GEM, 'bogus.txt')
159
- object_file = described_class.new(path)
160
- expect(File.exist?(path)).to be false
161
- expect(File.directory?(path)).to be false
162
- expect(object_file.file_exists?).to be false
163
- end
164
-
165
- it 'sets attributes correctly when initializing' do
166
- object_file = described_class.new('/some/file.txt')
167
- expect(object_file.path).to eq('/some/file.txt')
168
- expect(object_file.label).to be_nil
169
- expect(object_file.file_attributes).to be_nil
170
- expect(object_file.provider_sha1).to be_nil
171
- expect(object_file.provider_md5).to be_nil
172
- expect(object_file.relative_path).to be_nil
173
-
174
- object_file = described_class.new('/some/file.txt', label: 'some label', file_attributes: { 'shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no' }, relative_path: '/tmp')
175
- expect(object_file.path).to eq('/some/file.txt')
176
- expect(object_file.label).to eq('some label')
177
- expect(object_file.file_attributes).to eq('shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no')
178
- expect(object_file.provider_sha1).to be_nil
179
- expect(object_file.provider_md5).to be_nil
180
- expect(object_file.relative_path).to eq('/tmp')
416
+ describe '#exif' do
417
+ it 'returns MiniExiftool object' do
418
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
419
+ expect(object_file.exif).not_to be_nil
420
+ expect(object_file.exif.class).to eq MiniExiftool
421
+ end
422
+
423
+ it 'raises MiniExiftool::Error if exiftool raises one' do
424
+ object_file = described_class.new('spec/test_data/empty.txt')
425
+ expect { object_file.exif }.to raise_error(MiniExiftool::Error)
426
+ end
181
427
  end
182
428
 
183
- it 'sets md5_provider attribute' do
184
- object_file = described_class.new('/some/file.txt', provider_md5: 'XYZ')
185
- expect(object_file.provider_md5).to eq('XYZ')
429
+ describe '#extension_mimetype' do
430
+ # mime-types gem, based on a file extension lookup
431
+ context 'with .obj file' do
432
+ it 'application/x-tgif' do
433
+ object_file = described_class.new(TEST_OBJ_FILE)
434
+ expect(object_file.send(:extension_mimetype)).to eq('application/x-tgif')
435
+ end
436
+ end
437
+
438
+ context 'with .tif file' do
439
+ it 'image/tiff' do
440
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
441
+ expect(object_file.send(:extension_mimetype)).to eq('image/tiff')
442
+ end
443
+ end
186
444
  end
187
445
 
188
- it 'tells us if an input file is not an image' do
189
- non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/object_file_spec.rb')
190
- expect(File.exist?(non_image_file)).to be true
191
- object_file = described_class.new(non_image_file)
192
- expect(object_file.image?).to be(false)
193
- expect(object_file.object_type).not_to eq(:image)
194
- expect(object_file.valid_image?).to be(false)
195
-
196
- non_image_file = File.join(Assembly::PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
197
- expect(File.exist?(non_image_file)).to be true
198
- object_file = described_class.new(non_image_file)
199
- expect(object_file.image?).to be(false)
200
- expect(object_file.object_type).not_to eq(:image)
201
- expect(object_file.valid_image?).to be(false)
202
- end
203
-
204
- it 'tells us the size of an input file' do
205
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
206
- object_file = described_class.new(TEST_TIF_INPUT_FILE)
207
- expect(object_file.filesize).to eq(63_542)
208
- end
209
-
210
- it 'tells us the mimetype and encoding of an input file' do
211
- expect(File.exist?(TEST_TIF_INPUT_FILE)).to be true
212
- @ai = described_class.new(TEST_TIF_INPUT_FILE)
213
- expect(@ai.mimetype).to eq('image/tiff')
214
- expect(@ai.file_mimetype).to eq('image/tiff')
215
- expect(@ai.encoding).to eq('binary')
216
- end
217
-
218
- it 'raises MiniExiftool::Error if exiftool raises one' do
219
- object_file = described_class.new('spec/test_data/empty.txt')
220
- expect { object_file.exif }.to raise_error(MiniExiftool::Error)
446
+ describe '#exif_mimetype' do
447
+ context 'with .tif file' do
448
+ it 'image/tiff' do
449
+ object_file = described_class.new(TEST_TIF_INPUT_FILE)
450
+ expect(object_file.send(:exif_mimetype)).to eq('image/tiff')
451
+ end
452
+ end
453
+
454
+ context 'when .json file' do
455
+ it 'nil' do
456
+ object_file = described_class.new(TEST_JSON_FILE)
457
+ expect(object_file.send(:exif_mimetype)).to be_nil
458
+ end
459
+ end
221
460
  end
222
461
  end