Skip to content

Commit

Permalink
Fix silly bug in S3Store delete() and spec this method. Also be more …
Browse files Browse the repository at this point in the history
…specific when rescuing exceptions in S3Store.
  • Loading branch information
Martyn Loughran committed Oct 8, 2008
1 parent 41b1812 commit 770811f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/s3_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def set(key, tmp_file)
S3VideoObject.store(key, File.open(tmp_file), :access => :public_read)
sleep 3
end
rescue
rescue AWS::S3::S3Exception
Merb.logger.error "Error uploading #{key} to S3"
raise
else
Expand All @@ -37,7 +37,7 @@ def get(key, tmp_file)
end
sleep 3
end
rescue
rescue AWS::S3::S3Exception
raise_file_error(key)
else
true
Expand All @@ -49,10 +49,10 @@ def delete(key)
begin
retryable(:tries => 5) do
Merb.logger.info "Deleting #{key} from S3"
S3VideoObject.delete(self.filename)
S3VideoObject.delete(key)
sleep 3
end
rescue
rescue AWS::S3::S3Exception
raise_file_error(key)
else
true
Expand Down
15 changes: 13 additions & 2 deletions spec/models/s3_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,20 @@
end

describe "delete" do
it "should delete from S3"
it "should delete from S3" do
S3VideoObject.should_receive(:delete).with('abc.mov')

@store.delete('abc.mov')
end

it "should retry deleting up to 6 times and raise exception on fail"
it "should retry deleting up to 6 times and raise exception on fail" do
S3VideoObject.should_receive(:delete).exactly(6).times.
with('abc.mov').and_raise(AWS::S3::S3Exception)

lambda {
@store.delete('abc.mov')
}.should raise_error(AbstractStore::FileDoesNotExistError)
end
end

describe "url" do
Expand Down

0 comments on commit 770811f

Please sign in to comment.