Browse Source

update updated_at column when updating incref (#1838)

pull/1844/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
abe3ef670e
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_all(incref: 0) 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) 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) LettingsLog.where(old_id: nil, net_income_known: 2).update_all(incref: 1, updated_at: Time.zone.now)
end end

8
spec/lib/tasks/correct_incref_values_spec.rb

@ -39,6 +39,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 "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 end
end end

Loading…
Cancel
Save