-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As in claim the entry date form writes to the date_of_entry attribute. We also reset the date of entry if the start date changes as the eligibility calculation for date of entry depends on the start date. Of note there doesn't seem to be a validation in claim that the date of entry isn't _after_ the start date of the contract. I'm not sure if that's a business rule we want to enforce or not. There is a validation that the date of entry isn't in the future.
- Loading branch information
Showing
19 changed files
with
300 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/forms/journeys/get_a_teacher_relocation_payment/entry_date_form.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 Journeys | ||
module GetATeacherRelocationPayment | ||
class EntryDateForm < Form | ||
include ActiveRecord::AttributeAssignment | ||
|
||
attribute :date_of_entry, :date | ||
|
||
validates :date_of_entry, presence: { | ||
message: i18n_error_message(:presence) | ||
} | ||
|
||
validates :date_of_entry, | ||
comparison: { | ||
less_than: ->(_) { Date.tomorrow }, | ||
message: i18n_error_message(:date_not_in_future) | ||
}, if: :date_of_entry | ||
|
||
def initialize(journey_session:, journey:, params:) | ||
super | ||
|
||
# Handle setting date from multi part params see | ||
# ActiveRecord::AttributeAssignment | ||
_assign_attributes(permitted_params) | ||
rescue ActiveRecord::MultiparameterAssignmentErrors | ||
# Invalid date was entered | ||
self.date_of_entry = nil | ||
end | ||
|
||
def save | ||
return false unless valid? | ||
|
||
journey_session.answers.assign_attributes(date_of_entry: date_of_entry) | ||
|
||
journey_session.save! | ||
end | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ class SlugSequence | |
"start-date", | ||
"subject", | ||
"visa", | ||
"entry-date", | ||
"check-your-answers-part-one" | ||
] | ||
|
||
|
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
30 changes: 30 additions & 0 deletions
30
app/views/get_a_teacher_relocation_payment/claims/entry_date.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,30 @@ | ||
<% content_for( | ||
:page_title, | ||
page_title( | ||
t("get_a_teacher_relocation_payment.forms.entry_date.question"), | ||
journey: current_journey_routing_name, | ||
show_error: @form.errors.any? | ||
) | ||
) %> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_for( | ||
@form, | ||
url: claim_path(current_journey_routing_name), | ||
builder: GOVUKDesignSystemFormBuilder::FormBuilder | ||
) do |f| %> | ||
<% if f.object.errors.any? %> | ||
<%= render("shared/error_summary", instance: f.object) %> | ||
<% end %> | ||
|
||
<%= f.govuk_date_field( | ||
:date_of_entry, | ||
legend: { | ||
text: t("get_a_teacher_relocation_payment.forms.entry_date.question") | ||
}, | ||
) %> | ||
|
||
<%= f.govuk_submit %> | ||
<% end %> | ||
</div> | ||
</div> |
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 |
---|---|---|
|
@@ -198,6 +198,7 @@ shared: | |
- start_date | ||
- subject | ||
- visa_type | ||
- date_of_entry | ||
:schools: | ||
- id | ||
- urn | ||
|
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
...te/20240621200501_add_date_of_entry_to_international_relocation_payments_eligibilities.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 AddDateOfEntryToInternationalRelocationPaymentsEligibilities < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :international_relocation_payments_eligibilities, :date_of_entry, :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
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
102 changes: 102 additions & 0 deletions
102
spec/forms/journeys/get_a_teacher_relocation_payment/entry_date_form_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,102 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Journeys::GetATeacherRelocationPayment::EntryDateForm, type: :model do | ||
let(:journey_session) { create(:get_a_teacher_relocation_payment_session) } | ||
|
||
let(:params) do | ||
ActionController::Parameters.new( | ||
claim: multi_part_date_parms(option) | ||
) | ||
end | ||
|
||
let(:option) { nil } | ||
|
||
def multi_part_date_parms(date) | ||
return {} unless date.present? | ||
|
||
{ | ||
"date_of_entry(1i)" => date.year.to_s, | ||
"date_of_entry(2i)" => date.month.to_s, | ||
"date_of_entry(3i)" => date.day.to_s | ||
} | ||
end | ||
|
||
let(:form) do | ||
described_class.new( | ||
journey_session: journey_session, | ||
journey: Journeys::GetATeacherRelocationPayment, | ||
params: params | ||
) | ||
end | ||
|
||
describe "validations" do | ||
subject { form } | ||
|
||
context "with an invalid date" do | ||
it { is_expected.not_to be_valid } | ||
end | ||
|
||
context "with a date in the future" do | ||
it do | ||
is_expected.not_to( | ||
allow_value(Date.tomorrow) | ||
.for(:date_of_entry) | ||
.with_message("Date of entry cannot be in the future") | ||
) | ||
end | ||
end | ||
|
||
context "with a date in the present" do | ||
it { is_expected.to allow_value(Date.today).for(:date_of_entry) } | ||
end | ||
|
||
context "with a date in the past" do | ||
it { is_expected.to allow_value(Date.yesterday).for(:date_of_entry) } | ||
end | ||
end | ||
|
||
describe "#date_of_entry" do | ||
subject { form.date_of_entry } | ||
|
||
before do | ||
journey_session.answers.assign_attributes(date_of_entry: Date.tomorrow) | ||
end | ||
|
||
context "when date is not present in the params" do | ||
let(:option) { nil } | ||
|
||
it { is_expected.to eq(journey_session.answers.date_of_entry) } | ||
end | ||
|
||
context "when date is persent in the params" do | ||
let(:option) { Date.yesterday } | ||
|
||
it { is_expected.to eq(option) } | ||
end | ||
|
||
context "when date is invalid" do | ||
let(:params) do | ||
ActionController::Parameters.new( | ||
claim: { | ||
"date_of_entry(1i)" => "01", | ||
"date_of_entry(2i)" => "00", | ||
"date_of_entry(3i)" => "2024" | ||
} | ||
) | ||
end | ||
|
||
it { is_expected.to be_nil } | ||
end | ||
end | ||
|
||
describe "#save" do | ||
let(:option) { Date.yesterday } | ||
|
||
it "updates the journey session" do | ||
expect { expect(form.save).to be(true) }.to( | ||
change { journey_session.reload.answers.date_of_entry } | ||
.to(option) | ||
) | ||
end | ||
end | ||
end |
Oops, something went wrong.