Sha256: 308e472ff81d9a2f26294bbdc15e0bbe4b41b015efbc7e91a369377ae8285c08

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

require 'rake'
require 'foreman_tasks_test_helper'

class GenerateTaskActionsTest < ActiveSupport::TestCase
  TASK_NAME = 'foreman_tasks:generate_task_actions'.freeze

  setup do
    Rake.application.rake_require 'foreman_tasks/tasks/generate_task_actions'

    Rake::Task.define_task(:environment)
    Rake::Task[TASK_NAME].reenable
  end

  let(:tasks) do
    (1..5).map { FactoryBot.build(:dynflow_task) }
  end

  it 'fixes the tasks' do
    label = 'a label'
    tasks
    ForemanTasks::Task.update_all(:action => nil)
    ForemanTasks::Task.any_instance.stubs(:to_label).returns(label)

    stdout, _stderr = capture_io do
      Rake.application.invoke_task TASK_NAME
    end

    assert_match(%r{Generating action for #{tasks.count} tasks}, stdout)
    assert_equal tasks.count, ForemanTasks::Task.where(:action => label).count
    assert_match(%r{Processed #{tasks.count}/#{tasks.count} tasks}, stdout)
  end

  it 'fixes only tasks with missing action' do
    tasks
    ForemanTasks::Task.any_instance.expects(:save!).never

    stdout, _stderr = capture_io do
      Rake.application.invoke_task TASK_NAME
    end

    assert_match(%r{Generating action for 0 tasks}, stdout)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 test/tasks/generate_task_actions_test.rb
foreman-tasks-10.0.1 test/tasks/generate_task_actions_test.rb
foreman-tasks-10.0.0 test/tasks/generate_task_actions_test.rb
foreman-tasks-9.2.3 test/tasks/generate_task_actions_test.rb
foreman-tasks-9.2.2 test/tasks/generate_task_actions_test.rb
foreman-tasks-9.2.1 test/tasks/generate_task_actions_test.rb
foreman-tasks-9.2.0 test/tasks/generate_task_actions_test.rb
foreman-tasks-9.1.1 test/tasks/generate_task_actions_test.rb