Skip to content

Commit

Permalink
Update rake task to fix issue with rake paperclip:clean
Browse files Browse the repository at this point in the history
  • Loading branch information
sikachu committed Oct 14, 2011
1 parent 898baf2 commit cd856aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion features/rake_tasks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 10 additions & 6 deletions lib/tasks/paperclip.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cd856aa

Please sign in to comment.