Commit 5046dfcb by George Brocklehurst Committed by Mike Burns

Move after_save callback to HasAttachedFile

parent 32548249
......@@ -175,7 +175,6 @@ module Paperclip
def has_attached_file(name, options = {})
HasAttachedFile.define_on(self, name, options)
after_save { send(name).send(:save) }
before_destroy { send(name).send(:queue_all_for_delete) }
after_destroy { send(name).send(:flush_deletes) }
......
......@@ -17,6 +17,7 @@ module Paperclip
define_query
check_for_path_clash
register_with_rake_tasks
add_active_record_callbacks
end
private
......@@ -72,5 +73,10 @@ module Paperclip
def register_with_rake_tasks
Paperclip::Tasks::Attachments.add(@klass, @name, @options)
end
def add_active_record_callbacks
name = @name
@klass.send(:after_save) { send(name).send(:save) }
end
end
end
......@@ -26,6 +26,10 @@ class HasAttachedFileTest < Test::Unit::TestCase
should 'register the attachment with Paperclip::Tasks' do
assert_adding_attachment('avatar').registers_with_tasks
end
should 'define an after_save callback' do
assert_adding_attachment('avatar').defines_callback('after_save')
end
end
private
......@@ -84,12 +88,23 @@ class HasAttachedFileTest < Test::Unit::TestCase
end
end
def defines_callback(callback_name)
a_class = stub_class
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {})
assert_received(a_class, callback_name.to_sym)
end
private
def stub_class
stub('class',
validates_each: nil,
define_method: nil,
after_save: nil,
before_destroy: nil,
after_destroy: nil,
name: 'Billy')
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