From 35e2547b57d8f02bde27cc63dfa0f3f6c32eedef Mon Sep 17 00:00:00 2001 From: Kat Date: Tue, 15 Aug 2023 12:14:36 +0100 Subject: [PATCH] update updated_at column when updating incref --- lib/tasks/correct_incref_values.rake | 6 +++--- spec/lib/tasks/correct_incref_values_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/tasks/correct_incref_values.rake b/lib/tasks/correct_incref_values.rake index cc9278a72..d06618fa7 100644 --- a/lib/tasks/correct_incref_values.rake +++ b/lib/tasks/correct_incref_values.rake @@ -1,6 +1,6 @@ desc "Alter incref values for non imported lettings logs in the database" task correct_incref_values: :environment do - LettingsLog.where(old_id: nil, net_income_known: 0).update_all(incref: 0) - LettingsLog.where(old_id: nil, net_income_known: 1).update_all(incref: 2) - LettingsLog.where(old_id: nil, net_income_known: 2).update_all(incref: 1) + LettingsLog.where(old_id: nil, net_income_known: 0).update_all(incref: 0, updated_at: Time.zone.now) + LettingsLog.where(old_id: nil, net_income_known: 1).update_all(incref: 2, updated_at: Time.zone.now) + LettingsLog.where(old_id: nil, net_income_known: 2).update_all(incref: 1, updated_at: Time.zone.now) end diff --git a/spec/lib/tasks/correct_incref_values_spec.rb b/spec/lib/tasks/correct_incref_values_spec.rb index 8acddb636..9692c7ae4 100644 --- a/spec/lib/tasks/correct_incref_values_spec.rb +++ b/spec/lib/tasks/correct_incref_values_spec.rb @@ -39,6 +39,14 @@ RSpec.describe "correct_incref_values" do task.invoke expect(lettings_log.reload.incref).to eq(1) end + + it "updates updated_at value" do + lettings_log.updated_at = Time.zone.local(2021, 3, 3) + lettings_log.save!(validate: false) + expect(lettings_log.updated_at.to_date).to eq(Time.zone.local(2021, 3, 3)) + task.invoke + expect(lettings_log.reload.updated_at.to_date).to eq(Time.zone.today) + end end end end