Skip to content

Commit

Permalink
Ensure start date year has 4 digits
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailMcP authored and AbigailMcP committed Aug 23, 2024
1 parent 00794f1 commit 06cc8fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class StartDateForm < Form
attribute :start_date, :date

validates :start_date, presence: {message: i18n_error_message(:presence)}
validate :start_year_has_four_digits, if: -> { start_date.present? }

def initialize(journey_session:, journey:, params:)
super
Expand All @@ -30,6 +31,12 @@ def save
def nursery_name
EligibleEyProvider.find_by(urn: answers.nursery_urn)&.nursery_name
end

def start_year_has_four_digits
if start_date.year < 1000
errors.add(:start_date, "Year must include 4 numbers")
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@

describe "validations" do
it { should validate_presence_of(:start_date).with_message("Provide a date in the format 27 3 2024") }

context "when the year doesn't have 4 digits" do
let(:day) { 1 }
let(:month) { 1 }
let(:year) { 24 }

it "returns an error" do
subject.save
expect(subject.errors[:start_date]).to include("Year must include 4 numbers")
end
end
end

describe "#save" do
Expand Down

0 comments on commit 06cc8fc

Please sign in to comment.