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

Version Path
foreman-tasks-8.2.1 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.1.4 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.3.2 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.3.1 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.1.3 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.3.0 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.2.0 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.1.2 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.1.1 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.1.0 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.0.2 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.0.1 test/unit/actions/bulk_action_test.rb
foreman-tasks-8.0.0 test/unit/actions/bulk_action_test.rb
foreman-tasks-7.2.1 test/unit/actions/bulk_action_test.rb
foreman-tasks-7.1.1 test/unit/actions/bulk_action_test.rb
foreman-tasks-7.2.0 test/unit/actions/bulk_action_test.rb
foreman-tasks-7.1.0 test/unit/actions/bulk_action_test.rb
foreman-tasks-6.0.3 test/unit/actions/bulk_action_test.rb
foreman-tasks-7.0.0 test/unit/actions/bulk_action_test.rb
foreman-tasks-6.0.2 test/unit/actions/bulk_action_test.rb