Skip to content

Commit

Permalink
[5921] Show the first error messages of each attribute in forms (#5976)
Browse files Browse the repository at this point in the history
* show less error messagesin casa_cases

* fix rspec
  • Loading branch information
ElisaRmz authored Aug 31, 2024
1 parent 8b416e3 commit 9296150
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
6 changes: 4 additions & 2 deletions app/models/concerns/CasaCase/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 4 additions & 2 deletions app/models/court_date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions spec/requests/casa_cases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions spec/requests/court_dates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9296150

Please sign in to comment.