druid-tools 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,6 @@
1
- #$LOAD_PATH.unshift(File.expand_path('../../lib',__FILE__))
1
+ # frozen_string_literal: true
2
+
3
+ # $LOAD_PATH.unshift(File.expand_path('../../lib',__FILE__))
2
4
 
3
5
  require 'coveralls'
4
6
  Coveralls.wear_merged! # because we run travis on multiple rubies
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: druid-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klein
@@ -9,78 +9,78 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-19 00:00:00.000000000 Z
12
+ date: 2019-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rake
15
+ name: coveralls
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 10.1.0
20
+ version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 10.1.0
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rspec
29
+ name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '3.0'
34
+ version: 10.1.0
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '3.0'
41
+ version: 10.1.0
42
42
  - !ruby/object:Gem::Dependency
43
- name: coveralls
43
+ name: rspec
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: '3.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '3.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rubocop
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 0.50.0
62
+ version: 0.70.0
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 0.50.0
69
+ version: 0.70.0
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rubocop-rspec
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: 1.18.0
76
+ version: 1.33.0
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: 1.18.0
83
+ version: 1.33.0
84
84
  description: Tools to manipulate DRUID trees and content directories
85
85
  email:
86
86
  - mbklein@stanford.edu
@@ -105,8 +105,8 @@ files:
105
105
  - lib/druid_tools/druid.rb
106
106
  - lib/druid_tools/exceptions.rb
107
107
  - lib/druid_tools/version.rb
108
- - spec/access_druid_spec.rb
109
- - spec/druid_spec.rb
108
+ - spec/druid_tools/purl_druid_spec.rb
109
+ - spec/druid_tools_spec.rb
110
110
  - spec/spec_helper.rb
111
111
  homepage: http://github.com/sul-dlss/druid-tools
112
112
  licenses:
@@ -129,11 +129,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  requirements: []
131
131
  rubyforge_project:
132
- rubygems_version: 2.6.13
132
+ rubygems_version: 2.7.6
133
133
  signing_key:
134
134
  specification_version: 4
135
135
  summary: Tools to manipulate DRUID trees and content directories
136
136
  test_files:
137
- - spec/access_druid_spec.rb
138
- - spec/druid_spec.rb
137
+ - spec/druid_tools/purl_druid_spec.rb
138
+ - spec/druid_tools_spec.rb
139
139
  - spec/spec_helper.rb
