1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Merge pull request #479 from haines/context_lambda

Wrap context_args to avoid splatting hashes
This commit is contained in:
Steve Klabnik 2013-02-19 11:28:22 -08:00
commit f4dd9e0206
2 changed files with 11 additions and 1 deletions

View file

@ -80,7 +80,7 @@ module Draper
def update_context(options)
args = options.delete(:context_args)
options[:context] = options[:context].call(*args) if options[:context].respond_to?(:call)
options[:context] = options[:context].call(*Array.wrap(args)) if options[:context].respond_to?(:call)
end
end
end

View file

@ -124,6 +124,16 @@ module Draper
context.should_receive(:call).with(:foo, :bar)
worker.call(context: context, context_args: [:foo, :bar])
end
it "wraps non-arrays passed to :context_args" do
worker = Factory::Worker.new(double, double)
worker.stub decorator: ->(*){}
context = ->{}
hash = {foo: "bar"}
context.should_receive(:call).with(hash)
worker.call(context: context, context_args: hash)
end
end
context "when the :context option is not callable" do