Skip to content

Commit

Permalink
Add validation to evaluators form
Browse files Browse the repository at this point in the history
  • Loading branch information
serenaabbott11 authored and edwin-jebaraj committed Dec 13, 2024
1 parent 6ada51b commit 634f92b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app/models/support/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module Support
class Evaluator < ApplicationRecord
belongs_to :support_case, class_name: "Support::Case"

include HasNormalizedEmail

validates :email,
presence: true,
format: { with: URI::MailTo::EMAIL_REGEXP },
uniqueness: { case_sensitive: false, scope: :support_case_id }
validates :first_name, :last_name, presence: true

Expand Down
12 changes: 10 additions & 2 deletions config/locales/validation/support/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ en:
attributes:
body:
blank: Please enter a case note
support/evaluator:
attributes:
email:
blank: Enter the email address of the evaluator
invalid: Enter an email address in the correct format, like [email protected]
taken: This email address has already been added as an evaluator
first_name:
blank: Enter the first name of the evaluator
last_name:
blank: Enter the last name of the evaluator

activemodel:
errors:
Expand Down Expand Up @@ -65,8 +75,6 @@ en:
blank: Select files to upload
has_uploaded_documents:
blank: Please confirm that you uploaded all documents



forms:
rules:
Expand Down
14 changes: 14 additions & 0 deletions spec/models/support/evaluator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,19 @@
evaluator.support_case = case_b
expect(evaluator).to be_valid
end

it "doesn't allow invalid email formats" do
support_case = create(:support_case)
evaluator = build(:support_evaluator, support_case:)

evaluator.email = "test.example.com"
expect(evaluator).not_to be_valid

evaluator.email = "@example.com"
expect(evaluator).not_to be_valid

evaluator.email = "example"
expect(evaluator).not_to be_valid
end
end
end

0 comments on commit 634f92b

Please sign in to comment.