From d9f498912bc2abb1b6966a60fc51580322447857 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:11:18 +0100 Subject: [PATCH] Skip validations when updating incref (#1837) --- 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 0b1921998..cc9278a72 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!(incref: 0) - LettingsLog.where(old_id: nil, net_income_known: 1).update!(incref: 2) - LettingsLog.where(old_id: nil, net_income_known: 2).update!(incref: 1) + 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) end diff --git a/spec/lib/tasks/correct_incref_values_spec.rb b/spec/lib/tasks/correct_incref_values_spec.rb index fc046dcf6..8acddb636 100644 --- a/spec/lib/tasks/correct_incref_values_spec.rb +++ b/spec/lib/tasks/correct_incref_values_spec.rb @@ -31,6 +31,14 @@ RSpec.describe "correct_incref_values" do task.invoke expect(lettings_log.reload.incref).to eq(1) end + + it "skips validations for previous years" do + lettings_log.update!(net_income_known: 2, incref: nil) + lettings_log.startdate = Time.zone.local(2021, 3, 3) + lettings_log.save!(validate: false) + task.invoke + expect(lettings_log.reload.incref).to eq(1) + end end end end