added context to enumerable

This commit is contained in:
Nisarg Shah 2012-05-08 11:44:50 -04:00
parent 15992b8e34
commit f9f0982cd9
2 changed files with 9 additions and 0 deletions

View File

@ -38,6 +38,10 @@ module Draper
def to_s
"#<DecoratedEnumerableProxy of #{@klass} for #{@wrapped_collection.inspect}>"
end
def context=(input)
self.map { |member| member.context = input }
end
def source
@wrapped_collection

View File

@ -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