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
9324ba89
Commit
9324ba89
authored
Dec 29, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove empty directories when possible.
parent
b8506d36
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
lib/paperclip/storage.rb
+8
-0
test/integration_test.rb
+40
-0
No files found.
lib/paperclip/storage.rb
View file @
9324ba89
...
...
@@ -56,6 +56,14 @@ module Paperclip
rescue
Errno
::
ENOENT
=>
e
# ignore file-not-found, let everything else pass
end
begin
while
(
true
)
path
=
File
.
dirname
(
path
)
FileUtils
.
rmdir
(
path
)
end
rescue
Errno
::
ENOTEMPTY
,
Errno
::
ENOENT
,
Errno
::
EINVAL
# Stop trying to remove parent directories
end
end
@queued_for_delete
=
[]
end
...
...
test/integration_test.rb
View file @
9324ba89
...
...
@@ -49,6 +49,46 @@ class IntegrationTest < Test::Unit::TestCase
end
end
context
"A model with attachments scoped under an id"
do
setup
do
rebuild_model
:styles
=>
{
:large
=>
"100x100"
,
:medium
=>
"50x50"
},
:path
=>
":rails_root/tmp/:id/:attachments/:style.:extension"
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
),
'rb'
)
@dummy
.
avatar
=
@file
end
context
"when saved"
do
setup
do
@dummy
.
save
@saved_path
=
@dummy
.
avatar
.
path
(
:large
)
end
should
"have a large file in the right place"
do
assert
File
.
exists?
(
@dummy
.
avatar
.
path
(
:large
))
end
context
"and deleted"
do
setup
do
@dummy
.
avatar
=
nil
@dummy
.
save
end
should
"not have a large file in the right place anymore"
do
assert
!
File
.
exists?
(
@saved_path
)
end
should
"not have its next two parent directories"
do
assert
!
File
.
exists?
(
File
.
dirname
(
@saved_path
))
assert
!
File
.
exists?
(
File
.
dirname
(
File
.
dirname
(
@saved_path
)))
end
end
end
end
context
"A model with no attachment validation"
do
setup
do
rebuild_model
:styles
=>
{
:large
=>
"300x300>"
,
...
...
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