From 340a5e6f793c9ad00a26f90485b561265c8d3277 Mon Sep 17 00:00:00 2001 From: Albert Peng & JR Boyens Date: Wed, 23 Nov 2011 15:03:32 -0800 Subject: [PATCH] Allow index access into enumerable proxy --- lib/draper/decorated_enumerable_proxy.rb | 4 ++++ spec/draper/base_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/lib/draper/decorated_enumerable_proxy.rb b/lib/draper/decorated_enumerable_proxy.rb index 73bbe1b8..023995dd 100644 --- a/lib/draper/decorated_enumerable_proxy.rb +++ b/lib/draper/decorated_enumerable_proxy.rb @@ -26,6 +26,10 @@ def ==(other) @wrapped_collection == other end + def [](index) + @klass.new(@wrapped_collection[index], @context) + end + def to_s "#" end diff --git a/spec/draper/base_spec.rb b/spec/draper/base_spec.rb index 02cc01a2..4e6d71f0 100644 --- a/spec/draper/base_spec.rb +++ b/spec/draper/base_spec.rb @@ -269,6 +269,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