Skip to content

Commit

Permalink
Fixes #36931 - Pass keywords around the old way
Browse files Browse the repository at this point in the history
This is not ideal, but it should be in line with what we had before the
move to v2 bulk actions.

To handle this properly, the changes will need to start in Dynflow and
then in things that build on top of it. This is something we might
ultimately have to do for Ruby 3.
  • Loading branch information
adamruzicka committed Nov 20, 2023
1 parent 70b80b9 commit a1cc99a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/lib/actions/bulk_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def create_sub_plans
missing = Array.new((current_batch - targets.map(&:id)).count) { nil }

(targets + missing).map do |target|
trigger(action_class, target, *input[:args], **input[:kwargs])
trigger(action_class, target, *(input[:args] + [input[:kwargs]]))
end
end

Expand Down
18 changes: 18 additions & 0 deletions test/unit/actions/bulk_action_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -46,6 +52,18 @@ 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
end
end
end

0 comments on commit a1cc99a

Please sign in to comment.