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 ...@@ -47,7 +47,6 @@ Feature: Rake tasks
Then the attachment file "original/5k.png" should exist Then the attachment file "original/5k.png" should exist
And the attachment file "medium/5k.png" should exist And the attachment file "medium/5k.png" should exist
@wip
Scenario: Paperclip clean task Scenario: Paperclip clean task
When I upload the fixture "5k.png" When I upload the fixture "5k.png"
And I upload the fixture "12k.png" And I upload the fixture "12k.png"
......
...@@ -84,12 +84,16 @@ namespace :paperclip do ...@@ -84,12 +84,16 @@ namespace :paperclip do
names = Paperclip::Task.obtain_attachments(klass) names = Paperclip::Task.obtain_attachments(klass)
names.each do |name| names.each do |name|
Paperclip.each_instance_with_attachment(klass, name) do |instance| Paperclip.each_instance_with_attachment(klass, name) do |instance|
instance.send(name).send(:validate) unless instance.valid?
if instance.send(name).valid? attributes = %w(file_size file_name content_type).map{ |suffix| "#{name}_#{suffix}".to_sym }
true if attributes.any?{ |attribute| instance.errors[attribute].present? }
else instance.send("#{name}=", nil)
instance.send("#{name}=", nil) if Rails.version >= "3.0.0"
instance.save instance.save(:validate => false)
else
instance.save(false)
end
end
end 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