Merge pull request #86 from pivotalhalogen/master

Fixing index-based access to decorated collections
This commit is contained in:
Jeff Casimir 2011-11-30 08:27:14 -08:00
commit 524fc97bdb
2 changed files with 10 additions and 0 deletions

View File

@ -26,6 +26,10 @@ module Draper
@wrapped_collection == other @wrapped_collection == other
end end
def [](index)
@klass.new(@wrapped_collection[index], @context)
end
def to_s def to_s
"#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>" "#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
end end

View File

@ -310,6 +310,12 @@ describe Draper::Base do
subject_one.should_not == subject_two subject_one.should_not == subject_two
end end
it "should allow decorated access by index" do
subject = ProductDecorator.decorate(paged_array)
subject[0].should be_instance_of ProductDecorator
end
context '#all' do context '#all' do
it "should return a decorated collection" do it "should return a decorated collection" do
ProductDecorator.all.first.should be_instance_of ProductDecorator ProductDecorator.all.first.should be_instance_of ProductDecorator