Commit 32548249 by George Brocklehurst Committed by Mike Burns

Move Tasks registration to HasAttachedFile.

parent 232cacb7
......@@ -175,8 +175,6 @@ module Paperclip
def has_attached_file(name, options = {})
HasAttachedFile.define_on(self, name, options)
Paperclip::Tasks::Attachments.add(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) }
......
......@@ -16,6 +16,7 @@ module Paperclip
define_setter
define_query
check_for_path_clash
register_with_rake_tasks
end
private
......@@ -67,5 +68,9 @@ module Paperclip
def check_for_path_clash
Paperclip.check_for_path_clash(@name, @options[:path], @klass.name)
end
def register_with_rake_tasks
Paperclip::Tasks::Attachments.add(@klass, @name, @options)
end
end
end
......@@ -22,6 +22,10 @@ class HasAttachedFileTest < Test::Unit::TestCase
should 'check for a path collision' do
assert_adding_attachment('avatar').checks_for_path_collision
end
should 'register the attachment with Paperclip::Tasks' do
assert_adding_attachment('avatar').registers_with_tasks
end
end
private
......@@ -69,6 +73,17 @@ class HasAttachedFileTest < Test::Unit::TestCase
end
end
def registers_with_tasks
a_class = stub_class
Paperclip::Tasks::Attachments.stubs(:add)
Paperclip::HasAttachedFile.define_on(a_class, @attachment_name, {size: 1})
assert_received(Paperclip::Tasks::Attachments, :add) do |expect|
expect.with(a_class, @attachment_name, {size: 1})
end
end
private
def stub_class
......
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