mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Prevent automatically delegated methods from piling up on Decorator class.
This commit is contained in:
parent
57a514133b
commit
60b0acbcaa
2 changed files with 9 additions and 1 deletions
|
@ -6,7 +6,7 @@ module Draper
|
||||||
def method_missing(method, *args, &block)
|
def method_missing(method, *args, &block)
|
||||||
return super unless delegatable?(method)
|
return super unless delegatable?(method)
|
||||||
|
|
||||||
self.class.delegate method
|
self.singleton_class.delegate method
|
||||||
send(method, *args, &block)
|
send(method, *args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -604,6 +604,14 @@ module Draper
|
||||||
expect(decorator.methods).to include :hello_world
|
expect(decorator.methods).to include :hello_world
|
||||||
end
|
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
|
it "passes blocks to delegated methods" do
|
||||||
object = Model.new
|
object = Model.new
|
||||||
object.stub(:hello_world) { |*args, &block| block.call }
|
object.stub(:hello_world) { |*args, &block| block.call }
|
||||||
|
|
Loading…
Add table
Reference in a new issue