druid-tools 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YWYwNmM0OTExYjMwZDEyZTI4OTlmMGIzMGE5NzQ2NWY0NTlmNGVlOQ==
5
- data.tar.gz: !binary |-
6
- MDllNDUwYWUzMzJiZDUzZDUxZTA3NmQyYjFkMDQ1Y2FkMDQ3OWFhNg==
2
+ SHA1:
3
+ metadata.gz: ff667823f90ed97f46171b13552720e11baf161b
4
+ data.tar.gz: e49db2f65f8a5734d67d7619d42477f56361cc9b
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YWQ4NzY4ODNiYWI3NjZmZTQ0MDE3NDQzYTE5OWNiMjJhZTk3N2Y0ZTlhM2U5
10
- ZDI3NDc2NTU4NDNlOTBiMWRmOWFiNjM5NDAzNzBlOWY3NGU5MDI5NTU3ZmJk
11
- NTgxMThjYTlmODU0NTJhYTBhNDYzZDk5NTg4ODU2NmNlNTZlZWU=
12
- data.tar.gz: !binary |-
13
- N2E4ODdiZGEwMzI1YTU5ODE5ZDA1MjIxMmVjNmNhODZmZmQ0YTE1ZGY4Yzhl
14
- ODYwOTY3NWEwOTU1ZWE4NDcwYzdhODcwYTI1YzliMmRkZTNkNDFjMjE1ZmI2
15
- YzAwYTdlZjJkNTA3NDQxM2QyMzRmZWJkNGEyYjUzNTRjNDZhNzA=
6
+ metadata.gz: c95447c9d7b356c96894ea5de798d4292786e8fa2a9c86d696cf3cc87e764ec29c3e97b4ff0aec8007a528ebe6c9d0fefba825bcd63c4f7508c104e74e8b9a2a
7
+ data.tar.gz: 222ec27e234269a5606092d3889dbf40b68f22bc6a37e3b5e7791e9a8cfd3255addf873fdfe7ada1656be71e6e0203b03aa0b5e2cd9eb235ddf78112a44fe6c1
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,8 @@
1
+ notifications:
2
+ email: false
3
+
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.2
8
+
data/README.md CHANGED
@@ -6,85 +6,99 @@ Tools to manipulate DRUID trees and content directories
6
6
 
7
7
  ### Get attributes and paths
8
8
 
9
- d = DruidTools::Druid.new('druid:ab123cd4567', '/dor/workspace')
10
- d.druid
11
- => "druid:ab123cd4567"
12
- d.id
13
- => "ab123cd4567"
14
- d.path
15
- => "/dor/workspace/ab/123/cd/4567/ab123cd4567"
16
- d.content_dir
17
- => "/dor/workspace/ab/123/cd/4567/ab123cd4567/content"
18
- d.path('content/my_file.jpg')
19
- => "/dor/workspace/ab/123/cd/4567/ab123cd4567/content/my_file.jpg"
9
+ ```ruby
10
+ d = DruidTools::Druid.new('druid:ab123cd4567', '/dor/workspace')
11
+ d.druid
12
+ => "druid:ab123cd4567"
13
+ d.id
14
+ => "ab123cd4567"
15
+ d.path
16
+ => "/dor/workspace/ab/123/cd/4567/ab123cd4567"
17
+ d.content_dir
18
+ => "/dor/workspace/ab/123/cd/4567/ab123cd4567/content"
19
+ d.path('content/my_file.jpg')
20
+ => "/dor/workspace/ab/123/cd/4567/ab123cd4567/content/my_file.jpg"
21
+ ```
20
22
 
21
23
  ### Check whether a druid is valid
22
24
 
23
- d = DruidTools::Druid.valid?('druid:ab123cd4567')
24
- => true
25
- d = DruidTools::Druid.valid?('blah')
26
- => false
25
+ ```ruby
26
+ d = DruidTools::Druid.valid?('druid:ab123cd4567')
27
+ => true
28
+ d = DruidTools::Druid.valid?('blah')
29
+ => false
30
+ ```
27
31
 
28
32
  ### Manipulate directories and symlinks
29
33
 
30
- # Make the druid tree
31
- d.mkdir
32
- # Make a directory within the druid triee
33
- d.mkdir('temp')
34
- # Remove a druid tree, but only up to the last shared branch directory
35
- d.rmdir
36
- # Link content from another source into a druid tree
37
- d.mkdir_with_final_link('/some/other/content/location')
34
+ ```ruby
35
+ # Make the druid tree
36
+ d.mkdir
37
+ # Make a directory within the druid triee
38
+ d.mkdir('temp')
39
+ # Remove a druid tree, but only up to the last shared branch directory
40
+ d.rmdir
41
+ # Link content from another source into a druid tree
42
+ d.mkdir_with_final_link('/some/other/content/location')
43
+ ```
38
44
 
39
45
  ### Content-specific methods create the relevant directories if they don't exist
40
46
 
41
47
  Pass `false` as a parameter to prevent directory creation, or `true` (default) to create directories.
42
48
 
