jcasimir/draper — Issue #51: model.foo doesn't work with twice decorated model
Author: henrik
Created: 2011-10-17 10:52:54+00:00
State: open

Say I do something like

class ItemDecorator < ApplicationDecorator
decorates :item

def pretty_title
model.title.upcase
end

end

class ItemSubscriptionDecorator < ItemDecorator
decorates :item

def subscription_rates
1.upto(model.max_rate).to_a
end

end

Now, if I do

d = ItemSubscriptionDecorator.new(i)
d.pretty_title
d.subscription_rates

then everything works fine. But if I do

c = ItemDecorator.new(i)
d = ItemSubscriptionDecorator.new(c)
d.pretty_title
d.subscription_rates

then the last line will complain about `undefined local variable or method `max_rate` for <123:ItemSubscriptionDecorator>`.

I'm guessing it uses `respond_to?` on whatever is decorated, instead of following the model chain to its root first.

The above might not have been an intended use case, but I think it makes sense to be able to add layers of decoration as you need them. I might only need ItemDecorator in most of the controller/view, but then it renders one partial which needs ItemSubscriptionDecorator.

Might look into this later but only reporting for now.