Browse Source

add method to blank invalid non setup fields

pull/1197/head
Phil Lee 3 years ago
parent
commit
ae3d6cf575
  1. 10
      app/models/log.rb
  2. 20
      spec/models/lettings_log_spec.rb

10
app/models/log.rb

@ -52,6 +52,16 @@ class Log < ApplicationRecord
form.end_date > Time.zone.today
end
def blank_invalid_non_setup_fields!
setup_ids = form.setup_sections.flat_map(&:subsections).flat_map(&:questions).map(&:id)
errors.each do |error|
next if setup_ids.include?(error.attribute.to_s)
public_send("#{error.attribute}=", nil)
end
end
private
def update_status!

20
spec/models/lettings_log_spec.rb

@ -2536,4 +2536,24 @@ RSpec.describe LettingsLog do
end
end
end
describe "#blank_invalid_non_setup_fields!" do
context "when a setup field is invalid" do
subject(:model) { described_class.new(needstype: 404) }
it "does not blank it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.not_to change(model, :needstype)
end
end
context "when a non setup field is invalid" do
subject(:model) { described_class.new(beds: 404) }
it "blanks it" do
model.valid?
expect { model.blank_invalid_non_setup_fields! }.to change(model, :beds)
end
end
end
end

Loading…
Cancel
Save