43
- d.content_dir(false)
44
- => "/dor/workspace/ab/123/cd/4567/ab123cd4567/content"
45
- File.directory?(d.content_dir(false))
46
- => false
47
- File.directory?(d.content_dir)
48
- => true
49
- d.metadata_dir(false)
50
- => "/dor/workspace/ab/123/cd/4567/ab123cd4567/metadata"
51
- d.temp_dir(false)
52
- => "/dor/workspace/ab/123/cd/4567/ab123cd4567/temp"
49
+ ```ruby
50
+ d.content_dir(false)
51
+ => "/dor/workspace/ab/123/cd/4567/ab123cd4567/content"
52
+ File.directory?(d.content_dir(false))
53
+ => false
54
+ File.directory?(d.content_dir)
55
+ => true
56
+ d.metadata_dir(false)
57
+ => "/dor/workspace/ab/123/cd/4567/ab123cd4567/metadata"
58
+ d.temp_dir(false)
59
+ => "/dor/workspace/ab/123/cd/4567/ab123cd4567/temp"
60
+ ```
53
61
 
54
62
  ### Locate existing content within the druid tree
55
63
 
56
- # In the correct directory
57
- d.find_metadata('contentMetadata.xml')
58
- => "/dor/workspace/ab/123/cd/4567/ab123cd4567/metadata/contentMetadata.xml"
64
+ ```ruby
65
+ # In the correct directory
66
+ d.find_metadata('contentMetadata.xml')
67
+ => "/dor/workspace/ab/123/cd/4567/ab123cd4567/metadata/contentMetadata.xml"
59
68
 
60
- # In other known previous locations, for backward compatibility
61
- d.find_metadata('contentMetadata.xml')
62
- => "/dor/workspace/ab/123/cd/4567/ab123cd4567/contentMetadata.xml"
69
+ # In other known previous locations, for backward compatibility
70
+ d.find_metadata('contentMetadata.xml')
71
+ => "/dor/workspace/ab/123/cd/4567/ab123cd4567/contentMetadata.xml"
63
72
 
64
- d.find_metadata('contentMetadata.xml')
65
- => "/dor/workspace/ab/123/cd/4567/contentMetadata.xml"
73
+ d.find_metadata('contentMetadata.xml')
74
+ => "/dor/workspace/ab/123/cd/4567/contentMetadata.xml"
66
75
 
67
- d.find_content('this/file/does/not/exist.jpg')
68
- => nil
76
+ d.find_content('this/file/does/not/exist.jpg')
77
+ => nil
78
+ ```
69
79
 
70
80
  ### Pruning: removes leaves of tree up to non-empty branches
71
81
 
72
- d1 = DruidTools::Druid.new 'druid:cd456ef7890', '/workspace'
73
- d1.mkdir
74
- d2 = DruidTools::Druid.new 'druid:cd456gh1234', '/workspace'
75
- d2.mkdir
82
+ ```ruby
83
+ d1 = DruidTools::Druid.new 'druid:cd456ef7890', '/workspace'
84
+ d1.mkdir
85
+ d2 = DruidTools::Druid.new 'druid:cd456gh1234', '/workspace'
86
+ d2.mkdir
76
87
 
77
- # /workspace/cd/456/gh/1234/cd456gh1234 pruned down to /workspace/cd/456
78
- # /workspace/cd/456/ef/7890/cd456ef7890 left intact
79
- d2.prune!
88
+ # /workspace/cd/456/gh/1234/cd456gh1234 pruned down to /workspace/cd/456
89
+ # /workspace/cd/456/ef/7890/cd456ef7890 left intact
90
+ d2.prune!
91
+ ```
80
92
 
81
93
  ### Stacks and Purl compatible Druid. All files at the leaf directories
82
94
 
83
- pd = DruidTools::PurlDruid.new 'druid:ab123cd4567', '/purl'
84
- pd.path
85
- => "/purl/ab/123/cd/4567"
86
- pd.content_dir
87
- => "/purl/ab/123/cd/4567"
95
+ ```ruby
96
+ pd = DruidTools::PurlDruid.new 'druid:ab123cd4567', '/purl'
97
+ pd.path
98
+ => "/purl/ab/123/cd/4567"
99
+ pd.content_dir
100
+ => "/purl/ab/123/cd/4567"
101
+ ```
88
102
 
89
103
  ### History
90
104
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -138,47 +138,47 @@ module DruidTools
138
138
  parent = this_path.parent
139
139
  parent.rmtree if parent.exist? && parent != base_pathname
140
140
  prune_ancestors parent.parent
141
- creates_delete_record
141
+ creates_delete_record
142
142
  end
143
-
144
- #This function checks for existance of a .deletes dir one level into the path (ex: stacks/.deletes or purl/.deletes).
143
+
144
+ #This function checks for existance of a .deletes dir one level into the path (ex: stacks/.deletes or purl/.deletes).
145
145
  #If the directory does not exist, it is created. If the directory exists, check to see if the current druid has an entry there, if it does delete it.
146
- #This is done because a file might be deleted, then republishing, then deleted we again, and we want to log the most recent delete.
146
+ #This is done because a file might be deleted, then republishing, then deleted we again, and we want to log the most recent delete.
147
147
  #
148
148
  #@raises [Errno::EACCES] If write priveleges are denied
