-
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.
A business requirement is to only allow applicants between 21 and 80 years old, as per the previous IRP application.
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
app/forms/journeys/get_a_teacher_relocation_payment/personal_details_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,19 @@ | ||
module Journeys | ||
module GetATeacherRelocationPayment | ||
class PersonalDetailsForm < PersonalDetailsForm | ||
with_options if: -> { date_of_birth && date_of_birth.is_a?(Date) } do | ||
validates :date_of_birth, | ||
comparison: { | ||
less_than_or_equal_to: ->(_) { 21.years.ago }, | ||
message: PersonalDetailsForm.i18n_error_message(:below_min_age) | ||
} | ||
|
||
validates :date_of_birth, | ||
comparison: { | ||
greater_than: ->(_) { 80.years.ago }, | ||
message: PersonalDetailsForm.i18n_error_message(:over_max_age) | ||
} | ||
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
49 changes: 49 additions & 0 deletions
49
spec/forms/journeys/get_a_teacher_relocation_payment/personal_details_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,49 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Journeys::GetATeacherRelocationPayment::PersonalDetailsForm, type: :model do | ||
let(:journey_session) { build(:get_a_teacher_relocation_payment_session) } | ||
|
||
subject(:form) do | ||
described_class.new( | ||
journey_session: journey_session, | ||
journey: Journeys::GetATeacherRelocationPayment, | ||
params: ActionController::Parameters.new({}) | ||
) | ||
end | ||
|
||
describe "validations" do | ||
before do | ||
form.assign_attributes( | ||
day: date_of_birth.day, | ||
month: date_of_birth.month, | ||
year: date_of_birth.year | ||
) | ||
|
||
form.valid? | ||
end | ||
|
||
context "with too young of a birth date" do | ||
let(:date_of_birth) { 20.years.ago } | ||
|
||
it "does not permit the date of birth" do | ||
expect(form.errors[:date_of_birth]).to include("Age must be above 21") | ||
end | ||
end | ||
|
||
context "with too old of a birth date" do | ||
let(:date_of_birth) { 80.years.ago } | ||
|
||
it "does not permit the date of birth" do | ||
expect(form.errors[:date_of_birth]).to include("Age must be below 80") | ||
end | ||
end | ||
|
||
context "with a valid birth date" do | ||
let(:date_of_birth) { 30.years.ago } | ||
|
||
it "permits the date of birth" do | ||
expect(form.errors[:date_of_birth]).to be_empty | ||
end | ||
end | ||
end | ||
end |