Delete StateChanges older than a month

They are useful for troubleshooting but a month data seems enough.
This commit is contained in:
Pau Perez
2020-03-10 13:07:34 +01:00
parent d215c76bc9
commit 5f84c51c13
2 changed files with 25 additions and 1 deletions

View File

@@ -34,7 +34,7 @@ class TruncateData
def remove_transient_data
Spree::ReturnAuthorization.delete_all
Spree::StateChange.delete_all
Spree::StateChange.delete_all("created_at < '#{1.month.ago.to_date}'")
Spree::LogEntry.delete_all
sql_delete_from "sessions"
end

View File

@@ -20,6 +20,14 @@ describe TruncateData do
expect(OrderCycle.all).to be_empty
end
it 'deletes state changes older than a month' do
TruncateData.new.call
expect(Spree::StateChange)
.to have_received(:delete_all)
.with("created_at < '#{1.month.ago.to_date}'")
end
end
context 'when months_to_keep is nil' do
@@ -33,6 +41,14 @@ describe TruncateData do
expect(OrderCycle.all).to be_empty
end
it 'deletes state changes older than a month' do
TruncateData.new.call
expect(Spree::StateChange)
.to have_received(:delete_all)
.with("created_at < '#{1.month.ago.to_date}'")
end
end
context 'when months_to_keep is specified' do
@@ -50,6 +66,14 @@ describe TruncateData do
expect(OrderCycle.all).to contain_exactly(recent_order_cycle)
end
it 'deletes state changes older than a month' do
TruncateData.new.call
expect(Spree::StateChange)
.to have_received(:delete_all)
.with("created_at < '#{1.month.ago.to_date}'")
end
end
end
end