Browse Source

Log unsuccessful updates (#2350)

pull/2351/head
kosiakkatrina 9 months ago committed by GitHub
parent
commit
0e23fa160c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      lib/tasks/correct_renewal_postcodes.rake
  2. 23
      spec/lib/tasks/correct_renewal_postcodes_spec.rb

4
lib/tasks/correct_renewal_postcodes.rake

@ -19,6 +19,8 @@ task correct_renewal_postcodes: :environment do
log.previous_la_known = log.la.present? ? 1 : 0
log.prevloc = log.la
log.values_updated_at = Time.zone.now
log.save!
unless log.save
Rails.logger.info("Failed to save log #{log.id}: #{log.errors.full_messages}")
end
end
end

23
spec/lib/tasks/correct_renewal_postcodes_spec.rb

@ -213,6 +213,29 @@ RSpec.describe "correct_renewal_postcodes" do
expect(log.values_updated_at).to eq(nil)
end
end
context "and there there is a different validation error" do
let(:log) { create(:lettings_log, :completed, postcode_full: "SW1A 1AA", ppostcode_full: "AA1 1AA") }
let(:not_related_user) { create(:user) }
before do
log.renewal = 1
log.values_updated_at = nil
log.created_by = not_related_user
log.save!(validate: false)
end
it "does not updaate the log and logs the errors" do
expect(log.ppostcode_full).to eq("AA1 1AA")
expect(Rails.logger).to receive(:info).with(/Failed to save log #{log.id}:/)
task.invoke
log.reload
expect(log.ppostcode_full).to eq("AA1 1AA")
expect(log.values_updated_at).to eq(nil)
end
end
end
end
end

Loading…
Cancel
Save