Skip to content

Commit

Permalink
use pre-submit form to check for all sections being completed in both…
Browse files Browse the repository at this point in the history
… apply and review steps
  • Loading branch information
starswan committed Jan 16, 2025
1 parent 515b6a5 commit a32e815
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 43 deletions.
7 changes: 5 additions & 2 deletions app/controllers/jobseekers/job_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def create
end

def pre_submit
if all_steps_valid?
@form = Jobseekers::JobApplication::PreSubmitForm.new(completed_steps: job_application.completed_steps, all_steps: step_process.steps.excluding(:review).map(&:to_s))
if @form.valid? && all_steps_valid?
redirect_to jobseekers_job_application_review_path(@job_application)
else
render :apply
Expand All @@ -58,7 +59,9 @@ def new_quick_apply
raise ActionController::RoutingError, "Cannot quick apply if there's no profile or non-draft applications" unless quick_apply?
end

def apply; end
def apply
@form = Jobseekers::JobApplication::PreSubmitForm.new(completed_steps: job_application.completed_steps, all_steps: step_process.steps.excluding(:review).map(&:to_s))
end

def quick_apply
raise ActionController::RoutingError, "Cannot quick apply if there's no profile or non-draft applications" unless quick_apply?
Expand Down
26 changes: 26 additions & 0 deletions app/form_models/jobseekers/job_application/pre_submit_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

module Jobseekers
module JobApplication
class PreSubmitForm
include ActiveModel::Model

attr_accessor :completed_steps, :all_steps

validate :all_steps_completed?

def all_steps_completed?
all_steps.each do |step|
next if step.in?(completed_steps)

errors.add(
:base,
# I18n.t("activemodel.errors.models.jobseekers/job_application/review_form.attributes.#{step}.incomplete"),
"#{step}.incomplete".to_sym,
)
end
end
end
end
end

19 changes: 2 additions & 17 deletions app/form_models/jobseekers/job_application/review_form.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
class Jobseekers::JobApplication::ReviewForm
include ActiveModel::Model

attr_accessor :confirm_data_accurate, :confirm_data_usage, :update_profile, :completed_steps, :all_steps
class Jobseekers::JobApplication::ReviewForm < Jobseekers::JobApplication::PreSubmitForm
attr_accessor :confirm_data_accurate, :confirm_data_usage, :update_profile

validates_acceptance_of :confirm_data_accurate, :confirm_data_usage,
acceptance: true,
if: :all_steps_completed?
validate :all_steps_completed?

def all_steps_completed?
all_steps.each do |step|
next if step.in?(completed_steps)

errors.add(
step.to_sym,
I18n.t("activemodel.errors.models.jobseekers/job_application/review_form.attributes.#{step}.incomplete"),
)
end
end

def update_profile_qualifications?
update_profile&.include?("qualifications")
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/jobseekers/job_applications/apply.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
= govuk_notification_banner title_text: t("banners.important") do
p.govuk-body = t(".deadline_passed")

- unless review_form.errors.any?
- unless @form.errors.any?
= render "shared/error_messages", model: @job_application, presenter: ErrorSummaryPresenter.new(@job_application.errors)

h2.govuk-heading-m = t(".heading")
Expand Down Expand Up @@ -63,7 +63,7 @@

- r.with_below do
- unless @job_application.deadline_passed?
= form_for review_form, url: jobseekers_job_application_pre_submit_path(job_application), method: :post do |f|
= form_for @form, url: jobseekers_job_application_pre_submit_path(job_application), method: :post do |f|
= f.govuk_error_summary

- if vacancy.listed?
Expand Down
41 changes: 21 additions & 20 deletions config/locales/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -480,32 +480,33 @@ en:
attributes:
training_and_cpds_section_completed:
blank: Select yes if you have completed this section
jobseekers/job_application/pre_submit_form:
ask_for_support:
incomplete: Complete the questions on interview support
employment_history:
incomplete: Complete your employment history
equal_opportunities:
incomplete: Complete the questions on equal opportunities
declarations:
incomplete: Complete the declarations
personal_details:
incomplete: Complete your personal details
personal_statement:
incomplete: Complete your personal statement
professional_status:
incomplete: Complete the questions about your professional status
qualifications:
incomplete: Complete your qualifications
references:
incomplete: Complete your references
training_and_cpds:
incomplete: Complete your training and CPD
jobseekers/job_application/review_form:
attributes:
confirm_data_accurate:
accepted: You must confirm that your information is accurate and complete
confirm_data_usage:
accepted: You must consent to share your data in order to apply for this job
ask_for_support:
incomplete: Complete the questions on interview support
employment_history:
incomplete: Complete your employment history
equal_opportunities:
incomplete: Complete the questions on equal opportunities
declarations:
incomplete: Complete the declarations
personal_details:
incomplete: Complete your personal details
personal_statement:
incomplete: Complete your personal statement
professional_status:
incomplete: Complete the questions about your professional status
qualifications:
incomplete: Complete your qualifications
references:
incomplete: Complete your references
training_and_cpds:
incomplete: Complete your training and CPD
jobseekers/job_application/withdraw_form:
attributes:
withdraw_reason:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
it "is invalid" do
expect(subject).not_to be_valid
incomplete_steps.each do |incomplete_step|
expect(subject.errors.messages_for(incomplete_step))
.to include(I18n.t("activemodel.errors.models.jobseekers/job_application/review_form.attributes.#{incomplete_step}.incomplete"))
expect(subject.errors.messages_for(:base))
.to include(I18n.t("activemodel.errors.models.jobseekers/job_application/pre_submit_form.#{incomplete_step}.incomplete"))
end
end
end
Expand Down

0 comments on commit a32e815

Please sign in to comment.