assembly-objectfile 1.11.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +14 -0
- data/.github/pull_request_template.md +3 -5
- data/.gitignore +0 -1
- data/.rubocop.yml +87 -15
- data/.rubocop_todo.yml +19 -74
- data/Gemfile +2 -0
- data/Gemfile.lock +106 -0
- data/README.md +1 -1
- data/assembly-objectfile.gemspec +5 -6
- data/lib/assembly-objectfile/object_file.rb +253 -3
- data/lib/assembly-objectfile/version.rb +2 -2
- data/lib/assembly-objectfile.rb +0 -5
- data/spec/object_file_spec.rb +411 -167
- data/spec/spec_helper.rb +3 -31
- data/spec/test_data/empty.txt +0 -0
- metadata +35 -121
- data/.travis.yml +0 -20
- data/lib/assembly-objectfile/content_metadata/config.rb +0 -26
- data/lib/assembly-objectfile/content_metadata/file.rb +0 -63
- data/lib/assembly-objectfile/content_metadata/file_set.rb +0 -73
- data/lib/assembly-objectfile/content_metadata/file_set_builder.rb +0 -65
- data/lib/assembly-objectfile/content_metadata/nokogiri_builder.rb +0 -57
- data/lib/assembly-objectfile/content_metadata.rb +0 -117
- data/lib/assembly-objectfile/object_fileable.rb +0 -278
- data/spec/content_metadata_spec.rb +0 -791
- data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_001.tif +0 -0
- data/spec/test_data/input/oo000oo0001/00/oo000oo0001_00_002.tif +0 -0
- data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_001.jp2 +0 -0
- data/spec/test_data/input/oo000oo0001/05/oo000oo0001_05_002.jp2 +0 -0
- data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_001.pdf +0 -1
- data/spec/test_data/input/oo000oo0001/15/oo000oo0001_15_002.pdf +0 -1
- data/spec/test_data/input/oo000oo0001/31/oo000oo0001_31_001.pdf +0 -1
- data/spec/test_data/input/oo000oo0001/50/oo000oo0001_50_001.tif +0 -0
- data/spec/test_data/input/oo000oo0001/oo000oo0001_book.pdf +0 -1
- data/spec/test_data/input/res1_image1.jp2 +0 -0
- data/spec/test_data/input/res1_image2.jp2 +0 -0
- data/spec/test_data/input/res1_image2.tif +0 -0
- data/spec/test_data/input/res1_teifile.txt +0 -1
- data/spec/test_data/input/res2_image1.jp2 +0 -0
- data/spec/test_data/input/res2_image1.tif +0 -0
- data/spec/test_data/input/res2_image2.jp2 +0 -0
- data/spec/test_data/input/res2_image2.tif +0 -0
- data/spec/test_data/input/res2_teifile.txt +0 -1
- data/spec/test_data/input/res2_textfile.txt +0 -1
- data/spec/test_data/input/res3_image1.jp2 +0 -0
- data/spec/test_data/input/res3_image1.tif +0 -0
- data/spec/test_data/input/res3_teifile.txt +0 -1
- data/spec/test_data/input/test.pdf +0 -1
- data/spec/test_data/input/test2.jp2 +0 -0
- data/spec/test_data/input/test2.tif +0 -0
data/spec/object_file_spec.rb
CHANGED
@@ -3,215 +3,459 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Assembly::ObjectFile do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
14
|
-
|
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
|
-
|
18
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
expect(@ai.mimetype).to eq('image/tiff')
|
27
|
-
expect(@ai.file_mimetype).to eq('image/tiff')
|
28
|
-
expect(@ai.extension_mimetype).to eq('image/tiff')
|
29
|
-
expect(@ai.exif_mimetype).to eq('image/tiff')
|
30
|
-
expect(@ai.object_type).to eq(:image)
|
31
|
-
expect(@ai.valid_image?).to eq(true)
|
32
|
-
expect(@ai.jp2able?).to eq(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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
expect(@ai.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
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
expect(@ai.valid_image?).to eq(true)
|
120
|
-
expect(@ai.jp2able?).to eq(false)
|
121
|
-
expect(@ai.has_color_profile?).to eq(true)
|
122
|
-
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
|
123
393
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
expect(@ai.object_type).to eq(:image)
|
129
|
-
expect(@ai.valid_image?).to eq(true)
|
130
|
-
expect(@ai.jp2able?).to eq(true)
|
131
|
-
expect(@ai.has_color_profile?).to eq(true)
|
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
|
132
398
|
end
|
133
399
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
142
414
|
end
|
143
415
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
149
427
|
end
|
150
428
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
@ai = described_class.new('/some/file.txt')
|
167
|
-
expect(@ai.path).to eq('/some/file.txt')
|
168
|
-
expect(@ai.label).to be_nil
|
169
|
-
expect(@ai.file_attributes).to be_nil
|
170
|
-
expect(@ai.provider_sha1).to be_nil
|
171
|
-
expect(@ai.provider_md5).to be_nil
|
172
|
-
expect(@ai.relative_path).to be_nil
|
173
|
-
|
174
|
-
@ai = described_class.new('/some/file.txt', label: 'some label', file_attributes: { 'shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no' }, relative_path: '/tmp')
|
175
|
-
expect(@ai.path).to eq('/some/file.txt')
|
176
|
-
expect(@ai.label).to eq('some label')
|
177
|
-
expect(@ai.file_attributes).to eq('shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no')
|
178
|
-
expect(@ai.provider_sha1).to be_nil
|
179
|
-
expect(@ai.provider_md5).to be_nil
|
180
|
-
expect(@ai.relative_path).to eq('/tmp')
|
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
|
181
444
|
end
|
182
445
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
expect(File.exist?(non_image_file)).to be true
|
198
|
-
@ai = described_class.new(non_image_file)
|
199
|
-
expect(@ai.image?).to eq(false)
|
200
|
-
expect(@ai.object_type).not_to eq(:image)
|
201
|
-
expect(@ai.valid_image?).to eq(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
|
-
@ai = described_class.new(TEST_TIF_INPUT_FILE)
|
207
|
-
expect(@ai.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')
|
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
|
216
460
|
end
|
217
461
|
end
|