Permalink
Browse files

Bugfix for #106 - alias_method chain needs app name in method name

  • Loading branch information...
1 parent 61090ae commit 567e251b25f18dea456bf5ba9207620c603a9047 Mark Evans committed Mar 4, 2012
Showing with 36 additions and 16 deletions.
  1. +5 −4 lib/dragonfly/app.rb
  2. +31 −12 spec/dragonfly/active_model_extensions/model_spec.rb
View
@@ -138,13 +138,14 @@ def define_macro(mod, macro_name)
def define_macro_on_include(mod, macro_name)
app = self
+ name = self.name
(class << mod; self; end).class_eval do
- alias included_without_dragonfly included
- define_method :included_with_dragonfly do |mod|
- included_without_dragonfly(mod)
+ alias_method "included_without_dragonfly_#{name}", :included
+ define_method "included_with_dragonfly_#{name}" do |mod|
+ send "included_without_dragonfly_#{name}", mod
app.define_macro(mod, macro_name)
end
- alias included included_with_dragonfly
+ alias_method :included, "included_with_dragonfly_#{name}"
end
end
@@ -49,18 +49,37 @@ def set_up_item_class(app=test_app)
end
end
- it "should work for included modules (e.g. Mongoid::Document)" do
- mongoid_document = Module.new
- app1.define_macro_on_include(mongoid_document, :dog_accessor)
- model_class = Class.new do
- def self.before_save(*args); end
- def self.before_destroy(*args); end
- include mongoid_document
- dog_accessor :doogie
- end
- klass = model_class.dragonfly_attachment_classes.first
- klass.app.should == app1
- klass.attribute.should == :doogie
+ describe "included modules (e.g. Mongoid::Document)" do
+
+ it "should work" do
+ mongoid_document = Module.new
+ app1.define_macro_on_include(mongoid_document, :dog_accessor)
+ model_class = Class.new do
+ def self.before_save(*args); end
+ def self.before_destroy(*args); end
+ include mongoid_document
+ dog_accessor :doogie
+ end
+ klass = model_class.dragonfly_attachment_classes.first
+ klass.app.should == app1
+ klass.attribute.should == :doogie
+ end
+
+ it "should work with two apps" do
+ mongoid_document = Module.new
+ app1.define_macro_on_include(mongoid_document, :image_accessor)
+ app2.define_macro_on_include(mongoid_document, :video_accessor)
+ model_class = Class.new do
+ def self.before_save(*args); end
+ def self.before_destroy(*args); end
+ include mongoid_document
+ image_accessor :doogie
+ video_accessor :boogie
+ end
+ model_class.dragonfly_attachment_classes[0].app.should == app1
+ model_class.dragonfly_attachment_classes[1].app.should == app2
+ end
+
end
end

0 comments on commit 567e251

Please sign in to comment.