149
149
  #
150
- #@return [void]
150
+ #@return [void]
151
151
  def prep_deletes_dir
152
- #Check for existences of deletes dir
152
+ #Check for existences of deletes dir
153
153
  create_deletes_dir if !deletes_dir_exists?
154
154
  #In theory we could return true after this step (if it fires), since if there was no deletes dir then the file can't be present in the dir
155
155
 
156
- #Check to see if this druid has been deleted before, meaning file currently exists
156
+ #Check to see if this druid has been deleted before, meaning file currently exists
157
157
  deletes_delete_record if deletes_record_exists?
158
158
  end
159
-
159
+
160
160
  #Provide the location for the .deletes directory in the tree
161
161
  #
162
162
  #@return [Pathname] the path to the directory, ex: "stacks/.deletes"
163
163
  def deletes_dir_pathname
164
164
  return Pathname(self.base.to_s + (File::SEPARATOR+@@deletes_directory_name))
165
165
  end
166
-
166
+
167
167
  def deletes_record_pathname
168
168
  return Pathname(deletes_dir_pathname.to_s + File::SEPARATOR + self.id)
169
169
  end
170
-
171
- #Using the deletes directory path supplied by deletes_dir_pathname, this function determines if this directory exists
170
+
171
+ #Using the deletes directory path supplied by deletes_dir_pathname, this function determines if this directory exists
172
172
  #
173
173
  #@return [Boolean] true if if exists, false if it does not
174
174
  def deletes_dir_exists?
175
- return File.directory?(deletes_dir_pathname)
175
+ return File.directory?(deletes_dir_pathname)
176
176
  end
177
-
177
+
178
178
  def deletes_record_exists?
179
179
  return File.exists?(deletes_dir_pathname.to_s + File::SEPARATOR + self.id)
180
180
  end
181
-
181
+
182
182
  #Creates the deletes dir using the path supplied by deletes_dir_pathname
183
183
  #
184
184
  #@raises [Errno::EACCES] If write priveleges are denied
@@ -187,7 +187,7 @@ module DruidTools
187
187
  def create_deletes_dir
188
188
  FileUtils::mkdir_p deletes_dir_pathname
189
189
  end
190
-
190
+
191
191
  #Deletes the delete record if it currently exists. This is done to change the filed created, not just last modified time, on the system
192
192
  #
193
193
  #@raises [Errno::EACCES] If write priveleges are denied
@@ -196,7 +196,7 @@ module DruidTools
196
196
  def deletes_delete_record
197
197
  FileUtils.rm(deletes_record_pathname) if deletes_record_exists? #thrown in to prevent an Errno::ENOENT if you call this on something without a delete record
198
198
  end
199
-
199
+
200
200
  #Creates an empty (pointer) file using the object's id in the .deletes dir
201
201
  #
202
202
  #@raises [Errno::EACCES] If write priveleges are denied
@@ -206,16 +206,15 @@ module DruidTools
206
206
  prep_deletes_dir
207
207
  FileUtils.touch(deletes_record_pathname)
208
208
  end
209
-
209
+
210
210
  # @param [Pathname] outermost_branch The branch at which pruning begins
211
211
  # @return [void] Ascend the druid tree and prune empty branches
212
212
  def prune_ancestors(outermost_branch)
213
- while outermost_branch.children.size == 0
213
+ while outermost_branch.exist? && outermost_branch.children.size == 0
214
214
  outermost_branch.rmdir
215
215
  outermost_branch = outermost_branch.parent
216
216
  break if outermost_branch == base_pathname
217
217
  end
218
- rescue
219
218
  end
220
219
 
221
220
  end
@@ -40,54 +40,54 @@ describe DruidTools::Druid do
40
40
  [true, 'druid:zz943vx1492']
41
41
  ]
42
42
  tests.each do |exp, dru|
43
- DruidTools::Druid.valid?(dru).should == exp
43
+ expect(DruidTools::Druid.valid?(dru)).to eq(exp)
44
44
  end
45
45
  end
46
46
 
47
47
  it "provides the full druid including the prefix" do
48
- DruidTools::Druid.new('druid:cd456ef7890',@fixture_dir).druid.should == 'druid:cd456ef7890'
49
- DruidTools::Druid.new('cd456ef7890',@fixture_dir).druid.should == 'druid:cd456ef7890'
48
+ expect(DruidTools::Druid.new('druid:cd456ef7890',@fixture_dir).druid).to eq('druid:cd456ef7890')
49
+ expect(DruidTools::Druid.new('cd456ef7890',@fixture_dir).druid).to eq('druid:cd456ef7890')
50
50
  end
51
51
 
52
52
  it "extracts the ID from the stem" do
53
- DruidTools::Druid.new('druid:cd456ef7890',@fixture_dir).id.should == 'cd456ef7890'
54
- DruidTools::Druid.new('cd456ef7890',@fixture_dir).id.should == 'cd456ef7890'
53
+ expect(DruidTools::Druid.new('druid:cd456ef7890',@fixture_dir).id).to eq('cd456ef7890')
54
+ expect(DruidTools::Druid.new('cd456ef7890',@fixture_dir).id).to eq('cd456ef7890')
55
55
  end
