Sha256: d51ffd5d8d43b12e1f410331e6a844f7747f141e74b17e7a96e1b21d860c9501

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

require 'foreman_tasks_test_helper'
require 'foreman_tasks/test_helpers'

module ForemanTasks
  class ActionWithSubPlansTest < ActiveSupport::TestCase
    before do
      User.current = User.where(:login => 'apiadmin').first
    end

    # to be able to use the locking
    ::User.include ForemanTasks::Concerns::ActionSubject

    class ParentAction < Actions::ActionWithSubPlans
      def plan(user)
        action_subject(user)
        plan_self(user_id: user.id)
      end

      def create_sub_plans
        user = User.find(input[:user_id])
        trigger(ChildAction, user)
      end
    end

    class ChildAction < Actions::EntryAction
      def plan(user)
        action_subject(user)
        plan_self(user_id: user.id)
      end

      def run; end
    end

    describe Actions::ActionWithSubPlans do
      include ForemanTasks::TestHelpers::WithInThreadExecutor

      let(:task) do
        user = FactoryBot.create(:user)
        triggered = ForemanTasks.trigger(ParentAction, user)
        raise triggered.error if triggered.respond_to?(:error)
        triggered.finished.wait(30)
        ForemanTasks::Task.where(:external_id => triggered.id).first
      end

      specify 'the sub-plan stores the information about its parent' do
        _(task.sub_tasks.size).must_equal 1
        _(task.sub_tasks.first.label).must_equal ChildAction.name
      end

      specify "the locks of the sub-plan don't colide with the locks of its parent" do
        child_task = task.sub_tasks.first
        assert(child_task.locks.any? { |lock| lock.name == 'write' }, "it's locks don't conflict with parent's")
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foreman-tasks-3.0.6 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-3.0.5 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-3.0.4 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-3.0.3 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-3.0.2 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-3.0.1 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-3.0.0 test/unit/actions/action_with_sub_plans_test.rb