diff --git a/lib/draper/factory.rb b/lib/draper/factory.rb index 4879110..421394e 100644 --- a/lib/draper/factory.rb +++ b/lib/draper/factory.rb @@ -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 diff --git a/spec/draper/factory_spec.rb b/spec/draper/factory_spec.rb index 86f4124..ee315eb 100644 --- a/spec/draper/factory_spec.rb +++ b/spec/draper/factory_spec.rb @@ -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