Skip to content

Commit

Permalink
Merge pull request #2928 from DFE-Digital/CAPT-1742/dont-allow-future…
Browse files Browse the repository at this point in the history
…-start-dates

CAPT 1742/dont allow future start dates
  • Loading branch information
rjlynch authored Jun 27, 2024
2 parents 636cbfc + f4932ef commit 123eea5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ module GetATeacherRelocationPayment
class StartDateForm < Form
include ActiveRecord::AttributeAssignment

attribute :start_date, :date

validates :start_date,
presence: {
message: i18n_error_message(:presence)
}

attribute :start_date, :date
validates :start_date,
comparison: {
less_than: ->(_) { Date.tomorrow },
message: i18n_error_message(:date_not_in_future)
}, if: :start_date

def initialize(journey_session:, journey:, params:)
super
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ en:
question: "Enter the start date of your contract"
errors:
presence: "Enter your contract start date"
date_not_in_future: "Start date cannot be in the future"
subject:
question: "What subject are you employed to teach at your school?"
hint: "Physics, general or combined science including physics, and languages can be combined with other subjects but must make up at least 50% of your time in the classroom."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

let(:contract_start_date) do
Date.tomorrow
Date.yesterday
end

let(:entry_date) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
)
end

let(:option) { nil }

def multi_part_date_parms(date)
return {} unless date.present?

Expand All @@ -31,27 +33,25 @@ def multi_part_date_parms(date)
subject { form }

context "with an invalid date" do
let(:option) { nil }

it { is_expected.not_to be_valid }
end

context "with a date in the future" do
let(:option) { Date.tomorrow }

it { is_expected.to be_valid }
it do
is_expected.not_to(
allow_value(Date.tomorrow)
.for(:start_date)
.with_message("Start date cannot be in the future")
)
end
end

context "with a date in the present" do
let(:option) { Date.today }

it { is_expected.to be_valid }
it { is_expected.to allow_value(Date.today).for(:start_date) }
end

context "with a date in the past" do
let(:option) { Date.yesterday }

it { is_expected.to be_valid }
it { is_expected.to allow_value(Date.yesterday).for(:start_date) }
end
end

Expand Down Expand Up @@ -90,7 +90,7 @@ def multi_part_date_parms(date)
end

describe "#save" do
let(:option) { Date.tomorrow }
let(:option) { Date.yesterday }

it "updates the journey session" do
expect { expect(form.save).to be(true) }.to(
Expand Down

0 comments on commit 123eea5

Please sign in to comment.