Allow index access into enumerable proxy
This commit is contained in:
parent
78b200a84f
commit
340a5e6f79
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue