Browse Source

CLDC-3850: Clear postcode known when clearing postcode full

pull/2912/head
Rachael Booth 6 days ago
parent
commit
5dd4faae28
  1. 7
      app/models/log.rb
  2. 24
      spec/models/log_spec.rb

7
app/models/log.rb

@ -248,6 +248,11 @@ class Log < ApplicationRecord
end
def blank_compound_invalid_non_setup_fields!
if errors.attribute_names.include? :postcode_full
self.postcode_known = nil if lettings?
self.pcodenk = nil if sales?
end
self.ppcodenk = nil if errors.attribute_names.include? :ppostcode_full
self.previous_la_known = nil if errors.attribute_names.include? :prevloc
@ -258,6 +263,8 @@ class Log < ApplicationRecord
self.address_line2 = nil
self.town_or_city = nil
self.postcode_full = nil
self.postcode_known = nil if lettings?
self.pcodenk = nil if sales?
self.county = nil
process_postcode_changes!
end

24
spec/models/log_spec.rb

@ -101,5 +101,29 @@ RSpec.describe Log, type: :model do
expect(model.joint).to be_nil
end
end
context "when postcode_full is invalid" do
context "for a lettings log" do
subject(:model) { build_stubbed(:lettings_log, :setup_completed, postcode_full: "not a postcode", postcode_known: 1) }
it "blanks it and postcode_known" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.postcode_full).to be_nil
expect(model.postcode_known).to be_nil
end
end
context "for a sales log" do
subject(:model) { build_stubbed(:sales_log, :discounted_ownership_setup_complete, postcode_full: "not a postcode", pcodenk: 0) }
it "blanks it and pcodenk" do
model.valid?
model.blank_invalid_non_setup_fields!
expect(model.postcode_full).to be_nil
expect(model.pcodenk).to be_nil
end
end
end
end
end

Loading…
Cancel
Save