test/unit/cleaner_test.rb in foreman-tasks-9.1.0 vs test/unit/cleaner_test.rb in foreman-tasks-9.1.1

- old
+ new

@@ -20,18 +20,18 @@ task.save end, 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 + assert_empty ForemanTasks::Task.where(id: tasks_to_delete) + assert_equal tasks_to_keep.map(&:id).sort, ForemanTasks::Task.where(id: tasks_to_keep).order(:id).map(&:id) - _(ForemanTasks.dynflow.world.persistence - .find_execution_plans(filters: { 'uuid' => tasks_to_delete.map(&:external_id) }).size).must_equal 0 + assert_equal 0, ForemanTasks.dynflow.world.persistence + .find_execution_plans(filters: { 'uuid' => tasks_to_delete.map(&:external_id) }).size - _(ForemanTasks.dynflow.world.persistence - .find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size).must_equal tasks_to_keep.size + assert_equal tasks_to_keep.size, ForemanTasks.dynflow.world.persistence + .find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size end describe "#orphaned_dynflow_tasks" do # We can't use transactional tests because we're using Sequel for the cleanup query self.use_transactional_tests = false @@ -65,15 +65,15 @@ tasks_to_keep = [FactoryBot.create(:dynflow_task, :product_create_task)] link_to_keep = tasks_to_keep.first.links.create(:resource => User.current) 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 + assert_empty ForemanTasks::Task.where(id: tasks_to_delete) + assert_equal tasks_to_keep, ForemanTasks::Task.where(id: tasks_to_keep) - _(ForemanTasks::Link.find_by(id: link_to_delete.id)).must_be_nil - _(ForemanTasks::Link.find_by(id: link_to_keep.id)).wont_be_nil + assert_nil ForemanTasks::Link.find_by(id: link_to_delete.id) + assert_not_nil ForemanTasks::Link.find_by(id: link_to_keep.id) end it 'supports passing empty filter (just delete all)' do cleaner = ForemanTasks::Cleaner.new(:filter => '', :after => '10d') tasks_to_delete = [FactoryBot.create(:dynflow_task, :user_create_task), @@ -83,12 +83,12 @@ task.started_at = task.ended_at = Time.zone.now task.save end] 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 + assert_empty ForemanTasks::Task.where(id: tasks_to_delete) + assert_equal tasks_to_keep, ForemanTasks::Task.where(id: tasks_to_keep) end it 'matches tasks with compound filters properly' do cleaner = ForemanTasks::Cleaner.new(:filter => 'result = pending or result = error', :states => %w[paused planning]) @@ -98,12 +98,12 @@ tasks_to_delete[1].update!(:result => 'pending', :state => 'planning') task_to_keep = FactoryBot.create(:some_task) task_to_keep.update!(:result => 'pending', :state => 'planned') cleaner.expects(:tasks_to_csv) cleaner.delete - _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty - _(ForemanTasks::Task.where(id: task_to_keep)).must_equal [task_to_keep] + assert_empty ForemanTasks::Task.where(id: tasks_to_delete) + assert_equal [task_to_keep], ForemanTasks::Task.where(id: task_to_keep) end it 'backs tasks up before deleting' do dir = '/tmp' cleaner = ForemanTasks::Cleaner.new(:filter => '', :after => '10d', :backup_dir => dir) @@ -115,15 +115,15 @@ .with(dir, 'foreman_tasks.csv') .yields(w, false) cleaner.delete w.close header, *data = r.readlines.map(&:chomp) - _(header).must_equal ForemanTasks::Task.attribute_names.join(',') + assert_equal ForemanTasks::Task.attribute_names.join(','), header expected_lines = tasks_to_delete.map { |task| task.attributes.values.to_csv.chomp } - _(data.count).must_equal expected_lines.count - expected_lines.each { |line| _(data).must_include line } - _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty + assert_equal expected_lines.count, data.count + expected_lines.each { |line| assert_includes data, line } + assert_empty ForemanTasks::Task.where(id: tasks_to_delete) end class ActionWithCleanup < Actions::Base def self.cleanup_after '15d' @@ -133,19 +133,19 @@ describe 'default behaviour' do it 'searches for the actions that have the cleanup_after defined' do ForemanTasks::Cleaner.stubs(:cleanup_settings => {}) actions = ForemanTasks::Cleaner.actions_with_default_cleanup example = actions.find { |rule| rule.klass == ActionWithCleanup } - _(example.after).must_equal '15d' + assert_equal '15d', example.after end it 'searches for the actions that have the cleanup_after defined' do ForemanTasks::Cleaner.stubs(:cleanup_settings => { :actions => [{ :name => ActionWithCleanup.name, :after => '5d' }] }) actions = ForemanTasks::Cleaner.actions_with_default_cleanup example = actions.find { |rule| rule.klass == ActionWithCleanup } - _(example.after).must_equal '5d' + assert_equal '5d', example.after end it 'generates filters from rules properly' do actions_with_default = ForemanTasks::CompositeActionRule.new( ForemanTasks::ActionRule.new('action1', nil), @@ -155,13 +155,13 @@ { :after => '10d', :filter => 'label = something', :states => %w[stopped paused] }, { :after => '15d', :filter => 'label = something_else', :override_actions => true, :states => 'all' }] ForemanTasks::Cleaner.stubs(:cleanup_settings).returns(:rules => rules) r1, r2 = ForemanTasks::Cleaner.actions_by_rules actions_with_default - _(r1[:filter]).must_equal '(NOT ((label ^ (action1, action2)))) AND (label = something)' - _(r1[:states]).must_equal %w[stopped paused] - _(r2[:filter]).must_equal '(label = something_else)' - _(r2[:states]).must_equal [] + assert_equal '(NOT ((label ^ (action1, action2)))) AND (label = something)', r1[:filter] + assert_equal %w[stopped paused], r1[:states] + assert_equal '(label = something_else)', r2[:filter] + assert_equal [], r2[:states] end end end end