Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update rake task to fix issue with `rake paperclip:clean`

Closes #602
  • Loading branch information...
commit cd856aa021aaf053ca4b99e56894822615458585 1 parent 898baf2
@sikachu sikachu authored
Showing with 10 additions and 7 deletions.
  1. +0 −1  features/rake_tasks.feature
  2. +10 −6 lib/tasks/paperclip.rake
View
1  features/rake_tasks.feature
@@ -47,7 +47,6 @@ Feature: Rake tasks
Then the attachment file "original/5k.png" should exist
And the attachment file "medium/5k.png" should exist
- @wip
Scenario: Paperclip clean task
When I upload the fixture "5k.png"
And I upload the fixture "12k.png"
View
16 lib/tasks/paperclip.rake
@@ -84,12 +84,16 @@ namespace :paperclip do
names = Paperclip::Task.obtain_attachments(klass)
names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance|
- instance.send(name).send(:validate)
- if instance.send(name).valid?
- true
- else
- instance.send("#{name}=", nil)
- instance.save
+ unless instance.valid?
+ attributes = %w(file_size file_name content_type).map{ |suffix| "#{name}_#{suffix}".to_sym }
+ if attributes.any?{ |attribute| instance.errors[attribute].present? }
+ instance.send("#{name}=", nil)
+ if Rails.version >= "3.0.0"
+ instance.save(:validate => false)
+ else
+ instance.save(false)
+ end
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.