Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
1d22cdca
Commit
1d22cdca
authored
Jun 22, 2012
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gracefully handle a missing file command
parent
16f707ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
lib/paperclip/content_type_detector.rb
+7
-2
test/content_type_detector_test.rb
+6
-0
No files found.
lib/paperclip/content_type_detector.rb
View file @
1d22cdca
...
...
@@ -49,8 +49,13 @@ module Paperclip
end
def
type_from_file_command
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
type
=
Paperclip
.
run
(
"file"
,
"-b --mime :file"
,
:file
=>
@filename
)
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
SENSIBLE_DEFAULT
end
if
type
.
match
(
/\(.*?\)/
)
type
=
SENSIBLE_DEFAULT
end
...
...
test/content_type_detector_test.rb
View file @
1d22cdca
...
...
@@ -38,5 +38,11 @@ class ContentTypeDetectorTest < Test::Unit::TestCase
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
)
@filename
=
"/path/to/something"
assert_equal
"application/octet-stream"
,
Paperclip
::
ContentTypeDetector
.
new
(
@filename
).
detect
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment