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
f820685d
Commit
f820685d
authored
Feb 20, 2013
by
Michael Dotterer
Committed by
Jon Yurek
Feb 22, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reset instance attributes when clearing attachment with preserve_files
parent
30080c4a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
lib/paperclip/attachment.rb
+3
-3
test/attachment_test.rb
+6
-0
No files found.
lib/paperclip/attachment.rb
View file @
f820685d
...
@@ -233,11 +233,9 @@ module Paperclip
...
@@ -233,11 +233,9 @@ module Paperclip
# 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
# wipe out the existing attachment but not save, use #clear.
# wipe out the existing attachment but not save, use #clear.
def
destroy
def
destroy
unless
@options
[
:preserve_files
]
clear
clear
save
save
end
end
end
# Returns the uploaded file if present.
# Returns the uploaded file if present.
def
uploaded_file
def
uploaded_file
...
@@ -454,10 +452,12 @@ module Paperclip
...
@@ -454,10 +452,12 @@ module Paperclip
end
end
def
queue_all_for_delete
#:nodoc:
def
queue_all_for_delete
#:nodoc:
return
if
@options
[
:preserve_files
]
||
!
file?
return
if
!
file?
unless
@options
[
:preserve_files
]
@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
)
end
.
compact
end
.
compact
end
instance_write
(
:file_name
,
nil
)
instance_write
(
:file_name
,
nil
)
instance_write
(
:content_type
,
nil
)
instance_write
(
:content_type
,
nil
)
instance_write
(
:file_size
,
nil
)
instance_write
(
:file_size
,
nil
)
...
...
test/attachment_test.rb
View file @
f820685d
...
@@ -1324,6 +1324,12 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -1324,6 +1324,12 @@ class AttachmentTest < Test::Unit::TestCase
assert_file_exists
(
@path
)
assert_file_exists
(
@path
)
end
end
should
"clear out attachment data when attachment is destroyed"
do
@attachment
.
destroy
assert
!
@attachment
.
exists?
assert_nil
@dummy
.
avatar_file_name
end
should
"not delete the file when model is destroyed"
do
should
"not delete the file when model is destroyed"
do
@dummy
.
destroy
@dummy
.
destroy
assert_file_exists
(
@path
)
assert_file_exists
(
@path
)
...
...
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