Browse Source

add other reason left settled home validation

pull/54/head
MadeTech Dushan 3 years ago
parent
commit
9d95707e35
  1. 10
      app/models/case_log.rb
  2. 16
      spec/models/case_log_spec.rb

10
app/models/case_log.rb

@ -15,6 +15,16 @@ class CaseLogValidator < ActiveModel::Validator
end
end
def validate_other_reason_for_leaving_last_settled_home(record)
if record.reason_for_leaving_last_settled_home == "Other" && record.other_reason_for_leaving_last_settled_home.blank?
record.errors.add :other_reason_for_leaving_last_settled_home, "If reason for leaving settled home is other then the other reason must be provided"
end
if record.reason_for_leaving_last_settled_home != "Other" && record.other_reason_for_leaving_last_settled_home.present?
record.errors.add :other_reason_for_leaving_last_settled_home, "The other reason must not be provided if the reason for leaving settled home was not other"
end
end
def validate(record)
# If we've come from the form UI we only want to validate the specific fields
# that have just been submitted. If we're submitting a log via API or Bulk Upload

16
spec/models/case_log_spec.rb

@ -25,6 +25,22 @@ RSpec.describe Form, type: :model do
it "validates number of relets is over 0" do
expect { CaseLog.create!(property_number_of_times_relet: 0) }.to raise_error(ActiveRecord::RecordInvalid)
end
context "other reason for leaving last settled home validation" do
it "must be provided if main reason for leaving last settled home was given as other" do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Other",
other_reason_for_leaving_last_settled_home: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must not be provided if the main reason for leaving settled home is not other" do
expect {
CaseLog.create!(reason_for_leaving_last_settled_home: "Repossession",
other_reason_for_leaving_last_settled_home: "the other reason provided")
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
end
describe "status" do

Loading…
Cancel
Save