1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Merge pull request #539 from pmcneill/is_decoratable

Add `decorator_class?` method to Decoratable
This commit is contained in:
Andrew Haines 2013-05-20 02:23:28 -07:00
commit 9ce96c8fd4
2 changed files with 30 additions and 0 deletions

View file

@ -23,6 +23,10 @@ module Draper
self.class.decorator_class
end
def decorator_class?
self.class.decorator_class?
end
# The list of decorators that have been applied to the object.
#
# @return [Array<Class>] `[]`
@ -56,6 +60,12 @@ module Draper
decorator_class.decorate_collection(collection, options.reverse_merge(with: nil))
end
def decorator_class?
decorator_class
rescue Draper::UninferrableDecoratorError
false
end
# Infers the decorator class to be used by {Decoratable#decorate} (e.g.
# `Product` maps to `ProductDecorator`).
#

View file

@ -46,6 +46,26 @@ module Draper
end
end
describe "#decorator_class?" do
it "returns true for decoratable model" do
expect(Product.new.decorator_class?).to be_true
end
it "returns false for non-decoratable model" do
expect(Model.new.decorator_class?).to be_false
end
end
describe ".decorator_class?" do
it "returns true for decoratable model" do
expect(Product.decorator_class?).to be_true
end
it "returns false for non-decoratable model" do
expect(Model.decorator_class?).to be_false
end
end
describe "#decorator_class" do
it "delegates to .decorator_class" do
product = Product.new