Decorated collection also responds to decorated_with?

This commit is contained in:
David Rueck 2013-03-13 16:04:10 -07:00
parent 07e19ccfbf
commit a5d146c6dc
2 changed files with 16 additions and 0 deletions

View File

@ -66,6 +66,13 @@ module Draper
true true
end end
# Checks if a given decorator has been applied to the collection.
#
# @param [Class] decorator_class
def decorated_with?(decorator_class)
self.instance_of? decorator_class
end
def kind_of?(klass) def kind_of?(klass)
decorated_collection.kind_of?(klass) || super decorated_collection.kind_of?(klass) || super
end end

View File

@ -243,6 +243,15 @@ module Draper
end end
end end
describe '#decorated_with?' do
it "checks if a decorator has been applied to a collection" do
decorator = ProductsDecorator.new([Product.new])
expect(decorator).to be_decorated_with ProductsDecorator
expect(decorator).not_to be_decorated_with OtherDecorator
end
end
describe '#kind_of?' do describe '#kind_of?' do
it 'asks the kind of its decorated collection' do it 'asks the kind of its decorated collection' do
decorator = ProductsDecorator.new([]) decorator = ProductsDecorator.new([])