Browse files

Delegate #kind_of? to the underlying decorated collection

  • Loading branch information...
1 parent 942182e commit daabe77103214645a03ecc2bdfff0174ba1d9f70 @jtrim jtrim committed with haines Mar 3, 2013
Showing with 28 additions and 0 deletions.
  1. +5 −0 lib/draper/collection_decorator.rb
  2. +23 −0 spec/draper/collection_decorator_spec.rb
View
5 lib/draper/collection_decorator.rb
@@ -71,6 +71,11 @@ def decorated?
true
end
+ def kind_of?(klass)
+ decorated_collection.kind_of?(klass) || super
+ end
+ alias :is_a? :kind_of?
+
protected
# @return the collection being decorated.
View
23 spec/draper/collection_decorator_spec.rb
@@ -259,5 +259,28 @@ module Draper
end
end
+ describe '#kind_of?' do
+ it 'asks the kind of its decorated collection' do
+ decorator = ProductsDecorator.new([])
+ decorator.decorated_collection.should_receive(:kind_of?).with(Array).and_return("true")
+ expect(decorator.kind_of?(Array)).to eq "true"
+ end
+
+ context 'when asking the underlying collection returns false' do
+ it 'asks the CollectionDecorator instance itself' do
+ decorator = ProductsDecorator.new([])
+ decorator.decorated_collection.stub(:kind_of?).with(::Draper::CollectionDecorator).and_return(false)
+ expect(decorator.kind_of?(::Draper::CollectionDecorator)).to be true
+ end
+ end
+ end
+
+ describe '#is_a?' do
+ it 'aliases to #kind_of?' do
+ decorator = ProductsDecorator.new([])
+ expect(decorator.method(:kind_of?)).to eq decorator.method(:is_a?)
+ end
+ end
+
end
end

0 comments on commit daabe77

Please sign in to comment.