Sha256: e5d276094f7f0fbeaea1879d96b6114ebcfe113e1f031b22d1c3f7d45e3d1eb2

Contents?: true

Size: 1.58 KB

Versions: 20

Compression:

Stored size: 1.58 KB

Contents

require "foreman_tasks_test_helper"

module ForemanTasks
  class ActionWithSubPlansTest <  ActiveSupport::TestCase
    self.use_transactional_fixtures = false

    before do
      User.current = User.where(:login => 'apiadmin').first
    end

    # to be able to use the locking
    class ::User < User.parent
      include ForemanTasks::Concerns::ActionSubject
    end

    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
      let(:task) do
        user = FactoryGirl.create(:user)
        triggered = ForemanTasks.trigger(ParentAction, user)
        raise triggered.error if triggered.respond_to?(:error)
        triggered.finished.wait(2)
        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

20 entries across 20 versions & 1 rubygems

Version Path
foreman-tasks-0.8.6 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.8.5 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.8.4 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.8.3 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.8.2 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.8.1 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.8.0 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.20 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.19 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.18 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.17 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.16 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.15 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.14 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.13 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.12 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.11 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.10 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.9 test/unit/actions/action_with_sub_plans_test.rb
foreman-tasks-0.7.8 test/unit/actions/action_with_sub_plans_test.rb