Permalink
Browse files

Make command line error handling more generic

  • Loading branch information...
1 parent 1d22cdc commit b43693019d713cf89d06a172096a655990838333 @jyurek jyurek committed Jun 22, 2012
Showing with 3 additions and 10 deletions.
  1. +2 −1 lib/paperclip/content_type_detector.rb
  2. +1 −9 test/content_type_detector_test.rb
@@ -52,7 +52,8 @@ def type_from_file_command
type = begin
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
Paperclip.run("file", "-b --mime :file", :file => @filename)
- rescue Cocaine::CommandNotFoundError => e
+ rescue Cocaine::CommandLineError => e
+ Paperclip.log("Error while determining content type: #{e}")
SENSIBLE_DEFAULT
end
@@ -31,16 +31,8 @@ class ContentTypeDetectorTest < Test::Unit::TestCase
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
end
- should 'let errors raise if something blows up' do
- Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
- @filename = "/path/to/something"
- assert_raises(Cocaine::CommandLineError) do
- Paperclip::ContentTypeDetector.new(@filename).detect
- end
- end
-
should 'return a sensible default when the file command is missing' do
- Paperclip.stubs(:run).raises(Cocaine::CommandNotFoundError.new)
+ Paperclip.stubs(:run).raises(Cocaine::CommandLineError.new)
@filename = "/path/to/something"
assert_equal "application/octet-stream", Paperclip::ContentTypeDetector.new(@filename).detect
end

0 comments on commit b436930

Please sign in to comment.