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
1544a7b2
Commit
1544a7b2
authored
Nov 30, 2012
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't process if the attachment isn't valid.
parent
3f4180ef
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
lib/paperclip/attachment.rb
+9
-3
test/attachment_processing_test.rb
+29
-0
No files found.
lib/paperclip/attachment.rb
View file @
1544a7b2
...
@@ -105,7 +105,7 @@ module Paperclip
...
@@ -105,7 +105,7 @@ module Paperclip
@dirty
=
true
@dirty
=
true
post_process
(
*
only_process
)
if
post_processing
post_process
(
*
only_process
)
if
post_processing
&&
valid_assignment?
# Reset the file size if the original file was reprocessed.
# Reset the file size if the original file was reprocessed.
instance_write
(
:file_size
,
@queued_for_write
[
:original
].
size
)
instance_write
(
:file_size
,
@queued_for_write
[
:original
].
size
)
...
@@ -369,8 +369,14 @@ module Paperclip
...
@@ -369,8 +369,14 @@ module Paperclip
Paperclip
.
log
(
message
)
Paperclip
.
log
(
message
)
end
end
def
valid_assignment?
file
#:nodoc:
def
valid_assignment?
#:nodoc:
file
.
nil?
||
(
file
.
respond_to?
(
:original_filename
)
&&
file
.
respond_to?
(
:content_type
))
if
instance
.
valid?
true
else
instance
.
errors
.
none?
do
|
attr
,
message
|
attr
.
to_s
.
start_with?
(
@name
.
to_s
)
end
end
end
end
def
initialize_storage
#:nodoc:
def
initialize_storage
#:nodoc:
...
...
test/attachment_processing_test.rb
0 → 100644
View file @
1544a7b2
# encoding: utf-8
require
'./test/helper'
require
'paperclip/attachment'
class
AttachmentProcessingTest
<
Test
::
Unit
::
TestCase
def
setup
rebuild_model
end
should
'process attachments given a valid assignment'
do
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
"image/png"
instance
=
Dummy
.
new
attachment
=
instance
.
avatar
attachment
.
expects
(
:post_process
)
attachment
.
assign
(
file
)
end
should
'not process attachments if the assignment does not pass validation'
do
file
=
File
.
new
(
fixture_file
(
"5k.png"
))
Dummy
.
validates_attachment_content_type
:avatar
,
:content_type
=>
"image/tiff"
instance
=
Dummy
.
new
attachment
=
instance
.
avatar
attachment
.
expects
(
:post_process
).
never
attachment
.
assign
(
file
)
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