@@ -1,28 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe DruidTools::PurlDruid do
4
-
5
- let(:purl_root) { Dir.mktmpdir }
6
-
7
- let(:druid) { DruidTools::PurlDruid.new 'druid:cd456ef7890', purl_root }
8
-
9
- after(:each) do
10
- FileUtils.remove_entry purl_root
11
- end
12
-
13
- it "overrides Druid#tree so that the leaf is not Druid#id" do
14
- expect(druid.tree).to eq(['cd','456','ef','7890'])
15
- end
16
-
17
- describe "#content_dir" do
18
-
19
- it "creates content directories at leaf of the druid tree" do
20
- expect(druid.content_dir).to match(/ef\/7890$/)
21
- end
22
-
23
- it "does not create a 'content' subdirectory" do
24
- expect(druid.content_dir).to_not match(/content$/)
25
- end
26
- end
27
-
28
- end
@@ -1,470 +0,0 @@
1
- describe DruidTools::Druid do
2
- let(:fixture_dir) { File.expand_path("../fixtures", __FILE__) }
3
- let(:druid_str) { 'druid:cd456ef7890' }
4
- let(:tree_1) { File.join(fixture_dir, 'cd/456/ef/7890/cd456ef7890') }
5
- let(:strictly_valid_druid_str) { 'druid:cd456gh1234' }
6
- let(:tree_2) { File.join(fixture_dir, 'cd/456/gh/1234/cd456gh1234') }
7
-
8
- after(:each) do
9
- FileUtils.rm_rf(File.join(fixture_dir, 'cd'))
10
- end
11
-
12
- context '.valid?' do
13
- # also tests .pattern
14
- it "correctly validates druid strings" do
15
- tests = [
16
- # Expected Input druid
17
- [true, 'druid:aa000bb0001'],
18
- [true, 'aa000bb0001'],
19
- [false, 'Aa000bb0001'],
20
- [false, "xxx\naa000bb0001"],
21
- [false, 'aaa000bb0001'],
22
- [false, 'druidX:aa000bb0001'],
23
- [false, ':aa000bb0001'],
24
- [true, 'aa123bb1234'],
25
- [false, 'aa12bb1234'],
26
- [false, 'aa1234bb1234'],
27
- [false, 'aa123bb123'],
28
- [false, 'aa123bb12345'],
29
- [false, 'a123bb1234'],
30
- [false, 'aaa123bb1234'],
31
- [false, 'aa123b1234'],
32
- [false, 'aa123bbb1234'],
33
- [false, 'druid:az918AZ9381'.upcase],
34
- [true, 'druid:az918AZ9381'.downcase],
35
- [true, 'druid:zz943vx1492']
36
- ]
37
- tests.each do |exp, dru|
38
- expect(DruidTools::Druid.valid?(dru)).to eq(exp)
39
- expect(DruidTools::Druid.valid?(dru, false)).to eq(exp)
40
- end
41
- end
42
- context 'strict' do
43
- it "correctly validates druid strings" do
44
- tests = [
45
- # Expected Input druid
46
- [false, 'aa000aa0000'],
47
- [false, 'ee000ee0000'],
48
- [false, 'ii000ii0000'],
49
- [false, 'oo000oo0000'],
50
- [false, 'uu000uu0000'],
51
- [false, 'll000ll0000'],
52
- [false, 'aa000bb0001'],
53
- [true, 'druid:dd000bb0001'],
54
- [false, 'druid:aa000bb0001'],
55
- [true, 'dd000bb0001'],
56
- [false, 'Dd000bb0001'],
57
- [false, "xxx\ndd000bb0001"],
58
- [false, 'ddd000bb0001'],
59
- [false, 'druidX:dd000bb0001'],
60
- [false, ':dd000bb0001'],
61
- [true, 'cc123bb1234'],
62
- [false, 'aa123bb1234'],
63
- [false, 'dd12bb1234'],
64
- [false, 'dd1234bb1234'],
65
- [false, 'dd123bb123'],
66
- [false, 'dd123bb12345'],
67
- [false, 'd123bb1234'],
68
- [false, 'ddd123bb1234'],
69
- [false, 'dd123b1234'],
70
- [false, 'dd123bbb1234'],
71
- [false, 'druid:bz918BZ9381'.upcase],
72
- [true, 'druid:bz918BZ9381'.downcase],
73
- [false, 'druid:az918AZ9381'.downcase],
74
- [true, 'druid:zz943vx1492']
75
- ]
76
- tests.each do |exp, dru|
77
- expect(DruidTools::Druid.valid?(dru, true)).to eq(exp)
78
- end
79
- end
80
- end
81
- end
82
-
83
- it "#druid provides the full druid including the prefix" do
84
- expect(DruidTools::Druid.new('druid:cd456ef7890', fixture_dir).druid).to eq('druid:cd456ef7890')
85
- expect(DruidTools::Druid.new('cd456ef7890', fixture_dir).druid).to eq('druid:cd456ef7890')
86
- end
87
-
88
- it "#id extracts the ID from the stem" do
89
- expect(DruidTools::Druid.new('druid:cd456ef7890', fixture_dir).id).to eq('cd456ef7890')
90
- expect(DruidTools::Druid.new('cd456ef7890', fixture_dir).id).to eq('cd456ef7890')
91
- end
92
-
93
- context '#new' do
94
- it "raises exception if the druid is invalid" do
95
- expect { DruidTools::Druid.new('nondruid:cd456ef7890', fixture_dir) }.to raise_error(ArgumentError)
96
- expect { DruidTools::Druid.new('druid:cd4567ef890', fixture_dir) }.to raise_error(ArgumentError)
97
- end
98
- it "takes strict argument" do
99
- DruidTools::Druid.new(strictly_valid_druid_str, fixture_dir, true)
100
- expect { DruidTools::Druid.new(druid_str, fixture_dir, true) }.to raise_error(ArgumentError)
101
- end
102
- end
103
-
104
- it "#tree builds a druid tree from a druid" do
105
- druid = DruidTools::Druid.new(druid_str, fixture_dir)
106
- expect(druid.tree).to eq(['cd', '456', 'ef', '7890', 'cd456ef7890'])
107
- expect(druid.path).to eq(tree_1)
108
- end
109
-
110
- it "#mkdir, #rmdir create and destroy druid directories" do
111
- expect(File.exists?(tree_1)).to eq false
112
- expect(File.exists?(tree_2)).to eq false
113
-
114
- druid_1 = DruidTools::Druid.new(druid_str, fixture_dir)
115
- druid_2 = DruidTools::Druid.new(strictly_valid_druid_str, fixture_dir)
116
-
117
- druid_1.mkdir
118
- expect(File.exists?(tree_1)).to eq true
119
- expect(File.exists?(tree_2)).to eq false
120
-
121
- druid_2.mkdir
122
- expect(File.exists?(tree_1)).to eq true
123
- expect(File.exists?(tree_2)).to eq true
124
-
125
- druid_2.rmdir
126
- expect(File.exists?(tree_1)).to eq true
127
- expect(File.exists?(tree_2)).to eq false
128
-
129
- druid_1.rmdir
130
- expect(File.exists?(tree_1)).to eq false
131
- expect(File.exists?(tree_2)).to eq false
132
- expect(File.exists?(File.join(fixture_dir, 'cd'))).to eq false
133
- end
134
-
135
- describe "alternate prefixes" do
136
- before :all do
137
- DruidTools::Druid.prefix = 'sulair'
138
- end
139
-
140
- after :all do
141
- DruidTools::Druid.prefix = 'druid'
142
- end
143
-
144
- it "handles alternate prefixes" do
145
- expect { DruidTools::Druid.new('druid:cd456ef7890', fixture_dir) }.to raise_error(ArgumentError)
146
- expect(DruidTools::Druid.new('sulair:cd456ef7890', fixture_dir).id).to eq('cd456ef7890')
147
- expect(DruidTools::Druid.new('cd456ef7890', fixture_dir).druid).to eq('sulair:cd456ef7890')
148
- end
149
- end
150
-
151
- describe "content directories" do
152
- it "knows where its content goes" do
153
- druid = DruidTools::Druid.new(druid_str, fixture_dir)
154
- expect(druid.content_dir(false)).to eq(File.join(tree_1, 'content'))
155
- expect(druid.metadata_dir(false)).to eq(File.join(tree_1, 'metadata'))
156
- expect(druid.temp_dir(false)).to eq(File.join(tree_1, 'temp'))
157
-
158
- expect(File.exists?(File.join(tree_1, 'content'))).to eq false
159
- expect(File.exists?(File.join(tree_1, 'metadata'))).to eq false
160
- expect(File.exists?(File.join(tree_1, 'temp'))).to eq false
161
- end
162
-
163
- it "creates its content directories on the fly" do
164
- druid = DruidTools::Druid.new(druid_str, fixture_dir)
165
- expect(druid.content_dir).to eq(File.join(tree_1, 'content'))
166
- expect(druid.metadata_dir).to eq(File.join(tree_1, 'metadata'))
167
- expect(druid.temp_dir).to eq(File.join(tree_1, 'temp'))
168
-
169
- expect(File.exists?(File.join(tree_1, 'content'))).to eq true
170
- expect(File.exists?(File.join(tree_1, 'metadata'))).to eq true
171
- expect(File.exists?(File.join(tree_1, 'temp'))).to eq true
172
- end
173
-
174
- it "matches glob" do
175
- druid = DruidTools::Druid.new(druid_str, fixture_dir)
176
- druid.mkdir
177
- expect(Dir.glob(File.join(File.dirname(druid.path), DruidTools::Druid::glob)).size).to eq(1)
178
- end
179
- it "matches strict_glob" do
180
- druid = DruidTools::Druid.new(druid_str, fixture_dir)
181
- druid.mkdir
182
- expect(Dir.glob(File.join(File.dirname(druid.path), DruidTools::Druid::strict_glob)).size).to eq(0)
183
- druid = DruidTools::Druid.new(strictly_valid_druid_str, fixture_dir)
184
- druid.mkdir
185
- expect(Dir.glob(File.join(File.dirname(druid.path), DruidTools::Druid::strict_glob)).size).to eq(1)
186
- end
187
- end
188
-
189
- describe "content discovery" do
190
- let(:druid) { DruidTools::Druid.new(druid_str, fixture_dir) }
191
- let(:filelist) { %w(1 2 3 4).collect { |num| "someFile#{num}" } }
192
-
193
- it "finds content in content directories" do
194
- location = druid.content_dir
195
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
196
- expect(druid.find_content('someContent')).to eq(File.join(location, 'someContent'))
197
- end
198
-
199
- it "finds content in the root directory" do
200
- location = druid.path(nil, true)
201
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
202
- expect(druid.find_content('someContent')).to eq(File.join(location, 'someContent'))
203
- end
204
-
205
- it "finds content in the leaf directory" do
206
- location = File.expand_path('..', druid.path(nil, true))
207
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
208
- expect(druid.find_content('someContent')).to eq(File.join(location, 'someContent'))
209
- end
210
-
211
- it "does not find content in the wrong content directory" do
212
- location = druid.metadata_dir
213
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
214
- expect(druid.find_content('someContent')).to be_nil
215
- end
216
-
217
- it "does not find content in a higher-up directory" do
218
- location = File.expand_path('../..', druid.path(nil, true))
219
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
220
- expect(druid.find_content('someContent')).to be_nil
221
- end
222
-
223
- it "finds a filelist in the content directory" do
224
- location = Pathname(druid.content_dir)
225
- filelist.each do |filename|
226
- location.join(filename).open('w') { |f| f.write "This is #{filename}" }
227
- end
228
- expect(druid.find_filelist_parent('content', filelist)).to eq(location)
229
- end
230
-
231
- it "finds a filelist in the root directory" do
232
- location = Pathname(druid.path(nil, true))
233
- filelist.each do |filename|
234
- location.join(filename).open('w') { |f| f.write "This is #{filename}" }
235
- end
236
- expect(druid.find_filelist_parent('content', filelist)).to eq(location)
237
- end
238
-
239
- it "finds a filelist in the leaf directory" do
240
- location = Pathname(File.expand_path('..', druid.path(nil, true)))
241
- filelist.each do |filename|
242
- location.join(filename).open('w') { |f| f.write "This is #{filename}" }
243
- end
244
- expect(druid.find_filelist_parent('content', filelist)).to eq(location)
245
- end
246
-
247
- it "raises an exception if the first file in the filelist is not found" do
248
- location = Pathname(druid.content_dir)
249
- expect{druid.find_filelist_parent('content', filelist)}.to raise_exception(/content dir not found for 'someFile1' when searching/)
250
- end
251
-
252
- it "raises an exception if any other file in the filelist is not found" do
253
- location = Pathname(druid.content_dir)
254
- location.join(filelist.first).open('w') { |f| f.write "This is #{filelist.first}" }
255
- expect{druid.find_filelist_parent('content', filelist)}.to raise_exception(/File 'someFile2' not found/)
256
- end
257
- end
258
-
259
- describe "#mkdir error handling" do
260
- it "raises SameContentExistsError if the directory already exists" do
261
- druid_obj = DruidTools::Druid.new(strictly_valid_druid_str, fixture_dir)
262
- druid_obj.mkdir
263
- expect { druid_obj.mkdir }.to raise_error(DruidTools::SameContentExistsError)
264
- end
265
-
266
- it "raises DifferentContentExistsError if a link already exists in the workspace for this druid" do
267
- source_dir = '/tmp/content_dir'
268
- FileUtils.mkdir_p(source_dir)
269
- dr = DruidTools::Druid.new(strictly_valid_druid_str, fixture_dir)
270
- dr.mkdir_with_final_link(source_dir)
271
- expect { dr.mkdir }.to raise_error(DruidTools::DifferentContentExistsError)
272
- end
273
- end
274
-
275
- describe "#mkdir_with_final_link" do
276
- let(:source_dir) { '/tmp/content_dir' }
277
- let(:druid_obj){ DruidTools::Druid.new(strictly_valid_druid_str, fixture_dir) }
278
-
279
- before(:each) do
280
- FileUtils.mkdir_p(source_dir)
281
- end
282
-
283
- it "creates a druid tree in the workspace with the final directory being a link to the passed in source" do
284
- druid_obj.mkdir_with_final_link(source_dir)
285
- expect(File).to be_symlink(druid_obj.path)
286
- expect(File.readlink(tree_2)).to eq(source_dir)
287
- end
288
-
289
- it "does not error out if the link to source already exists" do
290
- druid_obj.mkdir_with_final_link(source_dir)
291
- expect(File).to be_symlink(druid_obj.path)
292
- expect(File.readlink(tree_2)).to eq(source_dir)
293
- end
294
-
295
- it "raises DifferentContentExistsError if a directory already exists in the workspace for this druid" do
296
- druid_obj.mkdir(fixture_dir)
297
- expect { druid_obj.mkdir_with_final_link(source_dir) }.to raise_error(DruidTools::DifferentContentExistsError)
298
- end
299
- end
300
-
301
- describe "#prune!" do
302
- let(:workspace) { Dir.mktmpdir }
303
- let(:dr1) { DruidTools::Druid.new(druid_str, workspace) }
304
- let(:dr2) { DruidTools::Druid.new(strictly_valid_druid_str, workspace) }
305
- let(:pathname1) { dr1.pathname }
306
-
307
- after(:each) do
308
- FileUtils.remove_entry workspace
309
- end
310
-
311
- it "throws error on misconfig when base dir cannot be created" do
312
- dir = '/some/dir/that/does/not/exist' # we don't have permissions to create
313
- dr0 = DruidTools::Druid.new(druid_str, dir)
314
- expect {dr0.prune!}.to raise_error(StandardError)
315
- expect(File).to_not exist(dir)
316
- end
317
-
318
- it "does not throw error when base can be created" do
319
- subdir = File.join(Dir.mktmpdir, 'some', 'nonexistant', 'subdir') # but this one *can* be created
320
- dr2 = DruidTools::Druid.new(strictly_valid_druid_str, subdir)
321
- expect {dr2.prune!}.not_to raise_error()
322
- expect(File).to exist(subdir)
323
- end
324
-
325
- context "shared ancestor" do
326
-
327
- before(:each) do
328
- #Nil the create records for this context because we're in a known read only one
329
- dr1.mkdir
330
- dr2.mkdir
331
- dr1.prune!
332
- end
333
-
334
- it "deletes the outermost directory" do
335
- expect(File).to_not exist(dr1.path)
336
- end
337
-
338
- it "deletes empty ancestor directories" do
339
- expect(File).to_not exist(pathname1.parent)
340
- expect(File).to_not exist(pathname1.parent.parent)
341
- end
342
-
343
- it "stops at ancestor directories that have children" do
344
- # 'cd/456' should still exist because of druid2
345
- shared_ancestor = pathname1.parent.parent.parent
346
- expect(shared_ancestor.to_s).to match(/cd\/456$/)
347
- expect(File).to exist(shared_ancestor)
348
- end
349
- end
350
-
351
- it "removes all directories up to the base path when there are no common ancestors" do
352
- #Make sure a delete record is not present
353
- expect(dr1.deletes_record_exists?).to be_falsey
354
-
355
- #Nil the create records for this test
356
- dr1.mkdir
357
- dr1.prune!
358
- expect(File).to_not exist(File.join(workspace, 'cd'))
359
- expect(File).to exist(workspace)
360
-
361
- #Make sure a delete record was created
362
- expect(dr1.deletes_dir_exists?).to be_truthy
363
- expect(dr1.deletes_record_exists?).to be_truthy
364
- end
365
-
366
- it "removes directories with symlinks" do
367
- #Make sure a delete record is not present
368
- expect(dr2.deletes_record_exists?).to be_falsey
369
-
370
- #Nil the create records for this test
371
- source_dir = File.join workspace, 'src_dir'
372
- FileUtils.mkdir_p(source_dir)
373
- dr2.mkdir_with_final_link(source_dir)
374
- dr2.prune!
375
- expect(File).to_not exist(dr2.path)
376
- expect(File).to_not exist(File.join(workspace, 'cd'))
377
-
378
- #Make sure a delete record was created
379
- expect(dr2.deletes_dir_exists?).to be_truthy
380
- expect(dr2.deletes_record_exists?).to be_truthy
381
- end
382
-
383
- describe "logging deleted druids" do
384
-
385
- #Purge any paths or delete records created in the test
386
- after :each do
387
- #Remove the .deletes dir to clean up
388
- dr2.deletes_delete_record if dr2.deletes_record_exists?
389
- FileUtils.rm_rf dr2.deletes_dir_pathname
390
- end
391
-
392
- it "returns the path to the .deletes directory as a Pathname" do
393
- expect(dr2.deletes_dir_pathname.class).to eq(Pathname)
394
- end
395
-
396
- it "returns the path to the delete record for a druid as a Pathname" do
397
- expect(dr2.deletes_record_pathname.class).to eq(Pathname)
398
- end
399
-
400
- it "returns the path to the delete record for a druid as top_level/.deletes/druid" do
401
- expect(dr2.deletes_record_pathname.to_s).to eq("#{dr2.base}/.deletes/#{dr2.id}")
402
- end
403
-
404
- it "returns false when the .deletes dir is not present on the file system" do
405
- expect(dr2.deletes_dir_exists?).to be_falsey
406
- end
407
-
408
- it "creates the .deletes dir and detect it exists" do
409
-
410
- #Clean the .deletes dir if present
411
- FileUtils.rm_rf dr2.deletes_dir_pathname
412
-
413
- #Test for exists? and create
414
- expect(dr2.deletes_dir_exists?).to be_falsey
415
- dr2.create_deletes_dir
416
- expect(dr2.deletes_dir_exists?).to be_truthy
417
- end
418
-
419
- it "returns false when the .deletes dir does not have a deleted record for a druid" do
420
- expect(dr2.deletes_record_exists?).to be_falsey
421
- end
422
-
423
- it "creates a deleted record with a parent directory that has no .deletes directory and no deleted for the file and successfully create a delete record there" do
424
- #Expect there not to be a .deletes dir or file (the file expectation is redundant I know)
425
- expect(dr2.deletes_dir_exists?).to be_falsey
426
- expect(dr2.deletes_record_exists?).to be_falsey
427
-
428
- #Create the delete record
429
- dr2.creates_delete_record
430
-
431
- #Check to ensure items were created
432
- expect(dr2.deletes_dir_exists?).to be_truthy
433
- expect(dr2.deletes_record_exists?).to be_truthy
434
- end
435
-
436
- it "creates a delete record with a parent directory that has a .deletes directory that does not contain a delete record for this druid" do
437
- #Expect there not to be a .deletes dir or file (the file expectation is redundant I know)
438
- expect(dr2.deletes_dir_exists?).to be_falsey
439
- expect(dr2.deletes_record_exists?).to be_falsey
440
-
441
- #Creates the deletes dir and check
442
- dr2.create_deletes_dir
443
- expect(dr2.deletes_dir_exists?).to be_truthy
444
- expect(dr2.deletes_record_exists?).to be_falsey
445
-
446
- #Create the delete record
447
- dr2.creates_delete_record
448
-
449
- #Check to ensure items were created
450
- expect(dr2.deletes_dir_exists?).to be_truthy
451
- expect(dr2.deletes_record_exists?).to be_truthy
452
- end
453
-
454
- it "creates a delete record with a parent directory that does not have a .deletes directory and contains an older delete record" do
455
- #Expect there not to be a .deletes dir or file (the file expectation is redundant I know)
456
- expect(dr2.deletes_dir_exists?).to be_falsey
457
- expect(dr2.deletes_record_exists?).to be_falsey
458
-
459
- dr2.creates_delete_record
460
- time = Time.now
461
- expect(File.mtime(dr2.deletes_record_pathname)).to be <= time
462
- sleep(1) #force a one second pause in case the machine is fast, since mtime only goes down to the second
463
-
464
- dr2.creates_delete_record
465
- #Should have a new newer deleted record
466
- expect(File.mtime(dr2.deletes_record_pathname)).to be > time
467
- end
468
- end
469
- end
470
- end