56
56
 
57
57
  it "raises an exception if the druid is invalid" do
58
- lambda { DruidTools::Druid.new('nondruid:cd456ef7890',@fixture_dir) }.should raise_error(ArgumentError)
59
- lambda { DruidTools::Druid.new('druid:cd4567ef890',@fixture_dir) }.should raise_error(ArgumentError)
58
+ expect { DruidTools::Druid.new('nondruid:cd456ef7890',@fixture_dir) }.to raise_error(ArgumentError)
59
+ expect { DruidTools::Druid.new('druid:cd4567ef890',@fixture_dir) }.to raise_error(ArgumentError)
60
60
  end
61
61
 
62
62
  it "builds a druid tree from a druid" do
63
63
  druid = DruidTools::Druid.new(@druid_1,@fixture_dir)
64
- druid.tree.should == ['cd','456','ef','7890','cd456ef7890']
65
- druid.path.should == @tree_1
64
+ expect(druid.tree).to eq(['cd','456','ef','7890','cd456ef7890'])
65
+ expect(druid.path).to eq(@tree_1)
66
66
  end
67
67
 
68
68
  it "creates and destroys druid directories" do
69
- File.exists?(@tree_1).should eq false
70
- File.exists?(@tree_2).should eq false
69
+ expect(File.exists?(@tree_1)).to eq false
70
+ expect(File.exists?(@tree_2)).to eq false
71
71
 
72
72
  druid_1 = DruidTools::Druid.new(@druid_1,@fixture_dir)
73
73
  druid_2 = DruidTools::Druid.new(@druid_2,@fixture_dir)
74
74
 
75
75
  druid_1.mkdir
76
- File.exists?(@tree_1).should eq true
77
- File.exists?(@tree_2).should eq false
76
+ expect(File.exists?(@tree_1)).to eq true
77
+ expect(File.exists?(@tree_2)).to eq false
78
78
 
79
79
  druid_2.mkdir
80
- File.exists?(@tree_1).should eq true
81
- File.exists?(@tree_2).should eq true
80
+ expect(File.exists?(@tree_1)).to eq true
81
+ expect(File.exists?(@tree_2)).to eq true
82
82
 
83
83
  druid_2.rmdir
84
- File.exists?(@tree_1).should eq true
85
- File.exists?(@tree_2).should eq false
84
+ expect(File.exists?(@tree_1)).to eq true
85
+ expect(File.exists?(@tree_2)).to eq false
86
86
 
87
87
  druid_1.rmdir
88
- File.exists?(@tree_1).should eq false
89
- File.exists?(@tree_2).should eq false
90
- File.exists?(File.join(@fixture_dir,'cd')).should eq false
88
+ expect(File.exists?(@tree_1)).to eq false
89
+ expect(File.exists?(@tree_2)).to eq false
90
+ expect(File.exists?(File.join(@fixture_dir,'cd'))).to eq false
91
91
  end
92
92
 
93
93
  describe "alternate prefixes" do
@@ -100,39 +100,39 @@ describe DruidTools::Druid do
100
100
  end
101
101
 
102
102
  it "handles alternate prefixes" do
103
- lambda { DruidTools::Druid.new('druid:cd456ef7890',@fixture_dir) }.should raise_error(ArgumentError)
104
- DruidTools::Druid.new('sulair:cd456ef7890',@fixture_dir).id.should == 'cd456ef7890'
105
- DruidTools::Druid.new('cd456ef7890',@fixture_dir).druid.should == 'sulair:cd456ef7890'
103
+ expect { DruidTools::Druid.new('druid:cd456ef7890',@fixture_dir) }.to raise_error(ArgumentError)
104
+ expect(DruidTools::Druid.new('sulair:cd456ef7890',@fixture_dir).id).to eq('cd456ef7890')
105
+ expect(DruidTools::Druid.new('cd456ef7890',@fixture_dir).druid).to eq('sulair:cd456ef7890')
106
106
  end
107
107
  end
108
108
 
109
109
  describe "content directories" do
110
110
  it "knows where its content goes" do
111
111
  druid = DruidTools::Druid.new(@druid_1,@fixture_dir)
112
- druid.content_dir(false).should == File.join(@tree_1,'content')
113
- druid.metadata_dir(false).should == File.join(@tree_1,'metadata')
114
- druid.temp_dir(false).should == File.join(@tree_1,'temp')
112
+ expect(druid.content_dir(false)).to eq(File.join(@tree_1,'content'))
113
+ expect(druid.metadata_dir(false)).to eq(File.join(@tree_1,'metadata'))
114
+ expect(druid.temp_dir(false)).to eq(File.join(@tree_1,'temp'))
115
115
 
116
- File.exists?(File.join(@tree_1,'content')).should eq false
117
- File.exists?(File.join(@tree_1,'metadata')).should eq false
118
- File.exists?(File.join(@tree_1,'temp')).should eq false
116
+ expect(File.exists?(File.join(@tree_1,'content'))).to eq false
117
+ expect(File.exists?(File.join(@tree_1,'metadata'))).to eq false
118
+ expect(File.exists?(File.join(@tree_1,'temp'))).to eq false
119
119
  end
120
120
 
121
121
  it "creates its content directories on the fly" do
122
122
  druid = DruidTools::Druid.new(@druid_1,@fixture_dir)
123
- druid.content_dir.should == File.join(@tree_1,'content')
124
- druid.metadata_dir.should == File.join(@tree_1,'metadata')
125
- druid.temp_dir.should == File.join(@tree_1,'temp')
123
+ expect(druid.content_dir).to eq(File.join(@tree_1,'content'))
124
+ expect(druid.metadata_dir).to eq(File.join(@tree_1,'metadata'))
125
+ expect(druid.temp_dir).to eq(File.join(@tree_1,'temp'))
126
126
 
127
- File.exists?(File.join(@tree_1,'content')).should eq true
128
- File.exists?(File.join(@tree_1,'metadata')).should eq true
129
- File.exists?(File.join(@tree_1,'temp')).should eq true
127
+ expect(File.exists?(File.join(@tree_1,'content'))).to eq true
128
+ expect(File.exists?(File.join(@tree_1,'metadata'))).to eq true
129
+ expect(File.exists?(File.join(@tree_1,'temp'))).to eq true
130
130
  end
131
131
 
132
132
  it "matches glob" do
133
133
  druid = DruidTools::Druid.new(@druid_1,@fixture_dir)
134
134
  druid.mkdir
135
- Dir.glob(File.join(File.dirname(druid.path), DruidTools::Druid::glob)).size.should == 1
135
+ expect(Dir.glob(File.join(File.dirname(druid.path), DruidTools::Druid::glob)).size).to eq(1)
136
136
  end
137
137
  end
138
138
 
@@ -145,31 +145,31 @@ describe DruidTools::Druid do
145
145
  it "finds content in content directories" do
146
146
  location = @druid.content_dir
147
147
  File.open(File.join(location,'someContent'),'w') { |f| f.write 'This is the content' }
148
- @druid.find_content('someContent').should == File.join(location,'someContent')
148
+ expect(@druid.find_content('someContent')).to eq(File.join(location,'someContent'))
149
149
  end
150
150
 
151
151
  it "finds content in the root directory" do
152
152
  location = @druid.path(nil,true)
153
153
  File.open(File.join(location,'someContent'),'w') { |f| f.write 'This is the content' }
154
- @druid.find_content('someContent').should == File.join(location,'someContent')
154
+ expect(@druid.find_content('someContent')).to eq(File.join(location,'someContent'))
155
155
  end
156
156
 
157
157
  it "finds content in the leaf directory" do
158
158
  location = File.expand_path('..',@druid.path(nil,true))
159
159
  File.open(File.join(location,'someContent'),'w') { |f| f.write 'This is the content' }
160
- @druid.find_content('someContent').should == File.join(location,'someContent')
160
+ expect(@druid.find_content('someContent')).to eq(File.join(location,'someContent'))
161
161
  end
162
162
 
163
163
  it "does not find content in the wrong content directory" do
164
164
  location = @druid.metadata_dir
165
165
  File.open(File.join(location,'someContent'),'w') { |f| f.write 'This is the content' }
166
- @druid.find_content('someContent').should be_nil
166
+ expect(@druid.find_content('someContent')).to be_nil
167
167
  end
168
168
 
169
169
  it "does not find content in a higher-up directory" do
170
170
  location = File.expand_path('../..',@druid.path(nil,true))
171
171
  File.open(File.join(location,'someContent'),'w') { |f| f.write 'This is the content' }
172
- @druid.find_content('someContent').should be_nil
172
+ expect(@druid.find_content('someContent')).to be_nil
173
173
  end
174
174
 
175
175
  it "finds a filelist in the content directory" do
@@ -177,7 +177,7 @@ describe DruidTools::Druid do
177
177
  @filelist.each do |filename|
178
178
  location.join(filename).open('w') { |f| f.write "This is #{filename}" }
179
179
  end
180
- @druid.find_filelist_parent('content',@filelist).should == location
180
+ expect(@druid.find_filelist_parent('content',@filelist)).to eq(location)
181
181
  end
182
182
 
183
183
  it "finds a filelist in the root directory" do
@@ -185,7 +185,7 @@ describe DruidTools::Druid do
185
185
  @filelist.each do |filename|
186
186
  location.join(filename).open('w') { |f| f.write "This is #{filename}" }
187
187
  end
188
- @druid.find_filelist_parent('content',@filelist).should == location
188
+ expect(@druid.find_filelist_parent('content',@filelist)).to eq(location)
189
189
  end
190
190
 
191
191
  it "finds a filelist in the leaf directory" do
@@ -193,18 +193,18 @@ describe DruidTools::Druid do
193
193
  @filelist.each do |filename|
194
194
  location.join(filename).open('w') { |f| f.write "This is #{filename}" }
195
195
  end
196
- @druid.find_filelist_parent('content',@filelist).should == location
196
+ expect(@druid.find_filelist_parent('content',@filelist)).to eq(location)
197
197
  end
198
198
 
199
199
  it "raises an exception if the first file in the filelist is not found" do
