Specify how much data to remove in :truncate_data

This commit is contained in:
Pau Perez
2020-03-06 17:40:11 +01:00
parent 60d29d619f
commit be123b2a72
3 changed files with 6 additions and 5 deletions

View File

@@ -9,10 +9,11 @@ require 'tasks/data/truncate_data'
namespace :ofn do
namespace :data do
desc 'Truncate data'
task truncate: :environment do
task :truncate, [:months_to_keep] => :environment do |_task, args|
guard_and_warn
TruncateData.new.call
months_to_keep = args.months_to_keep.to_i
TruncateData.new(months_to_keep).call
end
def guard_and_warn

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
class TruncateData
def initialize(months_to_keep: nil)
def initialize(months_to_keep = nil)
@date = (months_to_keep || 3).months.ago
end

View File

@@ -29,7 +29,7 @@ describe TruncateData do
)
create(:order, order_cycle: order_cycle)
TruncateData.new(months_to_keep: nil).call
TruncateData.new(nil).call
expect(OrderCycle.all).to be_empty
end
@@ -46,7 +46,7 @@ describe TruncateData do
)
create(:order, order_cycle: recent_order_cycle)
TruncateData.new(months_to_keep: 6).call
TruncateData.new(6).call
expect(OrderCycle.all).to contain_exactly(recent_order_cycle)
end