Move missing statements to where + delete_all

And fix the specs
This commit is contained in:
Pau Perez
2020-09-08 12:47:42 +02:00
parent df0b997258
commit d525ddfe14
2 changed files with 13 additions and 14 deletions

View File

@@ -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

View File

@@ -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