mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Decorated collection also responds to decorated_with?
This commit is contained in:
parent
07e19ccfbf
commit
a5d146c6dc
2 changed files with 16 additions and 0 deletions
|
@ -66,6 +66,13 @@ module Draper
|
|||
true
|
||||
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)
|
||||
decorated_collection.kind_of?(klass) || super
|
||||
end
|
||||
|
|
|
@ -243,6 +243,15 @@ module Draper
|
|||
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
|
||||
it 'asks the kind of its decorated collection' do
|
||||
decorator = ProductsDecorator.new([])
|
||||
|
|
Loading…
Reference in a new issue