generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/controllers/support/cases/evaluation_due_dates_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Support | ||
class Cases::EvaluationDueDatesController < Cases::ApplicationController | ||
before_action :set_current_case | ||
before_action { @back_url = support_case_path(@current_case, anchor: "tasklist") } | ||
|
||
include HasDateParams | ||
def edit | ||
@case_evaluation_due_date_form = CaseEvaluationDueDateForm.new(**current_case.to_h) | ||
end | ||
|
||
def update | ||
@case_evaluation_due_date_form = CaseEvaluationDueDateForm.from_validation(validation) | ||
|
||
if validation.success? | ||
@current_case.update!(@case_evaluation_due_date_form.to_h) | ||
redirect_to @back_url | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_current_case | ||
@current_case = Support::Case.find(params[:case_id]) | ||
end | ||
|
||
def validation | ||
@validation ||= CaseEvaluationDueDateFormSchema.new.call(**evaluation_due_date_params) | ||
end | ||
|
||
def evaluation_due_date_params | ||
form_params = params.require(:case_evaluation_due_date_form).permit | ||
form_params[:evaluation_due_date] = date_param(:case_evaluation_due_date_form, :evaluation_due_date) | ||
form_params | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Support | ||
class CaseEvaluationDueDateForm < Form | ||
option :evaluation_due_date, Types::DateField, optional: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Support | ||
class CaseEvaluationDueDateFormSchema < ::Support::Schema | ||
config.messages.top_namespace = :case_evaluation_due_date_form | ||
|
||
params do | ||
required(:evaluation_due_date).value(:hash) | ||
end | ||
|
||
rule(:evaluation_due_date) do | ||
key.failure(:missing) if value.values.all?(&:blank?) | ||
end | ||
|
||
rule :evaluation_due_date do | ||
key.failure(:invalid) unless value.values.all?(&:blank?) || hash_to_date.call(value) | ||
end | ||
|
||
rule :evaluation_due_date do | ||
if value.present? | ||
date = hash_to_date.call(value) | ||
if date && date <= Time.zone.today | ||
key.failure(:must_be_in_the_future) | ||
end | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
app/views/support/cases/evaluation_due_dates/edit.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= render partial: "support/cases/components/case_header", locals: { current_case: @current_case } %> | ||
<h1 class="govuk-heading-l"><%= I18n.t("support.cases.evaluation_due_date.header") %></h1> | ||
|
||
<%= form_with model: @case_evaluation_due_date_form, scope: :case_evaluation_due_date_form, url: support_case_evaluation_due_dates_path(@current_case), method: :patch do |form| %> | ||
<%= form.govuk_error_summary %> | ||
<%= form.govuk_date_field :evaluation_due_date, legend: { text: I18n.t("support.cases.evaluation_due_date.date.label"), }, hint: { text: I18n.t("support.cases.evaluation_due_date.date.hint") } %> | ||
|
||
<div class="govuk-button-group flex-align-center"> | ||
<%= form.submit I18n.t("support.cases.evaluation_due_date.submit"), class: "govuk-button" %> | ||
<%= link_to I18n.t("support.cases.evaluation_due_date.cancel"), @back_url, class: "govuk-link govuk-link--no-visited-state" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20241126122758_add_evaluation_due_date_to_support_cases.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddEvaluationDueDateToSupportCases < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :support_cases, :evaluation_due_date, :date | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
spec/features/support/agent_can_add_evaluation_due_date_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "rails_helper" | ||
|
||
describe "Edit evaluation due date", :js do | ||
include_context "with an agent" | ||
|
||
let(:support_case) { create(:support_case) } | ||
|
||
specify "Update evaluation due date evaluators" do | ||
visit edit_support_case_evaluation_due_dates_path(case_id: support_case) | ||
|
||
expect(page).to have_text("Set due date") | ||
expect(page).to have_text("When does the evaluation need to be completed by?") | ||
|
||
fill_in "Day", with: "" | ||
fill_in "Month", with: "" | ||
fill_in "Year", with: "" | ||
click_button "Continue" | ||
|
||
expect(page).to have_text("Enter valid evaluation due date") | ||
|
||
fill_in "Day", with: Date.yesterday.day | ||
fill_in "Month", with: Date.yesterday.month | ||
fill_in "Year", with: Date.yesterday.year | ||
click_button "Continue" | ||
|
||
expect(page).to have_text("Evaluation due date must be in the future") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters