Browse Source

Add test, update logs with different LAs

pull/2326/head
Kat 2 years ago
parent
commit
ce61cd48de
  1. 9
      lib/tasks/correct_renewal_postcodes.rake
  2. 100
      spec/lib/tasks/correct_renewal_postcodes_spec.rb

9
lib/tasks/correct_renewal_postcodes.rake

@ -1,6 +1,13 @@
desc "Update lettings logs renewal previous postcode and la data to be the same as current postcode/la"
task correct_renewal_postcodes: :environment do
LettingsLog.filter_by_year(2023).where(renewal: 1).where("(ppostcode_full != postcode_full) OR (ppostcode_full IS NULL AND postcode_full IS NOT NULL) OR (postcode_full IS NULL AND ppostcode_full IS NOT NULL)").each do |log|
LettingsLog.filter_by_year(2023).where(renewal: 1).where("
((ppostcode_full != postcode_full)
OR (ppostcode_full IS NULL AND postcode_full IS NOT NULL)
OR (postcode_full IS NULL AND ppostcode_full IS NOT NULL))
OR ((prevloc != la)
OR (la IS NULL AND prevloc IS NOT NULL)
OR (prevloc IS NULL AND la IS NOT NULL))
").each do |log|
log.ppostcode_full = log.postcode_full
log.ppcodenk = case log.postcode_known
when 0

100
spec/lib/tasks/correct_renewal_postcodes_spec.rb

@ -32,6 +32,26 @@ RSpec.describe "correct_renewal_postcodes" do
end
end
context "and there there is a non renewal lettings log with different previous postcode" do
let(:log) { create(:lettings_log, :completed, postcode_full: "SW1A 1AA", ppostcode_full: "AA1 1AA") }
before do
log.renewal = 0
log.values_updated_at = nil
log.save!(validate: false)
end
it "does not update and reexport the previous postcode" do
expect(log.ppostcode_full).to eq("AA1 1AA")
task.invoke
log.reload
expect(log.ppostcode_full).to eq("AA1 1AA")
expect(log.values_updated_at).to eq(nil)
end
end
context "and there there is a renewal lettings log with missing previous postcode" do
let(:log) { create(:lettings_log, :completed, postcode_full: "SW1A 1AA", ppostcode_full: nil) }
@ -92,6 +112,86 @@ RSpec.describe "correct_renewal_postcodes" do
end
end
context "and there is a renewal lettings log with same nil postcodes" do
let(:log) { create(:lettings_log, :completed, postcode_known: 0, la: "E07000223", prevloc: "E07000223", postcode_full: nil, ppostcode_full: nil) }
before do
log.renewal = 1
log.values_updated_at = nil
log.save!(validate: false)
end
it "does not update the previous postcode and does not re-export" do
expect(log.ppostcode_full).to eq(nil)
task.invoke
log.reload
expect(log.ppostcode_full).to eq(nil)
expect(log.values_updated_at).to eq(nil)
end
end
context "and there is a renewal lettings log with same nil postcodes and different la" do
let(:log) { create(:lettings_log, :completed, postcode_known: 0, postcode_full: nil, la: "E07000223", ppostcode_full: nil, prevloc: "E07000026") }
before do
log.renewal = 1
log.values_updated_at = nil
log.save!(validate: false)
end
it "updates the previous la and reexports the log" do
expect(log.ppostcode_full).to eq(nil)
task.invoke
log.reload
expect(log.prevloc).to eq("E07000223")
expect(log.values_updated_at).not_to eq(nil)
end
end
context "and there is a renewal lettings log with same nil postcodes, la not nil and prevloc nil" do
let(:log) { create(:lettings_log, :completed, postcode_known: 0, postcode_full: nil, la: "E07000223", ppostcode_full: nil, previous_la_known: 0, prevloc: nil) }
before do
log.renewal = 1
log.values_updated_at = nil
log.save!(validate: false)
end
it "updates the previous la and reexports the log" do
expect(log.ppostcode_full).to eq(nil)
task.invoke
log.reload
expect(log.prevloc).to eq("E07000223")
expect(log.values_updated_at).not_to eq(nil)
end
end
context "and there is a renewal lettings log with same nil postcodes, la nil and prevloc not nil" do
let(:log) { create(:lettings_log, :completed, postcode_known: 0, postcode_full: nil, la: nil, ppostcode_full: nil, prevloc: "E07000223") }
before do
log.renewal = 1
log.values_updated_at = nil
log.save!(validate: false)
end
it "updates the previous la and reexports the log" do
expect(log.ppostcode_full).to eq("E07000223")
task.invoke
log.reload
expect(log.prevloc).to eq(nil)
expect(log.values_updated_at).not_to eq(nil)
end
end
context "and there is a renewal lettings log from closed collection year" do
let(:log) { create(:lettings_log, :completed, postcode_full: "AA1 1AA", ppostcode_full: nil) }

Loading…
Cancel
Save