diff --git a/lib/draper/automatic_delegation.rb b/lib/draper/automatic_delegation.rb index 41e0e71..8f8d65e 100644 --- a/lib/draper/automatic_delegation.rb +++ b/lib/draper/automatic_delegation.rb @@ -6,7 +6,7 @@ module Draper def method_missing(method, *args, &block) return super unless delegatable?(method) - self.class.delegate method + self.singleton_class.delegate method send(method, *args, &block) end diff --git a/spec/draper/decorator_spec.rb b/spec/draper/decorator_spec.rb index 36eb83e..13d3067 100755 --- a/spec/draper/decorator_spec.rb +++ b/spec/draper/decorator_spec.rb @@ -604,6 +604,14 @@ module Draper expect(decorator.methods).to include :hello_world end + it "allows decorator to decorate different classes of objects" do + decorator_1 = Decorator.new(double) + decorator_2 = Decorator.new(double(hello_world: :delegated)) + + decorator_2.hello_world + expect(decorator_1.methods).not_to include :hello_world + end + it "passes blocks to delegated methods" do object = Model.new object.stub(:hello_world) { |*args, &block| block.call }