assembly-objectfile 1.13.0 → 2.1.1
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 +1 -1
- data/.gitignore +0 -1
- data/.rubocop.yml +34 -1
- data/.rubocop_todo.yml +3 -120
- data/Gemfile.lock +97 -0
- data/README.md +6 -6
- data/assembly-objectfile.gemspec +4 -8
- data/config/boot.rb +0 -1
- data/lib/{assembly-objectfile → assembly/object_file}/version.rb +1 -1
- data/lib/{assembly-objectfile/object_fileable.rb → assembly/object_file.rb} +116 -101
- data/lib/assembly-objectfile.rb +14 -19
- data/spec/assembly/object_file_spec.rb +452 -0
- data/spec/spec_helper.rb +3 -37
- metadata +10 -143
- 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_file.rb +0 -29
- data/profiles/AdobeRGB1998.icc +0 -0
- data/profiles/DotGain20.icc +0 -0
- data/profiles/sRGBIEC6196621.icc +0 -0
- data/spec/content_metadata_spec.rb +0 -809
- data/spec/object_file_spec.rb +0 -222
- 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/test.svg +0 -2
- data/spec/test_data/input/test2.jp2 +0 -0
- data/spec/test_data/input/test2.tif +0 -0
data/lib/assembly-objectfile.rb
CHANGED
@@ -1,30 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Assembly
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
# if input image is not one of these mime types, it will not be regarded as a valid image for the purpose of generating a JP2 derivative
|
4
|
+
# If input image is not one of these mime types, it will not be regarded as a valid image
|
5
|
+
# for the purpose of generating a JP2 derivative
|
8
6
|
VALID_IMAGE_MIMETYPES = ['image/jpeg', 'image/tiff', 'image/tif', 'image/png'].freeze
|
9
7
|
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
TRUSTED_MIMETYPES = ['text/plain', 'plain/text', 'application/pdf', 'text/html', 'application/xml'].freeze
|
8
|
+
# The list of mimetypes that will be "trusted" by the unix file command; if a mimetype other than
|
9
|
+
# one of these is returned by the file command, then a check will be made to see if exif data exists...
|
10
|
+
# if so, the mimetype returned by the exif data will be used if no exif data exists, then the
|
11
|
+
# mimetype returned by the unix file command will be used
|
12
|
+
TRUSTED_MIMETYPES = ['text/plain', 'plain/text', 'application/pdf', 'text/html', 'application/xml',
|
13
|
+
'application/octet-stream'].freeze
|
17
14
|
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
15
|
+
# This is a manual override mapping of file extension to mimetype; if a file with the given extension
|
16
|
+
# is found, the mapped mimetype will be returned and no further methods will be used - this is used
|
17
|
+
# to force a specific mimetype to be returned for a given file extension regardless of what exif or
|
18
|
+
# the unix file system command returns the mapping format is "extension with period: returned mimetype",
|
19
|
+
# e.g. for any .json file, you will always get `application/json`
|
22
20
|
OVERRIDE_MIMETYPES = {
|
23
21
|
'.json': 'application/json'
|
24
22
|
}.freeze
|
25
23
|
end
|
26
24
|
|
27
|
-
require 'assembly
|
28
|
-
require 'assembly-objectfile/object_fileable'
|
29
|
-
require 'assembly-objectfile/object_file'
|
30
|
-
require 'assembly-objectfile/version'
|
25
|
+
require 'assembly/object_file'
|
@@ -0,0 +1,452 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Assembly::ObjectFile do
|
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',
|
10
|
+
'/Users/peter/05/test.jp2'])).to eq('/Users/peter/')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when common path is 3 nodes out of 4' do
|
15
|
+
it 'returns the common directory' do
|
16
|
+
expect(described_class.common_path(['/Users/peter/00/test.tif',
|
17
|
+
'/Users/peter/00/test.jp2'])).to eq('/Users/peter/00/')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when all in list terminate in diff directories' do
|
22
|
+
it 'returns the common directory' do
|
23
|
+
expect(described_class.common_path(['/Users/peter/00', '/Users/peter/05'])).to eq('/Users/peter/')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#new' do
|
29
|
+
context 'without params' do
|
30
|
+
let(:object_file) { described_class.new('/some/file.txt') }
|
31
|
+
|
32
|
+
it 'does not set attributes' do
|
33
|
+
expect(object_file.path).to eq('/some/file.txt')
|
34
|
+
expect(object_file.label).to be_nil
|
35
|
+
expect(object_file.file_attributes).to be_nil
|
36
|
+
expect(object_file.provider_sha1).to be_nil
|
37
|
+
expect(object_file.provider_md5).to be_nil
|
38
|
+
expect(object_file.relative_path).to be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with params' do
|
43
|
+
let(:object_file) do
|
44
|
+
described_class.new('/some/file.txt', label: 'some label',
|
45
|
+
file_attributes: { 'shelve' => 'yes',
|
46
|
+
'publish' => 'yes',
|
47
|
+
'preserve' => 'no' },
|
48
|
+
relative_path: '/tmp')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'sets attributes to passed params' do
|
52
|
+
expect(object_file.path).to eq('/some/file.txt')
|
53
|
+
expect(object_file.label).to eq('some label')
|
54
|
+
expect(object_file.file_attributes).to eq('shelve' => 'yes', 'publish' => 'yes', 'preserve' => 'no')
|
55
|
+
expect(object_file.provider_sha1).to be_nil
|
56
|
+
expect(object_file.provider_md5).to be_nil
|
57
|
+
expect(object_file.relative_path).to eq('/tmp')
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with provider_md5' do
|
61
|
+
let(:object_file) { described_class.new('/some/file.txt', provider_md5: 'XYZ') }
|
62
|
+
|
63
|
+
it 'sets provider_md5 to passed param' do
|
64
|
+
expect(object_file.provider_md5).to eq('XYZ')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#filename' do
|
71
|
+
it 'returns File.basename' do
|
72
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
73
|
+
expect(object_file.filename).to eq('test.tif')
|
74
|
+
expect(object_file.filename).to eq(File.basename(TEST_TIF_INPUT_FILE))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#ext' do
|
79
|
+
it 'returns the file extension' do
|
80
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
81
|
+
expect(object_file.ext).to eq('.tif')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#dirname' do
|
86
|
+
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))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#filename_without_ext' do
|
93
|
+
it 'returns filename before extension' do
|
94
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
95
|
+
expect(object_file.filename_without_ext).to eq('test')
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#image?' do
|
100
|
+
context 'with tiff' do
|
101
|
+
it 'true' do
|
102
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
103
|
+
expect(object_file.image?).to be(true)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'with jp2' do
|
108
|
+
it 'true' do
|
109
|
+
object_file = described_class.new(TEST_JP2_INPUT_FILE)
|
110
|
+
expect(object_file.image?).to be(true)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'with ruby file' do
|
115
|
+
it 'false' do
|
116
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/assembly/object_file_spec.rb')
|
117
|
+
object_file = described_class.new(non_image_file)
|
118
|
+
expect(object_file.image?).to be(false)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'with xml' do
|
123
|
+
it 'false' do
|
124
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
|
125
|
+
object_file = described_class.new(non_image_file)
|
126
|
+
expect(object_file.image?).to be(false)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#object_type' do
|
132
|
+
context 'with tiff' do
|
133
|
+
it ':image' do
|
134
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
135
|
+
expect(object_file.object_type).to eq(:image)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'with jp2' do
|
140
|
+
it ':image' do
|
141
|
+
object_file = described_class.new(TEST_JP2_INPUT_FILE)
|
142
|
+
expect(object_file.object_type).to eq(:image)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'with ruby file' do
|
147
|
+
it ':text' do
|
148
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/assembly/object_file_spec.rb')
|
149
|
+
object_file = described_class.new(non_image_file)
|
150
|
+
expect(object_file.object_type).to eq(:text)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context 'with xml' do
|
155
|
+
it ':application' do
|
156
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
|
157
|
+
object_file = described_class.new(non_image_file)
|
158
|
+
expect(object_file.object_type).to eq(:application)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe '#valid_image?' do
|
164
|
+
context 'with tiff' do
|
165
|
+
it 'true' do
|
166
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
167
|
+
expect(object_file.valid_image?).to be(true)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'with tiff resolution 1' do
|
172
|
+
it 'true' do
|
173
|
+
object_file = described_class.new(TEST_RES1_TIF1)
|
174
|
+
expect(object_file.valid_image?).to be(true)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'with tiff no color' do
|
179
|
+
it 'true' do
|
180
|
+
object_file = described_class.new(TEST_TIFF_NO_COLOR_FILE)
|
181
|
+
expect(object_file.valid_image?).to be(true)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'with jp2' do
|
186
|
+
it 'true' do
|
187
|
+
object_file = described_class.new(TEST_JP2_INPUT_FILE)
|
188
|
+
expect(object_file.valid_image?).to be(true)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'with ruby file' do
|
193
|
+
it 'false' do
|
194
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/assembly/object_file_spec.rb')
|
195
|
+
object_file = described_class.new(non_image_file)
|
196
|
+
expect(object_file.valid_image?).to be(false)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'with xml' do
|
201
|
+
it 'false' do
|
202
|
+
non_image_file = File.join(PATH_TO_GEM, 'spec/test_data/input/file_with_no_exif.xml')
|
203
|
+
object_file = described_class.new(non_image_file)
|
204
|
+
expect(object_file.valid_image?).to be(false)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe '#mimetype' do
|
210
|
+
# rubocop:disable RSpec/RepeatedExampleGroupBody
|
211
|
+
context 'with .txt file' do
|
212
|
+
it 'plain/text' do
|
213
|
+
object_file = described_class.new(TEST_RES1_TEXT)
|
214
|
+
expect(object_file.mimetype).to eq('text/plain')
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'with .xml file' do
|
219
|
+
it 'plain/text' do
|
220
|
+
object_file = described_class.new(TEST_RES1_TEXT)
|
221
|
+
expect(object_file.mimetype).to eq('text/plain')
|
222
|
+
end
|
223
|
+
end
|
224
|
+
# rubocop:enable RSpec/RepeatedExampleGroupBody
|
225
|
+
|
226
|
+
context 'with .tif file' do
|
227
|
+
it 'image/tiff' do
|
228
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
229
|
+
expect(object_file.mimetype).to eq('image/tiff')
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
context 'with .jp2 file' do
|
234
|
+
it 'image/jp2' do
|
235
|
+
object_file = described_class.new(TEST_JP2_INPUT_FILE)
|
236
|
+
expect(object_file.mimetype).to eq('image/jp2')
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context 'with .pdf file' do
|
241
|
+
it 'application/pdf' do
|
242
|
+
object_file = described_class.new(TEST_RES1_PDF)
|
243
|
+
expect(object_file.mimetype).to eq('application/pdf')
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'with .obj (3d) file' do
|
248
|
+
context 'when default preference (unix file system command)' do
|
249
|
+
it 'plain/text' do
|
250
|
+
object_file = described_class.new(TEST_OBJ_FILE)
|
251
|
+
expect(object_file.mimetype).to eq('text/plain')
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'when mimetype extension gem preferred over unix file system command' do
|
256
|
+
it 'application/x-tgif' do
|
257
|
+
object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[extension file exif])
|
258
|
+
expect(object_file.mimetype).to eq('application/x-tgif')
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'when invalid first preference mimetype generation' do
|
263
|
+
it 'ignores invalid mimetype generation method and respects valid method preference order' do
|
264
|
+
object_file = described_class.new(TEST_OBJ_FILE, mime_type_order: %i[bogus extension file])
|
265
|
+
expect(object_file.mimetype).to eq('application/x-tgif')
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context 'with .ply 3d file' do
|
271
|
+
it 'text/plain' do
|
272
|
+
object_file = described_class.new(TEST_PLY_FILE)
|
273
|
+
expect(object_file.mimetype).to eq('text/plain')
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context 'when exif information is damaged' do
|
278
|
+
it 'gives us the mimetype' do
|
279
|
+
object_file = described_class.new(TEST_FILE_NO_EXIF)
|
280
|
+
expect(object_file.filename).to eq('file_with_no_exif.xml')
|
281
|
+
expect(object_file.ext).to eq('.xml')
|
282
|
+
# we could get either of these mimetypes depending on the OS
|
283
|
+
expect(['text/html', 'application/xml'].include?(object_file.mimetype)).to be true
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context 'when .json file' do
|
288
|
+
it 'uses the manual mapping to set the correct mimetype of application/json for a .json file' do
|
289
|
+
object_file = described_class.new(TEST_JSON_FILE)
|
290
|
+
expect(object_file.send(:exif_mimetype)).to be_nil # exif
|
291
|
+
expect(object_file.send(:file_mimetype)).to eq('text/plain') # unix file system command
|
292
|
+
expect(object_file.mimetype).to eq('application/json') # our configured mapping overrides both
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe '#file_mimetype (unix file system command)' do
|
298
|
+
context 'when .json file' do
|
299
|
+
it 'text/plain' do
|
300
|
+
object_file = described_class.new(TEST_JSON_FILE)
|
301
|
+
expect(object_file.send(:file_mimetype)).to eq('text/plain')
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context 'when .tif file' do
|
306
|
+
it 'image/tiff' do
|
307
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
308
|
+
expect(object_file.send(:file_mimetype)).to eq('image/tiff')
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
describe '#jp2able?' do
|
314
|
+
context 'with jp2 file' do
|
315
|
+
it 'false' do
|
316
|
+
object_file = described_class.new(TEST_JP2_INPUT_FILE)
|
317
|
+
expect(object_file.jp2able?).to be(false)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
context 'with tiff resolution 1 file' do
|
322
|
+
it 'true' do
|
323
|
+
object_file = described_class.new(TEST_RES1_TIF1)
|
324
|
+
expect(object_file.jp2able?).to be(true)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
context 'with tiff no color file' do
|
329
|
+
it 'true' do
|
330
|
+
object_file = described_class.new(TEST_TIFF_NO_COLOR_FILE)
|
331
|
+
expect(object_file.jp2able?).to be(true)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
describe '#md5' do
|
337
|
+
it 'computes md5 for an image file' do
|
338
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
339
|
+
expect(object_file.md5).to eq('a2400500acf21e43f5440d93be894101')
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'raises RuntimeError if no input file is passed in' do
|
343
|
+
object_file = described_class.new('')
|
344
|
+
expect { object_file.md5 }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
describe '#sha1' do
|
349
|
+
it 'computes sha1 for an image file' do
|
350
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
351
|
+
expect(object_file.sha1).to eq('8d11fab63089a24c8b17063d29a4b0eac359fb41')
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'raises RuntimeError if no input file is passed in' do
|
355
|
+
object_file = described_class.new('')
|
356
|
+
expect { object_file.sha1 }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
describe '#file_exists?' do
|
361
|
+
it 'false when a valid directory is specified instead of a file' do
|
362
|
+
path = PATH_TO_GEM
|
363
|
+
object_file = described_class.new(path)
|
364
|
+
expect(File.exist?(path)).to be true
|
365
|
+
expect(File.directory?(path)).to be true
|
366
|
+
expect(object_file.file_exists?).to be false
|
367
|
+
end
|
368
|
+
|
369
|
+
it 'false when a non-existent file is specified' do
|
370
|
+
path = File.join(PATH_TO_GEM, 'file_not_there.txt')
|
371
|
+
object_file = described_class.new(path)
|
372
|
+
expect(File.exist?(path)).to be false
|
373
|
+
expect(File.directory?(path)).to be false
|
374
|
+
expect(object_file.file_exists?).to be false
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
describe '#filesize' do
|
379
|
+
it 'tells us the size of an input file' do
|
380
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
381
|
+
expect(object_file.filesize).to eq(63_542)
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'raises RuntimeError if no file is passed in' do
|
385
|
+
object_file = described_class.new('')
|
386
|
+
expect { object_file.filesize }.to raise_error(RuntimeError, 'input file does not exist or is a directory')
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
describe '#encoding' do
|
391
|
+
context 'with .tif file' do
|
392
|
+
it 'binary' do
|
393
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
394
|
+
expect(object_file.send(:encoding)).to eq('binary')
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
context 'with .txt file' do
|
399
|
+
it 'binary' do
|
400
|
+
object_file = described_class.new(TEST_RES1_TEXT)
|
401
|
+
expect(object_file.send(:encoding)).to eq('us-ascii')
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
describe '#exif' do
|
407
|
+
it 'returns MiniExiftool object' do
|
408
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
409
|
+
expect(object_file.exif).not_to be_nil
|
410
|
+
expect(object_file.exif.class).to eq MiniExiftool
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'raises MiniExiftool::Error with file path if exiftool raises one' do
|
414
|
+
object_file = described_class.new('spec/test_data/empty.txt')
|
415
|
+
expect { object_file.exif }.to raise_error(MiniExiftool::Error,
|
416
|
+
"error initializing MiniExiftool for #{object_file.path}")
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
describe '#extension_mimetype' do
|
421
|
+
# mime-types gem, based on a file extension lookup
|
422
|
+
context 'with .obj file' do
|
423
|
+
it 'application/x-tgif' do
|
424
|
+
object_file = described_class.new(TEST_OBJ_FILE)
|
425
|
+
expect(object_file.send(:extension_mimetype)).to eq('application/x-tgif')
|
426
|
+
end
|
427
|
+
end
|
428
|
+
|
429
|
+
context 'with .tif file' do
|
430
|
+
it 'image/tiff' do
|
431
|
+
object_file = described_class.new(TEST_TIF_INPUT_FILE)
|
432
|
+
expect(object_file.send(:extension_mimetype)).to eq('image/tiff')
|
433
|
+
end
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
describe '#exif_mimetype' do
|
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(:exif_mimetype)).to eq('image/tiff')
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
context 'when .json file' do
|
446
|
+
it 'nil' do
|
447
|
+
object_file = described_class.new(TEST_JSON_FILE)
|
448
|
+
expect(object_file.send(:exif_mimetype)).to be_nil
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,60 +4,26 @@ require 'simplecov'
|
|
4
4
|
SimpleCov.start
|
5
5
|
|
6
6
|
require File.expand_path("#{File.dirname(__FILE__)}/../config/boot")
|
7
|
-
require 'byebug'
|
7
|
+
require 'pry-byebug'
|
8
8
|
|
9
9
|
RSpec.configure do |config|
|
10
10
|
config.order = 'random'
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
TEST_INPUT_DIR = File.join(
|
15
|
-
TEST_OUTPUT_DIR = File.join(TEST_DATA_DIR, 'output')
|
13
|
+
PATH_TO_GEM = File.expand_path("#{File.dirname(__FILE__)}/..")
|
14
|
+
TEST_INPUT_DIR = File.join(PATH_TO_GEM, 'spec', 'test_data', 'input')
|
16
15
|
TEST_TIF_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.tif')
|
17
|
-
TEST_TIF_INPUT_FILE2 = File.join(TEST_INPUT_DIR, 'test2.tif')
|
18
|
-
TEST_JPEG_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jpg')
|
19
16
|
TEST_JP2_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.jp2')
|
20
|
-
TEST_JP2_INPUT_FILE2 = File.join(TEST_INPUT_DIR, 'test2.jp2')
|
21
|
-
TEST_SVG_INPUT_FILE = File.join(TEST_INPUT_DIR, 'test.svg')
|
22
|
-
TEST_JP2_OUTPUT_FILE = File.join(TEST_OUTPUT_DIR, 'test.jp2')
|
23
|
-
TEST_PDF_FILE = File.join(TEST_INPUT_DIR, 'test.pdf')
|
24
|
-
|
25
|
-
TEST_DPG_TIF = File.join(TEST_INPUT_DIR, 'oo000oo0001', '00', 'oo000oo0001_00_001.tif')
|
26
|
-
TEST_DPG_TIF2 = File.join(TEST_INPUT_DIR, 'oo000oo0001', '00', 'oo000oo0001_00_002.tif')
|
27
|
-
TEST_DPG_JP = File.join(TEST_INPUT_DIR, 'oo000oo0001', '05', 'oo000oo0001_05_001.jp2')
|
28
|
-
TEST_DPG_JP2 = File.join(TEST_INPUT_DIR, 'oo000oo0001', '05', 'oo000oo0001_05_002.jp2')
|
29
|
-
TEST_DPG_PDF = File.join(TEST_INPUT_DIR, 'oo000oo0001', '15', 'oo000oo0001_15_001.pdf')
|
30
|
-
TEST_DPG_PDF2 = File.join(TEST_INPUT_DIR, 'oo000oo0001', '15', 'oo000oo0001_15_002.pdf')
|
31
|
-
TEST_DPG_SPECIAL_PDF1 = File.join(TEST_INPUT_DIR, 'oo000oo0001', 'oo000oo0001_book.pdf')
|
32
|
-
TEST_DPG_SPECIAL_PDF2 = File.join(TEST_INPUT_DIR, 'oo000oo0001', '31', 'oo000oo0001_31_001.pdf')
|
33
|
-
TEST_DPG_SPECIAL_TIF = File.join(TEST_INPUT_DIR, 'oo000oo0001', '50', 'oo000oo0001_50_001.tif')
|
34
17
|
|
35
18
|
TEST_TIFF_NO_COLOR_FILE = File.join(TEST_INPUT_DIR, 'test_no_color_profile.tif')
|
36
19
|
|
37
20
|
TEST_RES1_TIF1 = File.join(TEST_INPUT_DIR, 'res1_image1.tif')
|
38
|
-
TEST_RES1_JP1 = File.join(TEST_INPUT_DIR, 'res1_image1.jp2')
|
39
|
-
TEST_RES1_TIF2 = File.join(TEST_INPUT_DIR, 'res1_image2.tif')
|
40
|
-
TEST_RES1_JP2 = File.join(TEST_INPUT_DIR, 'res1_image2.jp2')
|
41
|
-
TEST_RES1_TEI = File.join(TEST_INPUT_DIR, 'res1_teifile.txt')
|
42
21
|
TEST_RES1_TEXT = File.join(TEST_INPUT_DIR, 'res1_textfile.txt')
|
43
22
|
TEST_RES1_PDF = File.join(TEST_INPUT_DIR, 'res1_transcript.pdf')
|
44
23
|
|
45
|
-
TEST_RES2_TIF1 = File.join(TEST_INPUT_DIR, 'res2_image1.tif')
|
46
|
-
TEST_RES2_JP1 = File.join(TEST_INPUT_DIR, 'res2_image1.jp2')
|
47
|
-
TEST_RES2_TIF2 = File.join(TEST_INPUT_DIR, 'res2_image2.tif')
|
48
|
-
TEST_RES2_JP2 = File.join(TEST_INPUT_DIR, 'res2_image2.jp2')
|
49
|
-
TEST_RES2_TEI = File.join(TEST_INPUT_DIR, 'res2_teifile.txt')
|
50
|
-
TEST_RES2_TEXT = File.join(TEST_INPUT_DIR, 'res2_textfile.txt')
|
51
|
-
|
52
|
-
TEST_RES3_TIF1 = File.join(TEST_INPUT_DIR, 'res3_image1.tif')
|
53
|
-
TEST_RES3_JP1 = File.join(TEST_INPUT_DIR, 'res3_image1.jp2')
|
54
|
-
TEST_RES3_TEI = File.join(TEST_INPUT_DIR, 'res3_teifile.txt')
|
55
|
-
|
56
24
|
TEST_FILE_NO_EXIF = File.join(TEST_INPUT_DIR, 'file_with_no_exif.xml')
|
57
25
|
|
58
26
|
TEST_JSON_FILE = File.join(TEST_INPUT_DIR, 'test.json')
|
59
27
|
|
60
28
|
TEST_OBJ_FILE = File.join(TEST_INPUT_DIR, 'someobject.obj')
|
61
29
|
TEST_PLY_FILE = File.join(TEST_INPUT_DIR, 'someobject.ply')
|
62
|
-
|
63
|
-
TEST_DRUID = 'nx288wh8889'
|