Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- Fixing edge callback changes issue (see http://dev.rubyonrails.org/…

…changeset/8664)

- Fix rmagick assertion
  • Loading branch information...
commit ee8474831d3181596220f2b970a707730b851950 1 parent b0da755
@nicksieger nicksieger authored
View
1  .gitignore
@@ -0,0 +1 @@
+test/debug.log
View
96 lib/technoweenie/attachment_fu.rb
@@ -116,41 +116,47 @@ def image?(content_type)
content_types.include?(content_type)
end
- # Callback after an image has been resized.
- #
- # class Foo < ActiveRecord::Base
- # acts_as_attachment
- # after_resize do |record, img|
- # record.aspect_ratio = img.columns.to_f / img.rows.to_f
- # end
- # end
- def after_resize(&block)
- write_inheritable_array(:after_resize, [block])
- end
+ if defined?(::ActiveSupport::Callbacks)
+ def self.extended(base)
+ base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
+ end
+ else
+ # Callback after an image has been resized.
+ #
+ # class Foo < ActiveRecord::Base
+ # acts_as_attachment
+ # after_resize do |record, img|
+ # record.aspect_ratio = img.columns.to_f / img.rows.to_f
+ # end
+ # end
+ def after_resize(&block)
+ write_inheritable_array(:after_resize, [block])
+ end
- # Callback after an attachment has been saved either to the file system or the DB.
- # Only called if the file has been changed, not necessarily if the record is updated.
- #
- # class Foo < ActiveRecord::Base
- # acts_as_attachment
- # after_attachment_saved do |record|
- # ...
- # end
- # end
- def after_attachment_saved(&block)
- write_inheritable_array(:after_attachment_saved, [block])
- end
+ # Callback after an attachment has been saved either to the file system or the DB.
+ # Only called if the file has been changed, not necessarily if the record is updated.
+ #
+ # class Foo < ActiveRecord::Base
+ # acts_as_attachment
+ # after_attachment_saved do |record|
+ # ...
+ # end
+ # end
+ def after_attachment_saved(&block)
+ write_inheritable_array(:after_attachment_saved, [block])
+ end
- # Callback before a thumbnail is saved. Use this to pass any necessary extra attributes that may be required.
- #
- # class Foo < ActiveRecord::Base
- # acts_as_attachment
- # before_thumbnail_saved do |record, thumbnail|
- # ...
- # end
- # end
- def before_thumbnail_saved(&block)
- write_inheritable_array(:before_thumbnail_saved, [block])
+ # Callback before a thumbnail is saved. Use this to pass any necessary extra attributes that may be required.
+ #
+ # class Foo < ActiveRecord::Base
+ # acts_as_attachment
+ # before_thumbnail_saved do |record, thumbnail|
+ # ...
+ # end
+ # end
+ def before_thumbnail_saved(&block)
+ write_inheritable_array(:before_thumbnail_saved, [block])
+ end
end
# Get the thumbnail class, which is the current attachment class by default.
@@ -397,10 +403,30 @@ def callback_with_args(method, arg = self)
result = callback.call(self, arg)
return false if result == false
end
+ result
+ end
- return result
+ # Rather ugly monkey-patch of AS::Callbacks to support taking an arg
+ if defined?(::ActiveSupport::Callbacks)
+ def callbacks_for(method) #:nodoc: compatibility method
+ self.class.send("#{method}_callback_chain")
+ end
+ class ::ActiveSupport::Callbacks::Callback
+ # Make callbacks accept arguments, but only pass them along to procs for now
+ def call(object, *args)
+ if should_run_callback?(object)
+ case method
+ when Proc
+ args = [object, *args].compact
+ method.call(*args)
+ else
+ evaluate_method(method, object)
+ end
+ end
+ end
+ end
end
-
+
# Removes the thumbnails for the attachment, if it has any
def destroy_thumbnails
self.thumbnails.each { |thumbnail| thumbnail.destroy } if thumbnailable?
View
2  test/processors/rmagick_test.rb
@@ -162,7 +162,7 @@ def test_should_use_thumbnail_subclass(klass = ImageWithThumbsClassFileAttachmen
assert_equal 'rails_thumb.png', attachment.thumbnails.first.filename
assert_equal attachment.thumbnails.first.full_filename, attachment.full_filename(attachment.thumbnails.first.thumbnail),
"#full_filename does not use thumbnail class' path."
- assert_equal attachment.destroy attachment
+ assert_equal attachment.destroy, attachment
end
test_against_subclass :test_should_use_thumbnail_subclass, ImageWithThumbsClassFileAttachment
Please sign in to comment.
Something went wrong with that request. Please try again.