Merge pull request #584 from mschuerig/master

Inherit decorator from superclass.
This commit is contained in:
Steve Klabnik 2014-06-01 12:06:39 +03:00
commit f260f211f2
3 changed files with 13 additions and 2 deletions

View File

@ -75,8 +75,12 @@ module Draper
decorator_name = "#{prefix}Decorator"
decorator_name.constantize
rescue NameError => error
raise unless error.missing_name?(decorator_name)
raise Draper::UninferrableDecoratorError.new(self)
if superclass.respond_to?(:decorator_class)
superclass.decorator_class
else
raise unless error.missing_name?(decorator_name)
raise Draper::UninferrableDecoratorError.new(self)
end
end
# Compares with possibly-decorated objects.

View File

@ -152,6 +152,12 @@ module Draper
it "infers the decorator from the class" do
expect(Product.decorator_class).to be ProductDecorator
end
context "without a decorator on its own" do
it "infers the decorator from a superclass" do
expect(SpecialProduct.decorator_class).to be ProductDecorator
end
end
end
context "for ActiveModel classes" do

View File

@ -13,6 +13,7 @@ end
class Model; include Draper::Decoratable; end
class Product < Model; end
class SpecialProduct < Product; end
class ProductDecorator < Draper::Decorator; end
class ProductsDecorator < Draper::CollectionDecorator; end