mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Move missing statements to where + delete_all
And fix the specs
This commit is contained in:
@@ -11,8 +11,8 @@ class RemoveTransientData
|
||||
Rails.logger.info("#{self.class.name}: processing")
|
||||
|
||||
Spree::StateChange.where("created_at < ?", retention_period).delete_all
|
||||
Spree::LogEntry.delete_all("created_at < '#{retention_period}'")
|
||||
Session.delete_all("updated_at < '#{retention_period}'")
|
||||
Spree::LogEntry.where("created_at < ?", retention_period).delete_all
|
||||
Session.where("updated_at < ?", retention_period).delete_all
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -14,28 +14,27 @@ describe RemoveTransientData do
|
||||
allow(Rails.logger).to receive(:info)
|
||||
end
|
||||
|
||||
it 'deletes state changes older than a month' do
|
||||
RemoveTransientData.new.call
|
||||
it 'deletes state changes older than rentention_period' do
|
||||
Spree::StateChange.create(created_at: retention_period - 1.day)
|
||||
|
||||
expect(Spree::StateChange)
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{retention_period}'")
|
||||
RemoveTransientData.new.call
|
||||
expect(Spree::StateChange.all).to be_empty
|
||||
end
|
||||
|
||||
it 'deletes log entries older than a month' do
|
||||
Spree::LogEntry.create(created_at: retention_period - 1.day)
|
||||
|
||||
RemoveTransientData.new.call
|
||||
|
||||
expect(Spree::LogEntry)
|
||||
.to have_received(:delete_all)
|
||||
.with("created_at < '#{retention_period}'")
|
||||
expect(Spree::LogEntry.all).to be_empty
|
||||
end
|
||||
|
||||
it 'deletes sessions older than two weeks' do
|
||||
it 'deletes sessions older than retention_period' do
|
||||
RemoveTransientData::Session.create(session_id: 1, updated_at: retention_period - 1.day)
|
||||
|
||||
RemoveTransientData.new.call
|
||||
|
||||
expect(RemoveTransientData::Session)
|
||||
.to have_received(:delete_all)
|
||||
.with("updated_at < '#{retention_period}'")
|
||||
expect(RemoveTransientData::Session.all).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user