Skip to content

Commit

Permalink
Rename validation contexts so they're consistent (#420)
Browse files Browse the repository at this point in the history
It's easier to follow when the validation contexts match the names of
the flows/steps they're triggered by. Instead of grouping the releaseing
and completion of an ECT induction into 'record_period' they've been
split to 'release_ect' and 'record_outcome'. This makes it more obvious
when they're used.
  • Loading branch information
peteryates authored Oct 7, 2024
2 parents 3086dbe + 77e6c26 commit cc21856
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
release_ect = AppropriateBodies::ReleaseECT.new(appropriate_body: @appropriate_body, pending_induction_submission: @pending_induction_submission)

PendingInductionSubmission.transaction do
if @pending_induction_submission.save(context: :record_period) && release_ect.release!
if @pending_induction_submission.save(context: :release_ect) && release_ect.release!
redirect_to ab_teacher_release_ect_path(@teacher)
else
render :new
Expand Down
4 changes: 2 additions & 2 deletions app/models/pending_induction_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class PendingInductionSubmission < ApplicationRecord

validates :finished_on,
presence: { message: "Enter a finish date" },
on: :record_period
on: %i[release_ect record_outcome]

validates :number_of_terms,
inclusion: { in: 0..16,
message: "Terms must be between 0 and 16" },
on: :record_period
on: %i[release_ect record_outcome]

validates :date_of_birth,
presence: { message: "Enter a date of birth" },
Expand Down
10 changes: 9 additions & 1 deletion spec/models/pending_induction_submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,16 @@
it { is_expected.to validate_inclusion_of(:induction_programme).in_array(%w[fip cip diy]).with_message("Choose an induction programme").on(:register_ect) }
end

describe "started_on" do
it { is_expected.to validate_presence_of(:started_on).with_message("Enter a start date").on(:register_ect) }
end

describe "finished_on" do
it { is_expected.to validate_presence_of(:finished_on).with_message("Enter a finish date").on(%i[release_ect record_outcome]) }
end

describe "number_of_terms" do
it { is_expected.to validate_inclusion_of(:number_of_terms).in_range(0..16).with_message("Terms must be between 0 and 16").on(:record_period) }
it { is_expected.to validate_inclusion_of(:number_of_terms).in_range(0..16).with_message("Terms must be between 0 and 16").on(%i[release_ect record_outcome]) }
end

describe "confirmed" do
Expand Down

0 comments on commit cc21856

Please sign in to comment.