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
c7b84adc
Commit
c7b84adc
authored
Oct 09, 2009
by
Jason Morrison
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a unit test for Upfile and updating a few content types
parent
d6ebd321
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
2 deletions
+31
-2
lib/paperclip/upfile.rb
+3
-2
test/upfile_test.rb
+28
-0
No files found.
lib/paperclip/upfile.rb
View file @
c7b84adc
...
...
@@ -8,12 +8,13 @@ module Paperclip
def
content_type
type
=
(
self
.
path
.
match
(
/\.(\w+)$/
)[
1
]
rescue
"octet-stream"
).
downcase
case
type
when
%r"jp
e?g"
then
"image/jpeg"
when
%r"jp
(e|g|eg)"
then
"image/jpeg"
when
%r"tiff?"
then
"image/tiff"
when
%r"png"
,
"gif"
,
"bmp"
then
"image/
#{
type
}
"
when
"txt"
then
"text/plain"
when
%r"html?"
then
"text/html"
when
"csv"
,
"xml"
,
"css"
,
"js"
then
"text/
#{
type
}
"
when
"js"
then
"application/js"
when
"csv"
,
"xml"
,
"css"
then
"text/
#{
type
}
"
else
"application/x-
#{
type
}
"
end
end
...
...
test/upfile_test.rb
0 → 100644
View file @
c7b84adc
require
'test/helper'
class
UpfileTest
<
Test
::
Unit
::
TestCase
{
%w(jpg jpe jpeg)
=>
'image/jpeg'
,
%w(tif tiff)
=>
'image/tiff'
,
%w(png)
=>
'image/png'
,
%w(gif)
=>
'image/gif'
,
%w(bmp)
=>
'image/bmp'
,
%w(txt)
=>
'text/plain'
,
%w(htm html)
=>
'text/html'
,
%w(csv)
=>
'text/csv'
,
%w(xml)
=>
'text/xml'
,
%w(css)
=>
'text/css'
,
%w(js)
=>
'application/js'
,
%w(foo)
=>
'application/x-foo'
}.
each
do
|
extensions
,
content_type
|
extensions
.
each
do
|
extension
|
should
"return a content_type of
#{
content_type
}
for a file with extension .
#{
extension
}
"
do
file
=
stub
(
'file'
,
:path
=>
"basename.
#{
extension
}
"
)
class
<<
file
include
Paperclip
::
Upfile
end
assert_equal
content_type
,
file
.
content_type
end
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