Permalink
Browse files

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

Closes #602
  • Loading branch information...
1 parent 898baf2 commit cd856aa021aaf053ca4b99e56894822615458585 @sikachu sikachu committed Oct 14, 2011
Showing with 10 additions and 7 deletions.
  1. +0 −1 features/rake_tasks.feature
  2. +10 −6 lib/tasks/paperclip.rake
@@ -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
@@ -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

0 comments on commit cd856aa

Please sign in to comment.