Merge pull request #86 from pivotalhalogen/master
Fixing index-based access to decorated collections
This commit is contained in:
commit
524fc97bdb
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue