diff --git a/app/controllers/support/cases/evaluators_controller.rb b/app/controllers/support/cases/evaluators_controller.rb index 2376f71f2..75d7bfcd1 100644 --- a/app/controllers/support/cases/evaluators_controller.rb +++ b/app/controllers/support/cases/evaluators_controller.rb @@ -3,6 +3,13 @@ class Cases::EvaluatorsController < Cases::ApplicationController before_action :set_current_case before_action :set_evaluator, only: %i[edit update destroy] + before_action only: %i[new create edit update destroy] do + @back_url = support_case_evaluators_path(@current_case) + end + + before_action only: [:index] do + @back_url = support_case_path(@current_case, anchor: "tasklist") + end def index @evaluators = @current_case.evaluators.all end diff --git a/app/models/support/evaluator.rb b/app/models/support/evaluator.rb index b7337a204..7ee49559f 100644 --- a/app/models/support/evaluator.rb +++ b/app/models/support/evaluator.rb @@ -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 diff --git a/app/views/support/cases/show/_tasklist.html.erb b/app/views/support/cases/show/_tasklist.html.erb index 352157ac9..e7602608a 100644 --- a/app/views/support/cases/show/_tasklist.html.erb +++ b/app/views/support/cases/show/_tasklist.html.erb @@ -8,7 +8,7 @@ <%= I18n.t("support.case.label.tasklist.complete_evaluation") %> <%= govuk_task_list(id_prefix: "complete-evaluation") do |task_list| - task_list.with_item(title: I18n.t("support.case.label.tasklist.item.add_evaluators"), href: '#', status: govuk_tag(text: I18n.t("support.case.label.tasklist.status.to_do"))) + task_list.with_item(title: I18n.t("support.case.label.tasklist.item.add_evaluators"), href: support_case_evaluators_path(@current_case), status: @current_case.evaluators.present? ? govuk_tag(text: I18n.t("support.case.label.tasklist.status.complete"), colour: "green") : govuk_tag(text: I18n.t("support.case.label.tasklist.status.to_do"))) task_list.with_item(title: I18n.t("support.case.label.tasklist.item.set_due_date"), href: edit_support_case_evaluation_due_dates_path(@current_case), status: @current_case.evaluation_due_date ? govuk_tag(text: I18n.t("support.case.label.tasklist.status.complete"), colour: "green") : govuk_tag(text: I18n.t("support.case.label.tasklist.status.to_do"))) if @current_case.has_uploaded_documents == true diff --git a/config/locales/validation/support/en.yml b/config/locales/validation/support/en.yml index b73d548f1..de3aa69af 100644 --- a/config/locales/validation/support/en.yml +++ b/config/locales/validation/support/en.yml @@ -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 name@example.com + 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: @@ -65,8 +75,6 @@ en: blank: Select files to upload has_uploaded_documents: blank: Please confirm that you uploaded all documents - - forms: rules: diff --git a/spec/features/support/case_tasklist_spec.rb b/spec/features/support/case_tasklist_spec.rb index a97716e98..94c61c470 100644 --- a/spec/features/support/case_tasklist_spec.rb +++ b/spec/features/support/case_tasklist_spec.rb @@ -13,6 +13,14 @@ expect(page).to have_text("Procurement task list") expect(page).to have_text("Complete evaluation") expect(page).to have_css(".govuk-task-list") + expect(page).to have_link("Add evaluators") + end + end + + it "navigates to the add evaluators page when clicked" do + within "#tasklist" do + click_link "Add evaluators" + expect(page).to have_current_path("/support/cases/#{support_case.id}/evaluators") end end end diff --git a/spec/models/support/evaluator_spec.rb b/spec/models/support/evaluator_spec.rb index 5cb169bc0..1c6b4c0e8 100644 --- a/spec/models/support/evaluator_spec.rb +++ b/spec/models/support/evaluator_spec.rb @@ -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