Skip to content

Commit

Permalink
Merge pull request #86 from pivotalhalogen/master
Browse files Browse the repository at this point in the history
Fixing index-based access to decorated collections
  • Loading branch information
jcasimir committed Nov 30, 2011
2 parents 948160a + 340a5e6 commit 524fc97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/draper/decorated_enumerable_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def ==(other)
@wrapped_collection == other
end

def [](index)
@klass.new(@wrapped_collection[index], @context)
end

def to_s
"#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
end
Expand Down
6 changes: 6 additions & 0 deletions spec/draper/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ module Paginator; def page_number; "magic_value"; end; end
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
Expand Down

0 comments on commit 524fc97

Please sign in to comment.