200
200
  location = Pathname(@druid.content_dir)
201
- lambda{@druid.find_filelist_parent('content',@filelist)}.should raise_exception(/content dir not found for 'someFile1' when searching/)
201
+ expect{@druid.find_filelist_parent('content',@filelist)}.to raise_exception(/content dir not found for 'someFile1' when searching/)
202
202
  end
203
203
 
204
204
  it "raises an exception if any other file in the filelist is not found" do
205
205
  location = Pathname(@druid.content_dir)
206
206
  location.join(@filelist.first).open('w') { |f| f.write "This is #{@filelist.first}" }
207
- lambda{@druid.find_filelist_parent('content',@filelist)}.should raise_exception(/File 'someFile2' not found/)
207
+ expect{@druid.find_filelist_parent('content',@filelist)}.to raise_exception(/File 'someFile2' not found/)
208
208
  end
209
209
 
210
210
  end
@@ -213,7 +213,7 @@ describe DruidTools::Druid do
213
213
  it "raises SameContentExistsError if the directory already exists" do
214
214
  druid_2 = DruidTools::Druid.new(@druid_2,@fixture_dir)
215
215
  druid_2.mkdir
216
- lambda { druid_2.mkdir }.should raise_error(DruidTools::SameContentExistsError)
216
+ expect { druid_2.mkdir }.to raise_error(DruidTools::SameContentExistsError)
217
217
  end
218
218
 
219
219
  it "raises DifferentContentExistsError if a link already exists in the workspace for this druid" do
@@ -221,7 +221,7 @@ describe DruidTools::Druid do
221
221
  FileUtils.mkdir_p(source_dir)
222
222
  dr = DruidTools::Druid.new(@druid_2,@fixture_dir)
223
223
  dr.mkdir_with_final_link(source_dir)
224
- lambda { dr.mkdir }.should raise_error(DruidTools::DifferentContentExistsError)
224
+ expect { dr.mkdir }.to raise_error(DruidTools::DifferentContentExistsError)
225
225
  end
226
226
  end
227
227
 
@@ -235,23 +235,21 @@ describe DruidTools::Druid do
235
235
 
236
236
  it "creates a druid tree in the workspace with the final directory being a link to the passed in source" do
237
237
  @dr.mkdir_with_final_link(@source_dir)
238
-
239
- File.should be_symlink(@dr.path)
240
- File.readlink(@tree_2).should == @source_dir
238
+ expect(File).to be_symlink(@dr.path)
239
+ expect(File.readlink(@tree_2)).to eq(@source_dir)
241
240
  end
242
241
 
243
242
  it "does not error out if the link to source already exists" do
244
243
  @dr.mkdir_with_final_link(@source_dir)
245
- File.should be_symlink(@dr.path)
246
- File.readlink(@tree_2).should == @source_dir
244
+ expect(File).to be_symlink(@dr.path)
245
+ expect(File.readlink(@tree_2)).to eq(@source_dir)
247
246
  end
248
247
 
249
248
  it "raises DifferentContentExistsError if a directory already exists in the workspace for this druid" do
250
249
  @dr.mkdir(@fixture_dir)
251
- lambda { @dr.mkdir_with_final_link(@source_di) }.should raise_error(DruidTools::DifferentContentExistsError)
250
+ expect { @dr.mkdir_with_final_link(@source_di) }.to raise_error(DruidTools::DifferentContentExistsError)
252
251
  end
253
-
254
-
252
+
255
253
  end
256
254
 
257
255
  describe "#prune!" do
@@ -261,17 +259,29 @@ describe DruidTools::Druid do
261
259
  let(:dr1) { DruidTools::Druid.new @druid_1, workspace }
262
260
  let(:dr2) { DruidTools::Druid.new @druid_2, workspace }
263
261
  let(:pathname1) { dr1.pathname }
264
-
265
-
262
+
266
263
  after(:each) do
267
264
  FileUtils.remove_entry workspace
268
265
  end
269
266
 
267
+ it "throws error on misconfig when base dir cannot be created" do
268
+ dir = '/some/dir/that/does/not/exist' # we don't have permissions to create
269
+ dr0 = DruidTools::Druid.new @druid_1, dir
270
+ expect {dr0.prune!}.to raise_error()
271
+ expect(File).to_not exist(dir)
272
+ end
273
+
274
+ it "does not throw error when base can be created" do
275
+ subdir = File.join(Dir.mktmpdir, 'some', 'nonexistant', 'subdir') # but this one *can* be created
276
+ dr2 = DruidTools::Druid.new @druid_2, subdir
277
+ expect {dr2.prune!}.not_to raise_error()
278
+ expect(File).to exist(subdir)
279
+ end
280
+
270
281
  context "shared ancestor" do
271
282
 
272
283
  before(:each) do
273
284
  #Nil the create records for this context because we're in a known read only one
274
-
275
285
  dr1.mkdir
276
286
  dr2.mkdir
277
287
  dr1.prune!
@@ -297,13 +307,13 @@ describe DruidTools::Druid do
297
307
  it "removes all directories up to the base path when there are no common ancestors" do
298
308
  #Make sure a delete record is not present
