Skip to content

Commit

Permalink
Merge pull request drapergem#186 from nisargshah100/enumerable_proxy_…
Browse files Browse the repository at this point in the history
…context

added context to enumerable
  • Loading branch information
steveklabnik committed May 8, 2012
2 parents 15992b8 + f9f0982 commit b60d195
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/draper/decorated_enumerable_proxy.rb
Expand Up @@ -38,6 +38,10 @@ def [](index)
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
Expand Down
5 changes: 5 additions & 0 deletions spec/draper/base_spec.rb
Expand Up @@ -313,6 +313,11 @@ class CustomDecorator < Draper::Base
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
Expand Down

0 comments on commit b60d195

Please sign in to comment.