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

Wrap context_args to avoid splatting hashes

This commit is contained in:
Andrew Haines 2013-02-19 15:07:11 +00:00
parent 3ab3b35e87
commit 70169d4ddf
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