Merge pull request #584 from mschuerig/master
Inherit decorator from superclass.
This commit is contained in:
commit
f260f211f2
|
@ -75,9 +75,13 @@ module Draper
|
||||||
decorator_name = "#{prefix}Decorator"
|
decorator_name = "#{prefix}Decorator"
|
||||||
decorator_name.constantize
|
decorator_name.constantize
|
||||||
rescue NameError => error
|
rescue NameError => error
|
||||||
|
if superclass.respond_to?(:decorator_class)
|
||||||
|
superclass.decorator_class
|
||||||
|
else
|
||||||
raise unless error.missing_name?(decorator_name)
|
raise unless error.missing_name?(decorator_name)
|
||||||
raise Draper::UninferrableDecoratorError.new(self)
|
raise Draper::UninferrableDecoratorError.new(self)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Compares with possibly-decorated objects.
|
# Compares with possibly-decorated objects.
|
||||||
#
|
#
|
||||||
|
|
|
@ -152,6 +152,12 @@ module Draper
|
||||||
it "infers the decorator from the class" do
|
it "infers the decorator from the class" do
|
||||||
expect(Product.decorator_class).to be ProductDecorator
|
expect(Product.decorator_class).to be ProductDecorator
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "for ActiveModel classes" do
|
context "for ActiveModel classes" do
|
||||||
|
|
|
@ -13,6 +13,7 @@ end
|
||||||
class Model; include Draper::Decoratable; end
|
class Model; include Draper::Decoratable; end
|
||||||
|
|
||||||
class Product < Model; end
|
class Product < Model; end
|
||||||
|
class SpecialProduct < Product; end
|
||||||
class ProductDecorator < Draper::Decorator; end
|
class ProductDecorator < Draper::Decorator; end
|
||||||
class ProductsDecorator < Draper::CollectionDecorator; end
|
class ProductsDecorator < Draper::CollectionDecorator; end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue