Overwrite #kind_of? and #is_a?

This commit is contained in:
Tobias Maier 2011-12-07 16:18:06 +01:00
parent f42f670812
commit db7f7f843e
2 changed files with 25 additions and 0 deletions

View File

@ -21,6 +21,11 @@ module Draper
def respond_to?(method)
super || @wrapped_collection.respond_to?(method)
end
def kind_of?(klass)
@wrapped_collection.kind_of?(klass) || super(klass)
end
alias :is_a? :kind_of?
def ==(other)
@wrapped_collection == other

View File

@ -314,6 +314,26 @@ describe Draper::Base do
subject = ProductDecorator.decorate(paged_array)
subject[0].should be_instance_of ProductDecorator
end
context "pretends to be of kind of wrapped collection class" do
subject { ProductDecorator.decorate(paged_array) }
it "#kind_of? DecoratedEnumerableProxy" do
subject.should be_kind_of Draper::DecoratedEnumerableProxy
end
it "#is_a? DecoratedEnumerableProxy" do
subject.is_a?(Draper::DecoratedEnumerableProxy).should be_true
end
it "#kind_of? Array" do
subject.should be_kind_of Array
end
it "#is_a? Array" do
subject.is_a?(Array).should be_true
end
end
context '#all' do
it "should return a decorated collection" do