remote_files 1.6.0 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -116,10 +116,21 @@ module RemoteFiles
116
116
  end
117
117
 
118
118
  def delete_now!(file)
119
+ exceptions = []
119
120
  file.stored_in.each do |store_identifier|
120
121
  store = lookup_store(store_identifier)
121
- store.delete!(file.identifier)
122
+ begin
123
+ store.delete!(file.identifier)
124
+ rescue NotFoundError => e
125
+ exceptions << e
126
+ end
127
+ end
128
+
129
+ if exceptions.size == file.stored_in.size # they all failed
130
+ raise exceptions.first
122
131
  end
132
+
133
+ true
123
134
  end
124
135
 
125
136
  def synchronize!(file)
@@ -32,13 +32,14 @@ module RemoteFiles
32
32
  :stored_in => [self]
33
33
  # what about content-type? maybe use the mime-types gem?
34
34
  )
35
- rescue Errno::ENOENT => e
36
- raise NotFoundError, e.message
35
+ rescue Errno::ENOENT
36
+ raise NotFoundError, $!.message, $!.backtrace
37
37
  end
38
38
 
39
39
  def delete!(identifier)
40
40
  (directory + identifier).delete
41
- rescue Errno::ENOENT => e
41
+ rescue Errno::ENOENT
42
+ raise NotFoundError, $!.message, $!.backtrace
42
43
  end
43
44
 
44
45
  def url(identifier)
@@ -56,6 +56,8 @@ module RemoteFiles
56
56
 
57
57
  def delete!(identifier)
58
58
  connection.delete_object(directory.key, identifier)
59
+ rescue Fog::Errors::NotFound, Excon::Errors::NotFound
60
+ raise NotFoundError, $!.message, $!.backtrace
59
61
  end
60
62
 
61
63
  def connection
@@ -39,6 +39,7 @@ module RemoteFiles
39
39
  end
40
40
 
41
41
  def delete!(identifier)
42
+ raise NotFoundError, "#{identifier} not found in #{self.identifier} store" unless data.has_key?(identifier)
42
43
  data.delete(identifier)
43
44
  end
44
45
 
@@ -13,7 +13,10 @@ module RemoteFiles
13
13
  when :synchronize
14
14
  file.synchronize!
15
15
  when :delete
16
- file.delete_now!
16
+ begin
17
+ file.delete_now!
18
+ rescue NotFoundError
19
+ end
17
20
  else
18
21
  raise "unknown action #{action.inspect}"
19
22
  end
@@ -1,3 +1,3 @@
1
1
  module RemoteFiles
2
- VERSION = '1.6.0'
2
+ VERSION = '1.6.1'
3
3
  end
@@ -158,11 +158,41 @@ describe RemoteFiles::Configuration do
158
158
  end
159
159
 
160
160
  describe '::delete_now!' do
161
- it 'should delete the file from all the stores' do
161
+ before do
162
162
  @file.stored_in.replace([:mock1, :mock2])
163
- @mock_store1.expects(:delete!).with(@file.identifier)
164
- @mock_store2.expects(:delete!).with(@file.identifier)
165
- @configuration.delete_now!(@file)
163
+ end
164
+
165
+ describe 'when the file is in all of stores' do
166
+ before do
167
+ @mock_store1.data[@file.identifier] = {:content_type => 'text/plain', :content => 'content'}
168
+ @mock_store2.data[@file.identifier] = {:content_type => 'text/plain', :content => 'content'}
169
+ end
170
+
171
+ it 'should delete the file from all the stores' do
172
+ @configuration.delete_now!(@file)
173
+ @mock_store1.data.has_key?(@file.identifier).must_equal false
174
+ @mock_store2.data.has_key?(@file.identifier).must_equal false
175
+ end
176
+ end
177
+
178
+ describe 'when the file is in some of stores' do
179
+ before do
180
+ @mock_store2.data[@file.identifier] = {:content_type => 'text/plain', :content => 'content'}
181
+ end
182
+
183
+ it 'should delete the file from all the stores' do
184
+ @configuration.delete_now!(@file)
185
+ @mock_store1.data.has_key?(@file.identifier).must_equal false
186
+ @mock_store2.data.has_key?(@file.identifier).must_equal false
187
+ end
188
+ end
189
+
190
+ describe 'when the file is in none of stores' do
191
+ it 'raises a NotFoundError' do
192
+ lambda { @configuration.delete_now!(@file) }.must_raise(RemoteFiles::NotFoundError)
193
+ @mock_store1.data.has_key?(@file.identifier).must_equal false
194
+ @mock_store2.data.has_key?(@file.identifier).must_equal false
195
+ end
166
196
  end
167
197
  end
168
198
 
@@ -70,6 +70,10 @@ describe RemoteFiles::FileStore do
70
70
  end
71
71
  end
72
72
 
73
+ it 'raises a NotFoundError if the file does not exist' do
74
+ lambda { @store.delete!('unknown') }.must_raise(RemoteFiles::NotFoundError)
75
+ end
76
+
73
77
  it 'should destroy the file' do
74
78
  assert (@store.directory + 'identifier').exist?
75
79
 
@@ -165,6 +165,11 @@ describe RemoteFiles::FogStore do
165
165
  )
166
166
  end
167
167
 
168
+ it 'raises a NotFoundError if the file does not exist' do
169
+ @store.directory.key = 'unknown' # to force an exception out of the fog
170
+ lambda { @store.delete!('unknown') }.must_raise(RemoteFiles::NotFoundError)
171
+ end
172
+
168
173
  it 'should destroy the file' do
169
174
  assert @store.directory.files.get('identifier')
170
175
 
@@ -59,6 +59,10 @@ describe RemoteFiles::MemoryStore do
59
59
  @store.data['identifier'] = {:content_type => 'text/plain', :content => 'content'}
60
60
  end
61
61
 
62
+ it 'raises a NotFoundError if the file does not exist' do
63
+ lambda { @store.delete!('unknown') }.must_raise(RemoteFiles::NotFoundError)
64
+ end
65
+
62
66
  it 'should destroy the file' do
63
67
  assert @store.data['identifier']
64
68
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_files
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.6.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-08 00:00:00.000000000 Z
12
+ date: 2013-01-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -146,18 +146,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  - - ! '>='
147
147
  - !ruby/object:Gem::Version
148
148
  version: '0'
149
- segments:
150
- - 0
151
- hash: 424450237323346317
152
149
  required_rubygems_version: !ruby/object:Gem::Requirement
153
150
  none: false
154
151
  requirements:
155
152
  - - ! '>='
156
153
  - !ruby/object:Gem::Version
157
154
  version: '0'
158
- segments:
159
- - 0
160
- hash: 424450237323346317
161
155
  requirements: []
162
156
  rubyforge_project:
163
157
  rubygems_version: 1.8.24