Sha256: 56acbc456ec75f56aa49a7512b84e03fed57a2a7f2cf0139bec59ee8666b1cd8

Contents?: true

Size: 1.69 KB

Versions: 91

Compression:

Stored size: 1.69 KB

Contents

require 'foreman_tasks_test_helper'

module Actions
  module Middleware
    class KeepCurrentUserTest < ActiveSupport::TestCase
      include ::Dynflow::Testing

      class TestAction < Support::DummyDynflowAction
        middleware.use KeepCurrentUser

        def run; end
      end

      class TestHookAction < Support::DummyDynflowAction
        middleware.use KeepCurrentUser
        execution_plan_hooks.use :null_hook, :on => :planning

        def null_hook; end
      end

      before do
        @user = mock('user')
        @user.stubs(:id).returns(1)
      end

      describe 'hook' do
        test 'does not reset current user before planning' do
          triggered = ForemanTasks.trigger(TestHookAction)
          task = ForemanTasks::Task.where(:external_id => triggered.id).first
          wait_for { task.reload.state == 'stopped' }

          assert_equal(User.current.id, task.execution_plan.entry_action.input['current_user_id'])
        end
      end

      describe 'plan' do
        test 'with current user set' do
          User.expects(:current).twice.returns(@user)

          @action = create_and_plan_action(TestAction)
          assert_equal(@user.id, @action.input['current_user_id'])
        end
      end

      describe 'run' do
        before do
          User.stubs(:current).returns(@user)

          @action = create_and_plan_action(TestAction)

          User.stubs(:current)
        end

        test 'with current user as input' do
          User.unscoped.class.any_instance.expects(:find).with(@user.id).returns(@user)

          User.expects(:current=).with(@user)

          User.stubs(:current=).with(nil)

          @action = run_action(@action)
        end
      end
    end
  end
end

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-10.0.1 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-10.0.0 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.2.3 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.2.2 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.2.1 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.2.0 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.1.1 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.0.4 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.1.0 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.0.2 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.0.1 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-8.3.3 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-9.0.0 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-8.2.1 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-8.1.4 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-8.3.2 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-8.3.1 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-8.1.3 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-8.3.0 test/lib/actions/middleware/keep_current_user_test.rb