-
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.
Merge pull request #3092 from DFE-Digital/LUPEYALPHA-765-ey-who-are-y…
…ou-making-this-claim-for [LUPEYALPHA-765] EY - Who are you making this claim for?
- Loading branch information
Showing
10 changed files
with
165 additions
and
23 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
app/forms/journeys/early_years_payment/provider/authenticated/claimant_name_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,27 @@ | ||
module Journeys | ||
module EarlyYearsPayment | ||
module Provider | ||
module Authenticated | ||
class ClaimantNameForm < Form | ||
attribute :first_name | ||
attribute :surname | ||
|
||
validates :first_name, presence: {message: i18n_error_message("first_name.presence")} | ||
validates :first_name, length: {maximum: 100, message: i18n_error_message("first_name.length")}, if: -> { first_name.present? } | ||
validates :first_name, name_format: {message: i18n_error_message("first_name.format")} | ||
|
||
validates :surname, presence: {message: i18n_error_message("last_name.presence")} | ||
validates :surname, length: {maximum: 100, message: i18n_error_message("last_name.length")}, if: -> { surname.present? } | ||
validates :surname, name_format: {message: i18n_error_message("last_name.format")} | ||
|
||
def save | ||
return false if invalid? | ||
|
||
journey_session.answers.assign_attributes(first_name:, surname:) | ||
journey_session.save! | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ class SlugSequence | |
consent | ||
current-nursery | ||
claimant-name | ||
start-date | ||
ineligible | ||
].freeze | ||
|
||
|
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,11 @@ | ||
class NameFormatValidator < ActiveModel::EachValidator | ||
NAME_REGEX_FILTER = /\A[^\[\]\^"=$%#&*+\/\\()@?!<>_`|{}~0-9]*\z/ | ||
|
||
def validate_each(record, attribute, value) | ||
return unless value.present? | ||
|
||
unless NAME_REGEX_FILTER.match?(value) | ||
record.errors.add(attribute, options[:message]) | ||
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,23 @@ | ||
<% content_for(:page_title, page_title(@form.t(:question), journey: current_journey_routing_name, show_error: @form.errors.any?)) %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_with model: @form, url: claim_path(current_journey_routing_name), method: :patch, builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> | ||
<%= f.govuk_error_summary %> | ||
|
||
<h1 class="govuk-heading-l"> | ||
<%= @form.t(:question) %> | ||
</h1> | ||
|
||
<div class="govuk-hint"> | ||
<%= @form.t(:hint) %> | ||
</div> | ||
|
||
<%= f.govuk_text_field :first_name, label: { text: "First name" }, spellcheck: "false", autocomplete: "name" %> | ||
|
||
<%= f.govuk_text_field :surname, label: { text: "Last name" }, spellcheck: "false", autocomplete: "name" %> | ||
|
||
<%= f.govuk_submit "Continue" %> | ||
<% end %> | ||
</div> | ||
</div> |
1 change: 1 addition & 0 deletions
1
app/views/early_years_payment/provider/authenticated/claims/start_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 @@ | ||
|
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
50 changes: 50 additions & 0 deletions
50
spec/forms/journeys/early_years_payment/provider/authenticated/claimant_name_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,50 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe Journeys::EarlyYearsPayment::Provider::Authenticated::ClaimantNameForm, type: :model do | ||
let(:journey) { Journeys::EarlyYearsPayment::Provider::Authenticated } | ||
let(:journey_session) { create(:early_years_payment_provider_authenticated_session) } | ||
let(:first_name) { nil } | ||
let(:surname) { nil } | ||
|
||
let(:params) do | ||
ActionController::Parameters.new( | ||
claim: { | ||
first_name:, | ||
surname: | ||
} | ||
) | ||
end | ||
|
||
subject do | ||
described_class.new(journey_session:, journey:, params:) | ||
end | ||
|
||
describe "validations" do | ||
# First name validations | ||
it { should validate_presence_of(:first_name).with_message("Enter employee’s first name") } | ||
it { should validate_length_of(:first_name).is_at_most(100).with_message("Employee’s first name must be less than 100 characters") } | ||
it { should allow_value("O'Brian").for(:first_name) } | ||
%w[* | { ^ /].each do |char| | ||
it { should_not allow_value(char).for(:first_name).with_message("Employee’s first name cannot contain special characters") } | ||
end | ||
|
||
# Surname validations | ||
it { should validate_presence_of(:surname).with_message("Enter employee’s last name") } | ||
it { should validate_length_of(:surname).is_at_most(100).with_message("Employee’s last name must be less than 100 characters") } | ||
it { should_not allow_value("5").for(:surname).with_message("Employee’s last name cannot contain special characters") } | ||
it { should allow_value("O'Brian").for(:surname) } | ||
end | ||
|
||
describe "#save" do | ||
let(:first_name) { "Bobby" } | ||
let(:surname) { "Bobberson" } | ||
|
||
it "updates the journey session" do | ||
expect { subject.save }.to( | ||
change { journey_session.answers.first_name }.to(first_name).and( | ||
change { journey_session.answers.surname }.to(surname) | ||
) | ||
) | ||
end | ||
end | ||
end |