Browse Source

Skip validations when updating incref (#1837)

pull/1838/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
d9f498912b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      lib/tasks/correct_incref_values.rake
  2. 8
      spec/lib/tasks/correct_incref_values_spec.rb

6
lib/tasks/correct_incref_values.rake

@ -1,6 +1,6 @@
desc "Alter incref values for non imported lettings logs in the database" desc "Alter incref values for non imported lettings logs in the database"
task correct_incref_values: :environment do 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: 0).update_all(incref: 0)
LettingsLog.where(old_id: nil, net_income_known: 1).update!(incref: 2) LettingsLog.where(old_id: nil, net_income_known: 1).update_all(incref: 2)
LettingsLog.where(old_id: nil, net_income_known: 2).update!(incref: 1) LettingsLog.where(old_id: nil, net_income_known: 2).update_all(incref: 1)
end end

8
spec/lib/tasks/correct_incref_values_spec.rb

@ -31,6 +31,14 @@ RSpec.describe "correct_incref_values" do
task.invoke task.invoke
expect(lettings_log.reload.incref).to eq(1) expect(lettings_log.reload.incref).to eq(1)
end 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 end
end end

Loading…
Cancel
Save