299
309
  expect(dr1.deletes_record_exists?).to be_falsey
300
-
301
- #Nil the create records for this test
310
+
311
+ #Nil the create records for this test
302
312
  dr1.mkdir
303
313
  dr1.prune!
304
314
  expect(File).to_not exist(File.join(workspace, 'cd'))
305
315
  expect(File).to exist(workspace)
306
-
316
+
307
317
  #Make sure a delete record was created
308
318
  expect(dr1.deletes_dir_exists?).to be_truthy
309
319
  expect(dr1.deletes_record_exists?).to be_truthy
@@ -312,106 +322,105 @@ describe DruidTools::Druid do
312
322
  it "removes directories with symlinks" do
313
323
  #Make sure a delete record is not present
314
324
  expect(dr2.deletes_record_exists?).to be_falsey
315
-
316
- #Nil the create records for this test
325
+
326
+ #Nil the create records for this test
317
327
  source_dir = File.join workspace, 'src_dir'
318
328
  FileUtils.mkdir_p(source_dir)
319
329
  dr2.mkdir_with_final_link(source_dir)
320
330
  dr2.prune!
321
331
  expect(File).to_not exist(dr2.path)
322
332
  expect(File).to_not exist(File.join(workspace, 'cd'))
323
-
333
+
324
334
  #Make sure a delete record was created
325
335
  expect(dr2.deletes_dir_exists?).to be_truthy
326
336
  expect(dr2.deletes_record_exists?).to be_truthy
327
337
  end
328
-
338
+
329
339
  describe "logging deleted druids" do
