From 9296150e29a8938c55c91f3fd17d8881e347c363 Mon Sep 17 00:00:00 2001 From: ElisaRmz Date: Sat, 31 Aug 2024 17:21:17 +0200 Subject: [PATCH] [5921] Show the first error messages of each attribute in forms (#5976) * show less error messagesin casa_cases * fix rspec --- app/models/concerns/CasaCase/validations.rb | 6 ++++-- app/models/court_date.rb | 6 ++++-- spec/requests/casa_cases_spec.rb | 2 -- spec/requests/court_dates_spec.rb | 8 ++------ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/models/concerns/CasaCase/validations.rb b/app/models/concerns/CasaCase/validations.rb index 0cca86f038..43126cdd80 100644 --- a/app/models/concerns/CasaCase/validations.rb +++ b/app/models/concerns/CasaCase/validations.rb @@ -7,11 +7,13 @@ module CasaCase::Validations validates :birth_month_year_youth, presence: true validates :birth_month_year_youth, comparison: { less_than_or_equal_to: -> { Time.now.end_of_day }, - message: "is not valid: Youth's Birth Month & Year cannot be a future date." + message: "is not valid: Youth's Birth Month & Year cannot be a future date.", + allow_nil: true } validates :birth_month_year_youth, comparison: { greater_than_or_equal_to: "1989-01-01".to_date, - message: "is not valid: Youth's Birth Month & Year cannot be prior to 1/1/1989." + message: "is not valid: Youth's Birth Month & Year cannot be prior to 1/1/1989.", + allow_nil: true } validates :date_in_care, comparison: { diff --git a/app/models/court_date.rb b/app/models/court_date.rb index b2bdaa9438..d4b5add8af 100644 --- a/app/models/court_date.rb +++ b/app/models/court_date.rb @@ -8,11 +8,13 @@ class CourtDate < ApplicationRecord validates :date, presence: true validates :date, comparison: { less_than_or_equal_to: -> { 1.year.from_now }, - message: "is not valid. Court date must be within one year from today." + message: "is not valid. Court date must be within one year from today.", + allow_nil: true } validates :date, comparison: { greater_than_or_equal_to: "1989-01-01".to_date, - message: "is not valid. Court date cannot be prior to 1/1/1989." + message: "is not valid. Court date cannot be prior to 1/1/1989.", + allow_nil: true } has_many :case_court_orders diff --git a/spec/requests/casa_cases_spec.rb b/spec/requests/casa_cases_spec.rb index 98ea95562e..237207e17e 100644 --- a/spec/requests/casa_cases_spec.rb +++ b/spec/requests/casa_cases_spec.rb @@ -243,8 +243,6 @@ expect(response).to have_http_status(:unprocessable_entity) expected_response_body = [ "Birth month year youth can't be blank", - "Birth month year youth is not valid: Youth's Birth Month & Year cannot be a future date.", - "Birth month year youth is not valid: Youth's Birth Month & Year cannot be prior to 1/1/1989.", "Case number can't be blank", "Casa case contact types : At least one contact type must be selected" ].to_json diff --git a/spec/requests/court_dates_spec.rb b/spec/requests/court_dates_spec.rb index ddec9c15ce..7484f2d1b8 100644 --- a/spec/requests/court_dates_spec.rb +++ b/spec/requests/court_dates_spec.rb @@ -264,9 +264,7 @@ post casa_case_court_dates_path(casa_case), params: {court_date: invalid_attributes} expect(response).to have_http_status(:unprocessable_entity) expected_errors = [ - "Date can't be blank", - "Date is not valid. Court date must be within one year from today.", - "Date is not valid. Court date cannot be prior to 1/1/1989." + "Date can't be blank" ].freeze expect(assigns[:court_date].errors.full_messages).to eq expected_errors end @@ -310,9 +308,7 @@ expect(response).to have_http_status(:unprocessable_entity) expected_errors = [ - "Date can't be blank", - "Date is not valid. Court date must be within one year from today.", - "Date is not valid. Court date cannot be prior to 1/1/1989." + "Date can't be blank" ].freeze expect(assigns[:court_date].errors.full_messages).to eq expected_errors end