Commit cd856aa0 by Prem Sichanugrist

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

Closes #602
parent 898baf2c
......@@ -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"
......
......@@ -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
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)
instance.save
if Rails.version >= "3.0.0"
instance.save(:validate => false)
else
instance.save(false)
end
end
end
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment