From 1e2868648bc8b9d05023f1f8438358607168fc73 Mon Sep 17 00:00:00 2001 From: Jeff Casimir Date: Mon, 3 Oct 2011 18:10:25 -0400 Subject: [PATCH] Adding context to find, closes #28 --- lib/draper/base.rb | 4 ++-- spec/base_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/draper/base.rb b/lib/draper/base.rb index 4c9685b..a79b4a2 100644 --- a/lib/draper/base.rb +++ b/lib/draper/base.rb @@ -32,8 +32,8 @@ module Draper # # @param [Symbol or String] id to lookup # @return [Object] instance of this decorator class - def self.find(input) - self.new(model_class.find(input)) + def self.find(input, context = {}) + self.new(model_class.find(input), context) end # Typically called within a decorator definition, this method diff --git a/spec/base_spec.rb b/spec/base_spec.rb index 0a0b9ee..d60b38e 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -89,6 +89,11 @@ describe Draper::Base do pd.should be_instance_of(ProductDecorator) pd.model.should be_instance_of(Product) end + + it "should accept and store a context" do + pd = ProductDecorator.find(1, :admin) + pd.context.should == :admin + end end context ".decorate" do