jcasimir/draper — Issue #143: decorates_association does not handle polymorphism
Author: simonc
Created: 2012-03-08 12:36:31+00:00
State: open

Given the following models:

``` ruby
class Rating < AR::Base
belongs_to :rateable, polymorphic: true
end

module Concerns::Rateable
...
has_many :ratings, :as => :rateable
...
end

class Post < AR::Base
include Concerns::Rateable
end

class Thing < AR::Base
include Concerns::Rateable
end
```

and the following decorators:

``` ruby
class RatingDecorator < AppDec
decorates :rating
decorates_association :rateable
end

module Concers::RateableDecorator
def foo; ...; end
end

class PostDecorator < AppDec
decorates :post
include Concerns::RateableDecorator
end

class ThingDecorator < AppDec
decorates :thing
include Concerns::RateableDecorator
end
```

When I try to access `@rating.rateable` I get the following error:

NameError: uninitialized constant Rating::Rateable
from .../activerecord-3.2.1/lib/active_record/inheritance.rb:119:in `compute_type'
from .../activerecord-3.2.1/lib/active_record/reflection.rb:172:in `klass'
from .../draper-0.10.0/lib/draper/base.rb:69:in `block in decorates_association'
from (irb):3
from .../railties-3.2.1/lib/rails/commands/console.rb:47:in `start'
from .../railties-3.2.1/lib/rails/commands/console.rb:8:in `start'
from .../railties-3.2.1/lib/rails/commands.rb:41:in `'
from script/rails:6:in `require'
from script/rails:6:in `

'