test/unit/cleaner_test.rb in foreman-tasks-0.10.9 vs test/unit/cleaner_test.rb in foreman-tasks-0.11.0

- old
+ new

@@ -8,17 +8,17 @@ describe ForemanTasks::Cleaner do it 'is able to delete tasks (including the dynflow plans) based on filter' do cleaner = ForemanTasks::Cleaner.new(:filter => 'label = "Actions::User::Create"', :after => '10d') - tasks_to_delete = [FactoryGirl.create(:dynflow_task, :user_create_task), - FactoryGirl.create(:dynflow_task, :user_create_task)] - tasks_to_keep = [FactoryGirl.create(:dynflow_task, :user_create_task) do |task| + tasks_to_delete = [FactoryBot.create(:dynflow_task, :user_create_task), + FactoryBot.create(:dynflow_task, :user_create_task)] + tasks_to_keep = [FactoryBot.create(:dynflow_task, :user_create_task) do |task| task.started_at = task.ended_at = Time.zone.now task.save end, - FactoryGirl.create(:dynflow_task, :product_create_task)] + FactoryBot.create(:dynflow_task, :product_create_task)] cleaner.expects(:tasks_to_csv) cleaner.delete ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty ForemanTasks::Task.where(id: tasks_to_keep).order(:id).map(&:id).must_equal tasks_to_keep.map(&:id).sort @@ -29,29 +29,29 @@ .find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size.must_equal tasks_to_keep.size end it 'deletes all tasks matching the filter when the time limit is not specified' do cleaner = ForemanTasks::Cleaner.new(:filter => 'label = "Actions::User::Create"') - tasks_to_delete = [FactoryGirl.create(:dynflow_task, :user_create_task), - FactoryGirl.create(:dynflow_task, :user_create_task) do |task| + tasks_to_delete = [FactoryBot.create(:dynflow_task, :user_create_task), + FactoryBot.create(:dynflow_task, :user_create_task) do |task| task.started_at = task.ended_at = Time.zone.now task.save end] - tasks_to_keep = [FactoryGirl.create(:dynflow_task, :product_create_task)] + tasks_to_keep = [FactoryBot.create(:dynflow_task, :product_create_task)] cleaner.expects(:tasks_to_csv) cleaner.delete ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty ForemanTasks::Task.where(id: tasks_to_keep).must_equal tasks_to_keep end it 'supports passing empty filter (just delete all)' do cleaner = ForemanTasks::Cleaner.new(:filter => '', :after => '10d') - tasks_to_delete = [FactoryGirl.create(:dynflow_task, :user_create_task), - FactoryGirl.create(:dynflow_task, :product_create_task)] + tasks_to_delete = [FactoryBot.create(:dynflow_task, :user_create_task), + FactoryBot.create(:dynflow_task, :product_create_task)] - tasks_to_keep = [FactoryGirl.create(:dynflow_task, :user_create_task) do |task| + tasks_to_keep = [FactoryBot.create(:dynflow_task, :user_create_task) do |task| task.started_at = task.ended_at = Time.zone.now task.save end] cleaner.expects(:tasks_to_csv) cleaner.delete @@ -60,11 +60,11 @@ end it 'backs tasks up before deleting' do dir = '/tmp' cleaner = ForemanTasks::Cleaner.new(:filter => '', :after => '10d', :backup_dir => dir) - tasks_to_delete = [FactoryGirl.create(:dynflow_task, :user_create_task), - FactoryGirl.create(:dynflow_task, :product_create_task)] + tasks_to_delete = [FactoryBot.create(:dynflow_task, :user_create_task), + FactoryBot.create(:dynflow_task, :product_create_task)] r, w = IO.pipe cleaner.expects(:with_backup_file) .with(dir, 'foreman_tasks.csv') .yields(w, false)