Decorated collection also responds to decorated_with?
This commit is contained in:
parent
07e19ccfbf
commit
a5d146c6dc
|
@ -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
|
||||||
|
|
|
@ -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([])
|
||||||
|
|
Loading…
Reference in New Issue