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
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
65 additions
and
11 deletions
+65
-11
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
+22
-6
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
...
@@ -429,10 +429,16 @@ module Paperclip
def
post_process_style
(
name
,
style
)
#:nodoc:
def
post_process_style
(
name
,
style
)
#:nodoc:
begin
begin
raise
RuntimeError
.
new
(
"Style
#{
name
}
has no processors defined."
)
if
style
.
processors
.
blank?
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
|
@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
end
unadapted_file
=
@queued_for_write
[
name
]
@queued_for_write
[
name
]
=
Paperclip
.
io_adapters
.
for
(
@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
rescue
Paperclip
::
Error
=>
e
log
(
"An error was received while processing:
#{
e
.
inspect
}
"
)
log
(
"An error was received while processing:
#{
e
.
inspect
}
"
)
(
@errors
[
:processing
]
||=
[])
<<
e
.
message
if
@options
[
:whiny
]
(
@errors
[
:processing
]
||=
[])
<<
e
.
message
if
@options
[
:whiny
]
...
...
test/attachment_test.rb
View file @
2fb4ba9e
...
@@ -643,7 +643,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -643,7 +643,7 @@ class AttachmentTest < Test::Unit::TestCase
rebuild_model
:processors
=>
[
:thumbnail
,
:test
],
:styles
=>
@style_params
rebuild_model
:processors
=>
[
:thumbnail
,
:test
],
:styles
=>
@style_params
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@file
=
StringIO
.
new
(
"..."
)
@file
=
StringIO
.
new
(
"..."
)
@file
.
stubs
(
:
to_tempfile
).
returns
(
@fil
e
)
@file
.
stubs
(
:
clos
e
)
Paperclip
::
Test
.
stubs
(
:make
).
returns
(
@file
)
Paperclip
::
Test
.
stubs
(
:make
).
returns
(
@file
)
Paperclip
::
Thumbnail
.
stubs
(
:make
).
returns
(
@file
)
Paperclip
::
Thumbnail
.
stubs
(
:make
).
returns
(
@file
)
end
end
...
...
test/content_type_detector_test.rb
View file @
2fb4ba9e
...
@@ -8,6 +8,7 @@ class ContentTypeDetectorTest < Test::Unit::TestCase
...
@@ -8,6 +8,7 @@ class ContentTypeDetectorTest < Test::Unit::TestCase
should
'return the empty content type when the file is empty'
do
should
'return the empty content type when the file is empty'
do
tempfile
=
Tempfile
.
new
(
"empty"
)
tempfile
=
Tempfile
.
new
(
"empty"
)
assert_equal
"inode/x-empty"
,
Paperclip
::
ContentTypeDetector
.
new
(
tempfile
.
path
).
detect
assert_equal
"inode/x-empty"
,
Paperclip
::
ContentTypeDetector
.
new
(
tempfile
.
path
).
detect
tempfile
.
close
end
end
should
'return content type of file if it is an acceptable type'
do
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
...
@@ -7,6 +7,8 @@ class FileCommandContentTypeDetectorTest < Test::Unit::TestCase
tempfile
.
rewind
tempfile
.
rewind
assert_equal
"text/plain"
,
Paperclip
::
FileCommandContentTypeDetector
.
new
(
tempfile
.
path
).
detect
assert_equal
"text/plain"
,
Paperclip
::
FileCommandContentTypeDetector
.
new
(
tempfile
.
path
).
detect
tempfile
.
close
end
end
should
'return a sensible default when the file command is missing'
do
should
'return a sensible default when the file command is missing'
do
...
...
test/helper.rb
View file @
2fb4ba9e
...
@@ -32,6 +32,7 @@ end
...
@@ -32,6 +32,7 @@ end
ROOT
=
Pathname
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)))
ROOT
=
Pathname
(
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
)))
$previous_count
=
0
class
Test
::
Unit
::
TestCase
class
Test
::
Unit
::
TestCase
def
setup
def
setup
silence_warnings
do
silence_warnings
do
...
@@ -41,6 +42,22 @@ class Test::Unit::TestCase
...
@@ -41,6 +42,22 @@ class Test::Unit::TestCase
Rails
.
stubs
(
:const_defined?
).
with
(
:Railtie
).
returns
(
false
)
Rails
.
stubs
(
:const_defined?
).
with
(
:Railtie
).
returns
(
false
)
end
end
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
end
$LOAD_PATH
<<
File
.
join
(
ROOT
,
'lib'
)
$LOAD_PATH
<<
File
.
join
(
ROOT
,
'lib'
)
...
...
test/io_adapters/attachment_adapter_test.rb
View file @
2fb4ba9e
require
'./test/helper'
require
'./test/helper'
require
'pp'
class
AttachmentAdapterTest
<
Test
::
Unit
::
TestCase
class
AttachmentAdapterTest
<
Test
::
Unit
::
TestCase
...
@@ -19,6 +20,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
...
@@ -19,6 +20,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
teardown
do
teardown
do
@file
.
close
@file
.
close
@subject
.
close
end
end
should
"get the right filename"
do
should
"get the right filename"
do
...
@@ -58,8 +60,8 @@ class AttachmentAdapterTest < Test::Unit::TestCase
...
@@ -58,8 +60,8 @@ class AttachmentAdapterTest < Test::Unit::TestCase
context
"for a file with restricted characters in the name"
do
context
"for a file with restricted characters in the name"
do
setup
do
setup
do
file_contents
=
File
.
new
(
fixture_file
(
"animated.gif"
))
file_contents
=
IO
.
read
(
fixture_file
(
"animated.gif"
))
@file
=
StringIO
.
new
(
file_contents
.
read
)
@file
=
StringIO
.
new
(
file_contents
)
@file
.
stubs
(
:original_filename
).
returns
(
'image:restricted.gif'
)
@file
.
stubs
(
:original_filename
).
returns
(
'image:restricted.gif'
)
@file
.
binmode
@file
.
binmode
...
@@ -69,7 +71,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
...
@@ -69,7 +71,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
end
end
teardown
do
teardown
do
@
file
.
close
@
subject
.
close
end
end
should
"not generate paths that include restricted characters"
do
should
"not generate paths that include restricted characters"
do
...
@@ -98,6 +100,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
...
@@ -98,6 +100,7 @@ class AttachmentAdapterTest < Test::Unit::TestCase
teardown
do
teardown
do
@file
.
close
@file
.
close
@thumb
.
close
@thumb
.
close
@subject
.
close
end
end
should
"get the original filename"
do
should
"get the original filename"
do
...
...
test/io_adapters/data_uri_adapter_test.rb
View file @
2fb4ba9e
require
'./test/helper'
require
'./test/helper'
class
DataUriAdapterTest
<
Test
::
Unit
::
TestCase
class
DataUriAdapterTest
<
Test
::
Unit
::
TestCase
def
teardown
if
@subject
@subject
.
close
end
end
context
"a new instance"
do
context
"a new instance"
do
setup
do
setup
do
@contents
=
"data:image/png;base64,
#{
original_base64_content
}
"
@contents
=
"data:image/png;base64,
#{
original_base64_content
}
"
...
...
test/io_adapters/empty_string_adapter_test.rb
View file @
2fb4ba9e
require
'./test/helper'
require
'./test/helper'
class
EmptyStringAdapterTest
<
Test
::
Unit
::
TestCase
class
EmptyStringAdapterTest
<
Test
::
Unit
::
TestCase
context
'a new instance'
do
context
'a new instance'
do
setup
do
setup
do
@subject
=
Paperclip
.
io_adapters
.
for
(
''
)
@subject
=
Paperclip
.
io_adapters
.
for
(
''
)
...
...
test/io_adapters/file_adapter_test.rb
View file @
2fb4ba9e
...
@@ -6,10 +6,17 @@ class FileAdapterTest < Test::Unit::TestCase
...
@@ -6,10 +6,17 @@ class FileAdapterTest < Test::Unit::TestCase
setup
do
setup
do
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
@file
=
File
.
new
(
fixture_file
(
"5k.png"
))
@file
.
binmode
@file
.
binmode
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
teardown
{
@file
.
close
}
teardown
do
@file
.
close
@subject
.
close
if
@subject
end
context
'doing normal things'
do
setup
do
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
should
"get the right filename"
do
should
"get the right filename"
do
assert_equal
"5k.png"
,
@subject
.
original_filename
assert_equal
"5k.png"
,
@subject
.
original_filename
...
@@ -45,10 +52,12 @@ class FileAdapterTest < Test::Unit::TestCase
...
@@ -45,10 +52,12 @@ class FileAdapterTest < Test::Unit::TestCase
assert
expected
.
length
>
0
assert
expected
.
length
>
0
assert_equal
expected
,
@subject
.
read
assert_equal
expected
,
@subject
.
read
end
end
end
context
"file with multiple possible content type"
do
context
"file with multiple possible content type"
do
setup
do
setup
do
MIME
::
Types
.
stubs
(
:type_for
).
returns
([
MIME
::
Type
.
new
(
'image/x-png'
),
MIME
::
Type
.
new
(
'image/png'
)])
MIME
::
Types
.
stubs
(
:type_for
).
returns
([
MIME
::
Type
.
new
(
'image/x-png'
),
MIME
::
Type
.
new
(
'image/png'
)])
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
should
"prefer officially registered mime type"
do
should
"prefer officially registered mime type"
do
...
@@ -86,13 +95,17 @@ class FileAdapterTest < Test::Unit::TestCase
...
@@ -86,13 +95,17 @@ class FileAdapterTest < Test::Unit::TestCase
context
"filename with restricted characters"
do
context
"filename with restricted characters"
do
setup
do
setup
do
file_contents
=
File
.
new
(
fixture_file
(
"animated.gif"
))
@file
=
File
.
open
(
fixture_file
(
"animated.gif"
))
do
|
file
|
@file
=
StringIO
.
new
(
file_contents
.
read
)
StringIO
.
new
(
file
.
read
)
end
@file
.
stubs
(
:original_filename
).
returns
(
'image:restricted.gif'
)
@file
.
stubs
(
:original_filename
).
returns
(
'image:restricted.gif'
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
teardown
{
@file
.
close
}
teardown
do
@file
.
close
@subject
.
close
end
should
"not generate filenames that include restricted characters"
do
should
"not generate filenames that include restricted characters"
do
assert_equal
'image_restricted.gif'
,
@subject
.
original_filename
assert_equal
'image_restricted.gif'
,
@subject
.
original_filename
...
@@ -109,7 +122,10 @@ class FileAdapterTest < Test::Unit::TestCase
...
@@ -109,7 +122,10 @@ class FileAdapterTest < Test::Unit::TestCase
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
@subject
=
Paperclip
.
io_adapters
.
for
(
@file
)
end
end
teardown
{
@file
.
close
}
teardown
do
@file
.
close
@subject
.
close
end
should
"provide correct mime-type"
do
should
"provide correct mime-type"
do
assert_match
%r{.*/x-empty}
,
@subject
.
content_type
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
...
@@ -4,6 +4,7 @@ class AttachmentContentTypeValidatorTest < Test::Unit::TestCase
def
setup
def
setup
rebuild_model
rebuild_model
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
super
end
end
def
build_validator
(
options
)
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