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