Overwrite #kind_of? and #is_a?
This commit is contained in:
parent
f42f670812
commit
db7f7f843e
|
@ -22,6 +22,11 @@ module Draper
|
|||
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
|
||||
end
|
||||
|
|
|
@ -315,6 +315,26 @@ describe Draper::Base do
|
|||
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
|
||||
ProductDecorator.all.first.should be_instance_of ProductDecorator
|
||||
|
|
Loading…
Reference in New Issue