330
-
331
- #Purge any paths or delete records created in the test
332
- after :each do
333
- #Remove the .deletes dir to clean up
334
- dr2.deletes_delete_record if dr2.deletes_record_exists?
335
- FileUtils.rm_rf dr2.deletes_dir_pathname
336
-
337
- end
338
-
339
- it "returns the path to the .deletes directory as a Pathname" do
340
- expect(dr2.deletes_dir_pathname.class).to eq(Pathname)
341
- end
342
-
343
- it "returns the path to the delete record for a druid as a Pathname" do
344
- expect(dr2.deletes_record_pathname.class).to eq(Pathname)
345
- end
346
-
347
- it "returns the path to the delete record for a druid as top_level/.deletes/druid" do
348
- expect(dr2.deletes_record_pathname.to_s).to eq("#{dr2.base}/.deletes/#{dr2.id}")
349
- end
350
-
351
- it "returns false when the .deletes dir is not present on the file system" do
352
- expect(dr2.deletes_dir_exists?).to be_falsey
353
- end
354
-
355
- it "creates the .deletes dir and detect it exists" do
356
-
357
- #Clean the .deletes dir if present
358
- FileUtils.rm_rf dr2.deletes_dir_pathname
359
-
360
- #Test for exists? and create
361
- expect(dr2.deletes_dir_exists?).to be_falsey
362
- dr2.create_deletes_dir
363
- expect(dr2.deletes_dir_exists?).to be_truthy
364
- end
365
-
366
- it "returns false when the .deletes dir does not have a deleted record for a druid" do
367
- expect(dr2.deletes_record_exists?).to be_falsey
368
- end
369
-
370
- 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
371
- #Expect there not to be a .deletes dir or file (the file expectation is redundant I know)
372
- expect(dr2.deletes_dir_exists?).to be_falsey
373
- expect(dr2.deletes_record_exists?).to be_falsey
374
-
375
- #Create the delete record
376
- dr2.creates_delete_record
377
-
378
- #Check to ensure items were created
379
- expect(dr2.deletes_dir_exists?).to be_truthy
380
- expect(dr2.deletes_record_exists?).to be_truthy
381
- end
382
-
383
- 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
384
- #Expect there not to be a .deletes dir or file (the file expectation is redundant I know)
385
- expect(dr2.deletes_dir_exists?).to be_falsey
386
- expect(dr2.deletes_record_exists?).to be_falsey
387
-
388
- #Creates the deletes dir and check
389
- dr2.create_deletes_dir
390
- expect(dr2.deletes_dir_exists?).to be_truthy
391
- expect(dr2.deletes_record_exists?).to be_falsey
392
-
393
- #Create the delete record
394
- dr2.creates_delete_record
395
-
396
- #Check to ensure items were created
397
- expect(dr2.deletes_dir_exists?).to be_truthy
398
- expect(dr2.deletes_record_exists?).to be_truthy
399
- end
400
-
401
- it "creates a delete record with a parent directory that does not have a .deletes directory and contains an older delete record" do
402
- #Expect there not to be a .deletes dir or file (the file expectation is redundant I know)
403
- expect(dr2.deletes_dir_exists?).to be_falsey
404
- expect(dr2.deletes_record_exists?).to be_falsey
405
-
406
- dr2.creates_delete_record
407
- time = Time.now
408
- expect(File.mtime(dr2.deletes_record_pathname)).to be <= time
409
- sleep(1) #force a one second pause in case the machine is fast (as in not some old Commodore64), since mtime only goes down to the second
410
-
411
- dr2.creates_delete_record
412
- #Should have a new newer deleted record
413
- expect(File.mtime(dr2.deletes_record_pathname)).to be > time
414
- end
340
+
341
+ #Purge any paths or delete records created in the test
342
+ after :each do
343
+ #Remove the .deletes dir to clean up
344
+ dr2.deletes_delete_record if dr2.deletes_record_exists?
345
+ FileUtils.rm_rf dr2.deletes_dir_pathname
346
+ end
347
+
348
+ it "returns the path to the .deletes directory as a Pathname" do
349
+ expect(dr2.deletes_dir_pathname.class).to eq(Pathname)
350
+ end
351
+
352
+ it "returns the path to the delete record for a druid as a Pathname" do
353
+ expect(dr2.deletes_record_pathname.class).to eq(Pathname)
354
+ end
355
+
356
+ it "returns the path to the delete record for a druid as top_level/.deletes/druid" do
357
+ expect(dr2.deletes_record_pathname.to_s).to eq("#{dr2.base}/.deletes/#{dr2.id}")
358
+ end
359
+
360
+ it "returns false when the .deletes dir is not present on the file system" do
361
+ expect(dr2.deletes_dir_exists?).to be_falsey
362
+ end
363
+
364
+ it "creates the .deletes dir and detect it exists" do
365
+
366
+ #Clean the .deletes dir if present
367
+ FileUtils.rm_rf dr2.deletes_dir_pathname
368
+
369
+ #Test for exists? and create
370
+ expect(dr2.deletes_dir_exists?).to be_falsey
371
+ dr2.create_deletes_dir
372
+ expect(dr2.deletes_dir_exists?).to be_truthy
373
+ end
374
+
375
+ it "returns false when the .deletes dir does not have a deleted record for a druid" do
376
+ expect(dr2.deletes_record_exists?).to be_falsey
377
+ end
378
+
379
+ 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
380
+ #Expect there not to be a .deletes dir or file (the file expectation is redundant I know)
381
+ expect(dr2.deletes_dir_exists?).to be_falsey
382
+ expect(dr2.deletes_record_exists?).to be_falsey
383
+
384
+ #Create the delete record
385
+ dr2.creates_delete_record
386
+
387
+ #Check to ensure items were created
388
+ expect(dr2.deletes_dir_exists?).to be_truthy
389
+ expect(dr2.deletes_record_exists?).to be_truthy
390
+ end
391
+
392
+ 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
393
+ #Expect there not to be a .deletes dir or file (the file expectation is redundant I know)
394
+ expect(dr2.deletes_dir_exists?).to be_falsey
395
+ expect(dr2.deletes_record_exists?).to be_falsey
396
+
397
+ #Creates the deletes dir and check
398
+ dr2.create_deletes_dir
399
+ expect(dr2.deletes_dir_exists?).to be_truthy
400
+ expect(dr2.deletes_record_exists?).to be_falsey
401
+
402
+ #Create the delete record
403
+ dr2.creates_delete_record
404
+
405
+ #Check to ensure items were created
406
+ expect(dr2.deletes_dir_exists?).to be_truthy
407
+ expect(dr2.deletes_record_exists?).to be_truthy
408
+ end
409
+
410
+ it "creates a delete record with a parent directory that does not have a .deletes directory and contains an older delete record" do
411
+ #Expect there not to be a .deletes dir or file (the file expectation is redundant I know)
412
+ expect(dr2.deletes_dir_exists?).to be_falsey
413
+ expect(dr2.deletes_record_exists?).to be_falsey
414
+
415
+ dr2.creates_delete_record
416
+ time = Time.now
417
+ expect(File.mtime(dr2.deletes_record_pathname)).to be <= time
418
+ sleep(1) #force a one second pause in case the machine is fast (as in not some old Commodore64), since mtime only goes down to the second
419
+
420
+ dr2.creates_delete_record
421
+ #Should have a new newer deleted record
422
+ expect(File.mtime(dr2.deletes_record_pathname)).to be > time
423
+ end
415
424
  end
416
425
  end
417
426
  end
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: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klein
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-31 00:00:00.000000000 Z
12
+ date: 2015-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 10.1.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
27
  version: 10.1.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rspec
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '3.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
41
  version: '3.0'
42
42
  description: Tools to manipulate DRUID trees and content directories
@@ -46,7 +46,9 @@ executables: []
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
- - .gitignore
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - ".travis.yml"
50
52
  - Gemfile
51
53
  - LICENSE
52
54
  - README.md
@@ -103,17 +105,17 @@ require_paths:
103
105
  - lib
104
106
  required_ruby_version: !ruby/object:Gem::Requirement
105
107
  requirements:
106
- - - ! '>='
108
+ - - ">="
107
109
  - !ruby/object:Gem::Version
108
110
  version: '0'
109
111
  required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  requirements:
111
- - - ! '>='
113
+ - - ">="
112
114
  - !ruby/object:Gem::Version
113
115
  version: '0'
114
116
  requirements: []
115
117
  rubyforge_project:
116
- rubygems_version: 2.1.2
118
+ rubygems_version: 2.4.5
117
119
  signing_key:
118
120
  specification_version: 4
119
121
  summary: Tools to manipulate DRUID trees and content directories