diff --git a/lib/draper/automatic_delegation.rb b/lib/draper/automatic_delegation.rb index 8d62faf..bd78884 100644 --- a/lib/draper/automatic_delegation.rb +++ b/lib/draper/automatic_delegation.rb @@ -20,7 +20,7 @@ module Draper # @private def delegatable?(method) - return if private_methods.include?(method) + return if private_methods(false).include?(method) object.respond_to?(method) end diff --git a/spec/draper/decorator_spec.rb b/spec/draper/decorator_spec.rb index 0f50aa4..9517ee3 100644 --- a/spec/draper/decorator_spec.rb +++ b/spec/draper/decorator_spec.rb @@ -684,6 +684,18 @@ module Draper expect{ decorator.hello_world }.to raise_error NoMethodError end end + + context 'when delegated method has the same name as private method defined on another object' do + let(:decorator_class) { Class.new(Decorator) } + let(:object) { Class.new { def print; end }.new } + + it 'delegates the public method defined on the object' do + decorator = decorator_class.new(object) + + # `print` private method is defined on `Object` + expect{ decorator.print }.not_to raise_error NoMethodError + end + end end context ".method_missing" do