Sha256: 7017f7ca095ad0799b2fe6c6c81203aa9987d50fe756c7bfbd0c0a01167a292f
Contents?: true
Size: 1.63 KB
Versions: 46
Compression:
Stored size: 1.63 KB
Contents
require 'foreman_tasks_test_helper' module ForemanTasks class BulkActionTest < ActiveSupport::TestCase before do User.current = User.where(:login => 'apiadmin').first end Target = Struct.new(:id) class ParentAction < Actions::BulkAction; end class ChildAction < Actions::EntryAction def plan(target) target.id end end describe Actions::BulkAction do include ForemanTasks::TestHelpers::WithInThreadExecutor let(:targets) { (1..5).map { |i| Target.new i } } let(:task) do triggered = ForemanTasks.trigger(ParentAction, ChildAction, targets) task = ForemanTasks::Task.where(:external_id => triggered.id).first wait_for { task.reload.state == 'stopped' } task end specify 'it plans a task for each target' do Target.expects(:unscoped).returns(Target) Target.expects(:where).with(:id => targets.map(&:id)).returns(targets) _(task.sub_tasks.count).must_equal targets.count success, failed = task.sub_tasks.partition { |sub_task| sub_task.result == 'success' } _(failed).must_be :empty? _(success.count).must_equal 5 end specify 'it plans a task for each target even if target cannot be found' do Target.expects(:unscoped).returns(Target) Target.expects(:where).with(:id => targets.map(&:id)).returns(targets.take(4)) _(task.sub_tasks.count).must_equal targets.count success, failed = task.sub_tasks.partition { |sub_task| sub_task.result == 'success' } _(success.count).must_equal 4 _(failed.count).must_equal 1 end end end end
Version data entries
46 entries across 46 versions & 1 rubygems