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
2fb4ba9e
Commit
2fb4ba9e
authored
Nov 01, 2013
by
Jon Yurek
Browse files
Options
Browse Files
Download
Plain Diff
Merged close-all-the-files
parents
8e900b2a
8c2904cc
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
91 additions
and
37 deletions
+91
-37
lib/paperclip/attachment.rb
+7
-1
test/attachment_test.rb
+1
-1
test/content_type_detector_test.rb
+1
-0
test/file_command_content_type_detector_test.rb
+2
-0
test/helper.rb
+17
-0
test/io_adapters/attachment_adapter_test.rb
+6
-3
test/io_adapters/data_uri_adapter_test.rb
+7
-0
test/io_adapters/empty_string_adapter_test.rb
+1
-0
test/io_adapters/file_adapter_test.rb
+48
-32
test/validators/attachment_content_type_validator_test.rb
+1
-0
No files found.
lib/paperclip/attachment.rb
View file @
2fb4ba9e
...
...
@@ -429,10 +429,16 @@ module Paperclip
def
post_process_style
(
name
,
style
)
#:nodoc:
begin
raise
RuntimeError
.
new
(
"Style
#{
name
}
has no processors defined."
)
if
style
.
processors
.
blank?
original_file
=
@queued_for_write
[
:original
]
@queued_for_write
[
name
]
=
style
.
processors
.
inject
(
@queued_for_write
[
:original
])
do
|
file
,
processor
|
Paperclip
.
processor
(
processor
).
make
(
file
,
style
.
processor_options
,
self
)
new_file
=
Paperclip
.
processor
(
processor
).
make
(
file
,
style
.
processor_options
,
self
)
file
.
close
unless
file
==
original_file
new_file
end
unadapted_file
=
@queued_for_write
[
name
]
@queued_for_write
[
name
]
=
Paperclip
.
io_adapters
.
for
(
@queued_for_write
[
name
])
unadapted_file
.
close
if
unadapted_file
.
respond_to?
(
:close
)
@queued_for_write
[
name
]
rescue
Paperclip
::
Error
=>
e
log
(
"An error was received while processing:
#{
e
.
inspect
}
"
)
(
@errors
[
:processing
]
||=
[])
<<
e
.
message
if
@options
[
:whiny
]
...
...
test/attachment_test.rb
View file @
2fb4ba9e
...
...
@@ -643,7 +643,7 @@ class AttachmentTest < Test::Unit::TestCase
rebuild_model
:processors
=>
[
:thumbnail
,
:test
],
:styles
=>
@style_params
@dummy
=
Dummy
.
new
@file
=
StringIO
.
new
(
"..."
)
@file
.
stubs
(
:
to_tempfile
).
returns
(
@fil
e
)
@file
.
stubs
(
:
clos
e
)
Paperclip
::
Test
.
stubs
(
:make
).
returns
(
@file
)
Paperclip
::
Thumbnail
.
stubs
(
:make
).
returns
(
@file
)
end
...
...
test/content_type_detector_test.rb
View file @
2fb4ba9e
...
...
@@ -8,6 +8,7 @@ class ContentTypeDetectorTest < Test::Unit::TestCase
should
'return the empty content type when the file is empty'
do
tempfile
=
Tempfile
.
new
(
"empty"
)
assert_equal
"inode/x-empty"
,
Paperclip
::
ContentTypeDetector
.
new
(
tempfile
.
path
).
detect
tempfile
.
close
end
should
'return content type of file if it is an acceptable type'
do
...
...
test/file_command_content_type_detector_test.rb
View file @
2fb4ba9e
...
...
@@ -7,6 +7,8 @@ class FileCommandContentTypeDetectorTest < Test::Unit::TestCase
tempfile
.
rewind
assert_equal
"text/plain"
,
Paperclip
::
FileCommandContentTypeDetector
.
new
(
tempfile
.
path
).
detect
tempfile
.
close
end
should
'return a sensible default when the file command is missing'
do
...
...
test/helper.rb
View file @
2fb4ba9e
...
...
@@ -32,6 +32,7 @@ end
ROOT
=
Pathname
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)))
$previous_count
=
0
class
Test
::
Unit
::
TestCase
def
setup
silence_warnings
do
...
...
@@ -41,6 +42,22 @@ class Test::Unit::TestCase
Rails
.
stubs
(
:const_defined?
).
with
(
:Railtie
).
returns
(
false
)
end
end
def
teardown
end
def
report_files
files
=
[]
ObjectSpace
.
each_object
(
IO
){
|
io
|
files
<<
io
unless
io
.
closed?
}
if
files
.
count
>
$previous_count
puts
__name__
puts
"
#{
files
.
count
}
files"
files
.
each
do
|
file
|
puts
"Open IO:
#{
file
.
inspect
}
"
end
end
$previous_count
=
files
.
count
end
end
$LOAD_PATH
<<
File
.
join
(
ROOT
,
'lib'
)
...
...
test/io_adapters/attachment_adapter_test.rb
View file @
2fb4ba9e
require
'./test/helper'
require
'pp'
class
AttachmentAdapterTest
<
Test
::
Unit
::
TestCase
...
...
@@ -19,6 +20,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
teardown
do
@file
.
close
@subject
.
close
end
should
"get the right filename"
do
...
...
@@ -58,8 +60,8 @@ class AttachmentAdapterTest < Test::Unit::TestCase
context
"for a file with restricted characters in the name"
do
setup
do
file_contents
=
File
.
new
(
fixture_file
(
"animated.gif"
))
@file
=
StringIO
.
new
(
file_contents
.
read
)
file_contents
=
IO
.
read
(
fixture_file
(
"animated.gif"
))
@file
=
StringIO
.
new
(
file_contents
)
@file
.
stubs
(
:original_filename
).
returns
(
'image:restricted.gif'
)
@file
.
binmode
...
...
@@ -69,7 +71,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end
teardown
do
@
file
.
close
@
subject
.
close
end
should
"not generate paths that include restricted characters"
do
...
...
@@ -98,6 +100,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
teardown
do
@file
.
close
@thumb
.
close
@subject
.
close
end
should
"get the original filename"
do
...
...
test/io_adapters/data_uri_adapter_test.rb
View file @
2fb4ba9e
require
'./test/helper'
class
DataUriAdapterTest
<
Test
::
Unit
::
TestCase
def
teardown
if
@subject
@subject
.
close
end
end
context
"a new instance"
do
setup
do
@contents
=
"data:image/png;base64,
#{
original_base64_content
}
"
...
...
test/io_adapters/empty_string_adapter_test.rb
View file @
2fb4ba9e
require
'./test/helper'
class
EmptyStringAdapterTest
<
Test
::
Unit
::
TestCase
context
'a new instance'
do
setup
do
@subject
=
Paperclip
.
io_adapters
.
for
(
''
)
...
...
test/io_adapters/file_adapter_test.rb
View file @
2fb4ba9e
...
...
@@ -6,49 +6,58 @@ class FileAdapterTest < Test::Unit::TestCase
setup
do
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
@file
.
binmode
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
teardown
{
@file
.
close
}
should
"get the right filename"
do
assert_equal
"5k.png"
,
@subject
.
original_filename
teardown
do
@file
.
close
@subject
.
close
if
@subject
end
should
"force binmode on tempfile"
do
assert
@subject
.
instance_variable_get
(
"@tempfile"
).
binmode?
end
context
'doing normal things'
do
setup
do
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
should
"get the content typ
e"
do
assert_equal
"image/png"
,
@subject
.
content_typ
e
end
should
"get the right filenam
e"
do
assert_equal
"5k.png"
,
@subject
.
original_filenam
e
end
should
"return content type as a string
"
do
assert_kind_of
String
,
@subject
.
content_type
end
should
"force binmode on tempfile
"
do
assert
@subject
.
instance_variable_get
(
"@tempfile"
).
binmode?
end
should
"get the file's siz
e"
do
assert_equal
4456
,
@subject
.
siz
e
end
should
"get the content typ
e"
do
assert_equal
"image/png"
,
@subject
.
content_typ
e
end
should
"return false for a call to nil?
"
do
assert
!
@subject
.
nil?
end
should
"return content type as a string
"
do
assert_kind_of
String
,
@subject
.
content_type
end
should
"generate a MD5 hash of the contents"
do
expected
=
Digest
::
MD5
.
file
(
@file
.
path
).
to_s
assert_equal
expected
,
@subject
.
fingerprint
end
should
"get the file's size"
do
assert_equal
4456
,
@subject
.
size
end
should
"return false for a call to nil?"
do
assert
!
@subject
.
nil?
end
should
"read the contents of the file"
do
expected
=
@file
.
read
assert
expected
.
length
>
0
assert_equal
expected
,
@subject
.
read
should
"generate a MD5 hash of the contents"
do
expected
=
Digest
::
MD5
.
file
(
@file
.
path
).
to_s
assert_equal
expected
,
@subject
.
fingerprint
end
should
"read the contents of the file"
do
expected
=
@file
.
read
assert
expected
.
length
>
0
assert_equal
expected
,
@subject
.
read
end
end
context
"file with multiple possible content type"
do
setup
do
MIME
::
Types
.
stubs
(
:type_for
).
returns
([
MIME
::
Type
.
new
(
'image/x-png'
),
MIME
::
Type
.
new
(
'image/png'
)])
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
should
"prefer officially registered mime type"
do
...
...
@@ -86,13 +95,17 @@ class FileAdapterTest < Test::Unit::TestCase
context
"filename with restricted characters"
do
setup
do
file_contents
=
File
.
new
(
fixture_file
(
"animated.gif"
))
@file
=
StringIO
.
new
(
file_contents
.
read
)
@file
=
File
.
open
(
fixture_file
(
"animated.gif"
))
do
|
file
|
StringIO
.
new
(
file
.
read
)
end
@file
.
stubs
(
:original_filename
).
returns
(
'image:restricted.gif'
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
teardown
{
@file
.
close
}
teardown
do
@file
.
close
@subject
.
close
end
should
"not generate filenames that include restricted characters"
do
assert_equal
'image_restricted.gif'
,
@subject
.
original_filename
...
...
@@ -109,7 +122,10 @@ class FileAdapterTest < Test::Unit::TestCase
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
teardown
{
@file
.
close
}
teardown
do
@file
.
close
@subject
.
close
end
should
"provide correct mime-type"
do
assert_match
%r{.*/x-empty}
,
@subject
.
content_type
...
...
test/validators/attachment_content_type_validator_test.rb
View file @
2fb4ba9e
...
...
@@ -4,6 +4,7 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
def
setup
rebuild_model
@dummy
=
Dummy
.
new
super
end
def
build_validator
(
options
)
...
...
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