Permalink
Browse files

Merge pull request #497 from haines/collection-decorator-kind-of

Delegate CollectionDecorator#kind_of? to the underlying decorated collection
  • Loading branch information...
2 parents 942182e + 63721db commit d5975f2c5b810306a96d9485fd39d550896dc2a1 @steveklabnik steveklabnik committed Mar 11, 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
@@ -71,6 +71,11 @@ def decorated?
true
end
+ def kind_of?(klass)
+ decorated_collection.kind_of?(klass) || super
+ end
+ alias_method :is_a?, :kind_of?
+
protected
# @return the collection being decorated.
@@ -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 d5975f2

Please sign in to comment.