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
e705b737
Commit
e705b737
authored
Apr 24, 2012
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't delete all the existing styles if we reprocess
parent
a596c01b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
5 deletions
+35
-5
lib/paperclip/attachment.rb
+14
-4
lib/paperclip/instance_methods.rb
+1
-1
test/attachment_test.rb
+20
-0
No files found.
lib/paperclip/attachment.rb
View file @
e705b737
...
@@ -90,7 +90,7 @@ module Paperclip
...
@@ -90,7 +90,7 @@ module Paperclip
ensure_required_accessors!
ensure_required_accessors!
file
=
Paperclip
.
io_adapters
.
for
(
uploaded_file
)
file
=
Paperclip
.
io_adapters
.
for
(
uploaded_file
)
self
.
clear
self
.
clear
(
*
@options
[
:only_process
])
return
nil
if
file
.
nil?
return
nil
if
file
.
nil?
@queued_for_write
[
:original
]
=
file
@queued_for_write
[
:original
]
=
file
...
@@ -202,11 +202,15 @@ module Paperclip
...
@@ -202,11 +202,15 @@ module Paperclip
# Clears out the attachment. Has the same effect as previously assigning
# Clears out the attachment. Has the same effect as previously assigning
# nil to the attachment. Does NOT save. If you wish to clear AND save,
# nil to the attachment. Does NOT save. If you wish to clear AND save,
# use #destroy.
# use #destroy.
def
clear
def
clear
(
*
styles_to_clear
)
queue_existing_for_delete
if
styles_to_clear
.
any?
queue_some_for_delete
(
*
styles_to_clear
)
else
queue_all_for_delete
@queued_for_write
=
{}
@queued_for_write
=
{}
@errors
=
{}
@errors
=
{}
end
end
end
# Destroys the attachment. Has the same effect as previously assigning
# Destroys the attachment. Has the same effect as previously assigning
# nil to the attachment *and saving*. This is permanent. If you wish to
# nil to the attachment *and saving*. This is permanent. If you wish to
...
@@ -406,7 +410,13 @@ module Paperclip
...
@@ -406,7 +410,13 @@ module Paperclip
interpolator
.
interpolate
(
pattern
,
self
,
style_name
)
interpolator
.
interpolate
(
pattern
,
self
,
style_name
)
end
end
def
queue_existing_for_delete
#:nodoc:
def
queue_some_for_delete
(
*
styles
)
@queued_for_delete
+=
styles
.
uniq
.
map
do
|
style
|
path
(
style
)
if
exists?
(
style
)
end
.
compact
end
def
queue_all_for_delete
#:nodoc:
return
if
@options
[
:preserve_files
]
||
!
file?
return
if
@options
[
:preserve_files
]
||
!
file?
@queued_for_delete
+=
[
:original
,
*
styles
.
keys
].
uniq
.
map
do
|
style
|
@queued_for_delete
+=
[
:original
,
*
styles
.
keys
].
uniq
.
map
do
|
style
|
path
(
style
)
if
exists?
(
style
)
path
(
style
)
if
exists?
(
style
)
...
...
lib/paperclip/instance_methods.rb
View file @
e705b737
...
@@ -28,7 +28,7 @@ module Paperclip
...
@@ -28,7 +28,7 @@ module Paperclip
def
prepare_for_destroy
def
prepare_for_destroy
Paperclip
.
log
(
"Scheduling attachments for deletion."
)
Paperclip
.
log
(
"Scheduling attachments for deletion."
)
each_attachment
do
|
name
,
attachment
|
each_attachment
do
|
name
,
attachment
|
attachment
.
send
(
:queue_
existing
_for_delete
)
attachment
.
send
(
:queue_
all
_for_delete
)
end
end
end
end
end
end
...
...
test/attachment_test.rb
View file @
e705b737
...
@@ -19,6 +19,26 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -19,6 +19,26 @@ class AttachmentTest < Test::Unit::TestCase
file
.
close
file
.
close
end
end
should
"not delete styles that don't get reprocessed"
do
file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"50x50.png"
),
'rb'
)
rebuild_class
:styles
=>
{
:small
=>
'100x>'
,
:large
=>
'500x>'
,
:original
=>
'42x42#'
}
dummy
=
Dummy
.
new
dummy
.
avatar
=
file
dummy
.
save
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:small
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:large
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:original
))
dummy
.
avatar
.
reprocess!
(
:small
)
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:small
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:large
))
assert
File
.
exists?
(
dummy
.
avatar
.
path
(
:original
))
end
should
"handle a boolean second argument to #url"
do
should
"handle a boolean second argument to #url"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:url_generator
=>
mock_url_generator_builder
)
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:url_generator
=>
mock_url_generator_builder
)
...
...
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