Permalink
Browse files

Merge pull request #479 from haines/context_lambda

Wrap context_args to avoid splatting hashes
  • Loading branch information...
2 parents 3ab3b35 + 70169d4 commit f4dd9e0206929a81274256daf6021b8c821f4757 @steveklabnik steveklabnik committed Feb 19, 2013
Showing with 11 additions and 1 deletion.
  1. +1 −1 lib/draper/factory.rb
  2. +10 −0 spec/draper/factory_spec.rb
@@ -80,7 +80,7 @@ def source_decorator_class
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
@@ -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

0 comments on commit f4dd9e0

Please sign in to comment.