Sha256: 4e10f325a82a2c7e02a6e03c9a4416248a96b27ef87a44811e69a2db8fac271d

Contents?: true

Size: 1.11 KB

Versions: 15

Compression:

Stored size: 1.11 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

      before do
        @user = mock('user')
        @user.stubs(:id).returns(1)
      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

15 entries across 15 versions & 1 rubygems

Version Path
foreman-tasks-0.14.6 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.15.2 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.15.1 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.15.0 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.14.5 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.14.4 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.14.3 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.14.2 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.14.1 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.14.0 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.13.4 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.13.3 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.13.2 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.13.1 test/lib/actions/middleware/keep_current_user_test.rb
foreman-tasks-0.13.0 test/lib/actions/middleware/keep_current_user_test.rb