test/unit/cleaner_test.rb in foreman-tasks-0.13.1 vs test/unit/cleaner_test.rb in foreman-tasks-0.13.2

- old
+ new

@@ -37,16 +37,22 @@ 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] + lock_to_delete = tasks_to_delete.first.locks.create(:name => 'read', :resource => User.current) - tasks_to_keep = [FactoryBot.create(:dynflow_task, :product_create_task)] + tasks_to_keep = [FactoryBot.create(:dynflow_task, :product_create_task)] + lock_to_keep = tasks_to_keep.first.locks.create(:name => 'read', :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 + + ForemanTasks::Lock.find_by(id: lock_to_delete.id).must_be_nil + ForemanTasks::Lock.find_by(id: lock_to_keep.id).wont_be_nil 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), @@ -74,10 +80,10 @@ .yields(w, false) cleaner.delete w.close header, *data = r.readlines.map(&:chomp) header.must_equal ForemanTasks::Task.attribute_names.join(',') - expected_lines = tasks_to_delete.map { |task| task.attributes.values.join(',') } + 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 end