Browse Source

Add armed forces injured validation

pull/60/head
MadeTech Dushan 3 years ago
parent
commit
f74d3b763f
  1. 10
      app/models/case_log.rb
  2. 2
      spec/helpers/check_answers_helper_spec.rb
  3. 19
      spec/models/case_log_spec.rb

10
app/models/case_log.rb

@ -39,6 +39,16 @@ class CaseLogValidator < ActiveModel::Validator
end
end
def validate_armed_forces_injured(record)
if (record.armed_forces == "Yes - a regular" || record.armed_forces == "Yes - a reserve") && record.armed_forces_injured.blank?
record.errors.add :armed_forces_injured, "You must answer the armed forces injury question if the tenant has served in the armed forces"
end
if (record.armed_forces == "No" || record.armed_forces == "Prefer not to say") && record.armed_forces_injured.present?
record.errors.add :armed_forces_injured, "You must not answer the armed forces injury question if the tenant has not served in the armed forces or prefer not to say was chosen"
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

2
spec/helpers/check_answers_helper_spec.rb

@ -11,7 +11,7 @@ RSpec.describe CheckAnswersHelper do
)
end
let(:case_log_with_met_radio_condition) do
FactoryBot.create(:case_log, armed_forces: "Yes - a regular")
FactoryBot.create(:case_log, armed_forces: "Yes - a regular", armed_forces_injured: "No")
end
let(:subsection) { "income_and_benefits" }
let(:subsection_with_numeric_conditionals) { "household_characteristics" }

19
spec/models/case_log_spec.rb

@ -26,7 +26,7 @@ RSpec.describe Form, type: :model do
expect { CaseLog.create!(property_number_of_times_relet: 0) }.to raise_error(ActiveRecord::RecordInvalid)
end
describe "reasonable preference validation" do
context "reasonable preference validation" do
it "if given reasonable preference is yes a reason must be selected" do
expect {
CaseLog.create!(reasonable_preference: "Yes",
@ -57,6 +57,7 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid)
end
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 {
@ -72,6 +73,22 @@ RSpec.describe Form, type: :model do
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
context "armed forces injured validation" do
it "must be anwered if tenant was a regular or reserve in armed forces" do
expect {
CaseLog.create!(armed_forces: "Yes - a regular",
armed_forces_injured: nil)
}.to raise_error(ActiveRecord::RecordInvalid)
end
it "must be anwered if tenant was not a regular or reserve in armed forces" do
expect {
CaseLog.create!(armed_forces: "No",
armed_forces_injured: "Yes")
}.to raise_error(ActiveRecord::RecordInvalid)
end
end
end
describe "status" do

Loading…
Cancel
Save