diff --git a/app/lib/actions/bulk_action.rb b/app/lib/actions/bulk_action.rb index 2191b9596..69d410cbb 100644 --- a/app/lib/actions/bulk_action.rb +++ b/app/lib/actions/bulk_action.rb @@ -50,8 +50,11 @@ def create_sub_plans missing = Array.new((current_batch - targets.map(&:id)).count) { nil } + args = input[:args] + args += [input[:kwargs]] unless input[:kwargs].empty? + (targets + missing).map do |target| - trigger(action_class, target, *input[:args], **input[:kwargs]) + trigger(action_class, target, *args) end end diff --git a/test/unit/actions/bulk_action_test.rb b/test/unit/actions/bulk_action_test.rb index 1696f7f61..0979c7137 100644 --- a/test/unit/actions/bulk_action_test.rb +++ b/test/unit/actions/bulk_action_test.rb @@ -16,6 +16,12 @@ def plan(target) end end + class KwArgChildAction < Actions::EntryAction + def plan(_target, options = {}) + plan_self(kw_string: options['kw'], kw_symbol: options[:kw]) + end + end + describe Actions::BulkAction do include ForemanTasks::TestHelpers::WithInThreadExecutor @@ -46,6 +52,27 @@ def plan(target) _(success.count).must_equal 4 _(failed.count).must_equal 1 end + + specify "it handles keyword arguments as indifferent hashes when they're being flattened" do + Target.expects(:unscoped).returns(Target) + Target.expects(:where).with(:id => targets.map(&:id)).returns(targets) + + triggered = ForemanTasks.trigger(ParentAction, KwArgChildAction, targets, kw: 7) + task = ForemanTasks::Task.where(:external_id => triggered.id).first + wait_for { task.reload.state == 'stopped' } + task = task.sub_tasks.first + _(task.input[:kw_string]).must_equal 7 + _(task.input[:kw_symbol]).must_equal 7 + end + + specify 'it allows setting concurrency limit' do + Target.expects(:unscoped).returns(Target) + Target.expects(:where).with(:id => targets.map(&:id)).returns(targets) + + triggered = ForemanTasks.trigger(ParentAction, ChildAction, targets, concurrency_limit: 25) + task = ForemanTasks::Task.where(:external_id => triggered.id).first + _(task.execution_plan.entry_action.concurrency_limit).must_equal 25 + end end end end