diff --git a/lib/draper/decorated_enumerable_proxy.rb b/lib/draper/decorated_enumerable_proxy.rb index 91682b6..eadc1f8 100644 --- a/lib/draper/decorated_enumerable_proxy.rb +++ b/lib/draper/decorated_enumerable_proxy.rb @@ -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 "#" end end -end \ No newline at end of file +end diff --git a/spec/base_spec.rb b/spec/base_spec.rb index 7544b7f..691507f 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -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