Introduce respond_to? on DecoratedEnumerableProxy

This commit is contained in:
Jonathan Greenberg and Lake Denman 2011-10-20 17:22:05 -04:00 committed by Entryway Pair
parent ca5c538133
commit bdfc9683c9
2 changed files with 19 additions and 1 deletions

View File

@ -20,8 +20,12 @@ module Draper
@wrapped_collection.send(meth, *args, &block)
end
def respond_to?(meth)
super || @wrapped_collection.respond_to?(meth)
end
def to_s
"#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
end
end
end
end

View File

@ -188,6 +188,7 @@ describe Draper::Base do
module Paginator; def page_number; "magic_value"; end; end
Array.send(:include, Paginator)
let(:paged_array) { [Product.new, Product.new] }
let(:empty_collection) { [] }
subject { ProductDecorator.decorate(paged_array) }
it "should proxy all calls to decorated collection" do
@ -201,6 +202,19 @@ describe Draper::Base do
subject.respond_to?(:to_ary).should be true
subject.to_a.first.should == ProductDecorator.decorate(paged_array.first)
end
it "should delegate respond_to? to the wrapped collection" do
decorator = ProductDecorator.decorate(paged_array)
paged_array.should_receive(:respond_to?).with(:whatever)
decorator.respond_to?(:whatever)
end
it "should return blank for a decorated empty collection" do
# This tests that respond_to? is defined for the DecoratedEnumerableProxy
# since activesupport calls respond_to?(:empty) in #blank
decorator = ProductDecorator.decorate(empty_collection)
decorator.should be_blank
end
end
describe "a sample usage with denies" do