Allow index access into enumerable proxy

This commit is contained in:
Albert Peng & JR Boyens 2011-11-23 15:03:32 -08:00
parent 78b200a84f
commit 340a5e6f79
2 changed files with 10 additions and 0 deletions

View File

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

View File

@ -269,6 +269,12 @@ describe Draper::Base do
subject_one.should_not == subject_two
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
it "should return a decorated collection" do
ProductDecorator.all.first.should be_instance_of ProductDecorator