mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
DRY date usage
This commit is contained in:
@@ -10,8 +10,14 @@ class RemoveTransientData
|
||||
def call
|
||||
Rails.logger.info("RemoveTransientData: processing")
|
||||
|
||||
Spree::StateChange.delete_all("created_at < '#{1.month.ago.to_date}'")
|
||||
Spree::LogEntry.delete_all("created_at < '#{1.month.ago.to_date}'")
|
||||
Session.delete_all("created_at < '#{2.weeks.ago.to_date}'")
|
||||
Spree::StateChange.delete_all("created_at < '#{retention_period}'")
|
||||
Spree::LogEntry.delete_all("created_at < '#{retention_period}'")
|
||||
Session.delete_all("updated_at < '#{retention_period}'")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def retention_period
|
||||
2.months.ago.to_date
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,6 +5,8 @@ require 'tasks/data/remove_transient_data'
|
||||
|
||||
describe RemoveTransientData do
|
||||
describe '#call' do
|
||||
let(:retention_period) { RemoveTransientData.new.__send__(:retention_period) }
|
||||
|
||||
before do
|
||||
allow(Spree::StateChange).to receive(:delete_all)
|
||||
allow(Spree::LogEntry).to receive(:delete_all)
|
||||
@@ -17,7 +19,7 @@ describe RemoveTransientData do
|
||||
|
||||
expect(Spree::StateChange)
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{1.month.ago.to_date}'")
|
||||
.with("created_at < '#{retention_period}'")
|
||||
end
|
||||
|
||||
it 'deletes log entries older than a month' do
|
||||
@@ -25,7 +27,7 @@ describe RemoveTransientData do
|
||||
|
||||
expect(Spree::LogEntry)
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{1.month.ago.to_date}'")
|
||||
.with("created_at < '#{retention_period}'")
|
||||
end
|
||||
|
||||
it 'deletes sessions older than two weeks' do
|
||||
@@ -33,7 +35,7 @@ describe RemoveTransientData do
|
||||
|
||||
expect(RemoveTransientData::Session)
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{2.weeks.ago.to_date}'")
|
||||
.with("updated_at < '#{retention_period}'")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user