From f9f0982cd9c8542964e3c3bed815554f58b44408 Mon Sep 17 00:00:00 2001 From: Nisarg Shah Date: Tue, 8 May 2012 11:44:50 -0400 Subject: [PATCH] added context to enumerable --- lib/draper/decorated_enumerable_proxy.rb | 4 ++++ spec/draper/base_spec.rb | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/draper/decorated_enumerable_proxy.rb b/lib/draper/decorated_enumerable_proxy.rb index dc3b9ed..90cf47b 100644 --- a/lib/draper/decorated_enumerable_proxy.rb +++ b/lib/draper/decorated_enumerable_proxy.rb @@ -38,6 +38,10 @@ module Draper def to_s "#" end + + def context=(input) + self.map { |member| member.context = input } + end def source @wrapped_collection diff --git a/spec/draper/base_spec.rb b/spec/draper/base_spec.rb index 6e46603..e08345d 100644 --- a/spec/draper/base_spec.rb +++ b/spec/draper/base_spec.rb @@ -313,6 +313,11 @@ describe Draper::Base do it "returns a collection of wrapped objects" do subject.each{ |decorated| decorated.should be_instance_of(Draper::Base) } end + + it 'should accepted and store a context for a collection' do + subject.context = :admin + subject.each { |decorated| decorated.context.should == :admin } + end end context "when given a single source object" do