mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Specify how much data to remove in :truncate_data
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user