Skip to content

Commit

Permalink
faith schools: Convert religious forms to single step with 'complete …
Browse files Browse the repository at this point in the history
…later' field (#7435)
  • Loading branch information
starswan committed Jan 29, 2025
1 parent ac15171 commit 708689f
Show file tree
Hide file tree
Showing 41 changed files with 367 additions and 451 deletions.
4 changes: 2 additions & 2 deletions app/components/job_application_review_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class JobApplicationReviewComponent < ApplicationComponent

renders_many(:sections, lambda do |section_name, **kwargs|
case section_name
when :catholic_following_religion
when :catholic
CatholicReligiousInformationSection.new(@job_application,
name: section_name,
allow_edit: @allow_edit)
when :school_ethos
when :non_catholic
NonCatholicReligiousInformationSection.new(@job_application,
name: section_name,
allow_edit: @allow_edit)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
class JobApplicationReviewComponent::CatholicReligiousInformationSection < JobApplicationReviewComponent::Section
def initialize(job_application, allow_edit:, name:)
# only include the details form if we follow a religion
forms = if job_application.following_religion
%w[CatholicFollowingReligionForm CatholicReligionDetailsForm]
else
%w[CatholicFollowingReligionForm]
end
super(job_application, forms: forms, name: name, allow_edit: allow_edit)
super(job_application, forms: %w[CatholicForm], name: name, allow_edit: allow_edit)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

class JobApplicationReviewComponent::NonCatholicReligiousInformationSection < JobApplicationReviewComponent::Section
def initialize(job_application, allow_edit:, name:)
# only include the details form if we follow a religion
forms = if job_application.following_religion
%w[SchoolEthosForm NonCatholicFollowingReligionForm NonCatholicReligionDetailsForm]
else
%w[SchoolEthosForm NonCatholicFollowingReligionForm]
end
super(job_application, forms: forms, name: name, allow_edit: allow_edit)
super(job_application, forms: %w[NonCatholicForm], name: name, allow_edit: allow_edit)
end
end
17 changes: 3 additions & 14 deletions app/controllers/jobseekers/job_applications/build_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,12 @@ def form_attributes
when "show"
form_class.load_form(job_application)
when "update"
form_params
form_class.load_form(job_application).merge(form_params)
end

case step
when :professional_status
attributes.merge(jobseeker_profile_attributes)
.merge(trn_params)
when :references
attributes.merge(references: job_application.references)
attributes.merge(trn_params)
when :employment_history
attributes.merge(unexplained_employment_gaps: job_application.unexplained_employment_gaps)
else
Expand Down Expand Up @@ -108,7 +105,7 @@ def update_params
end

def update_fields
# This version doesn't work with date fields
# This version doesn't work with date fields as they are submitted in 3 parts (hence form_params doesn't contain the right key)
# form_class.storable_fields.select { |f| form_params.key?(f) }.index_with { |field| form.public_send(field) }
form_params.except(*form_class.unstorable_fields)
end
Expand All @@ -121,15 +118,7 @@ def vacancy
@vacancy ||= job_application.vacancy
end

def jobseeker_profile_attributes
{
jobseeker_profile: current_jobseeker.jobseeker_profile,
}
end

def trn_params
return {} unless step == :professional_status

{
teacher_reference_number: form_params[:teacher_reference_number] || current_jobseeker&.jobseeker_profile&.teacher_reference_number,
has_teacher_reference_number: form_params[:has_teacher_reference_number] || current_jobseeker&.jobseeker_profile&.has_teacher_reference_number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def unstorable_fields
end

def load_form(model)
load_form_attributes(model.attributes.merge(completed_attrs(model, :ask_for_support)))
super.merge(completed_attrs(model, :ask_for_support))
end
end
attr_accessor(*FIELDS)
Expand Down
6 changes: 1 addition & 5 deletions app/form_models/jobseekers/job_application/base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ def storable_fields
end

def load_form(model)
load_form_attributes(model.attributes)
end

def load_form_attributes(attrs)
attrs.symbolize_keys.slice(*fields)
model.slice(*storable_fields)
end
end
end
Expand Down

This file was deleted.

36 changes: 36 additions & 0 deletions app/form_models/jobseekers/job_application/catholic_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Jobseekers
module JobApplication
class CatholicForm < ReligiousInformationForm
FIELDS = %i[baptism_certificate
baptism_address].freeze

class << self
def storable_fields
super + FIELDS + [:baptism_date]
end

def unstorable_fields
%i[catholic_section_completed]
end

def load_form(model)
model.slice(*storable_fields).merge(completed_attrs(model, :catholic))
end
end

attr_accessor(*FIELDS)

attribute :baptism_date, :date

validates :religious_reference_type,
inclusion: { in: ::JobApplication::RELIGIOUS_REFERENCE_TYPES.keys.map(&:to_s), nil: false },
if: -> { catholic_section_completed && following_religion }

completed_attribute(:catholic)

def section_completed
catholic_section_completed
end
end
end
end

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def unstorable_fields
end

def load_form(model)
load_form_attributes(model.attributes.merge(completed_attrs(model, :declarations)))
super.merge(completed_attrs(model, :declarations))
end
end
attr_accessor(*FIELDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def unstorable_fields
end

def load_form(model)
load_form_attributes(model.attributes.merge(completed_attrs(model, :employment_history)))
super.merge(completed_attrs(model, :employment_history))
end
end
attr_accessor(*FIELDS, :unexplained_employment_gaps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def unstorable_fields
end

def load_form(model)
load_form_attributes(model.attributes.merge(completed_attrs(model, :equal_opportunities)))
super.merge(completed_attrs(model, :equal_opportunities))
end
end
attr_accessor(*FIELDS)
Expand Down

This file was deleted.

This file was deleted.

31 changes: 31 additions & 0 deletions app/form_models/jobseekers/job_application/non_catholic_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Jobseekers
module JobApplication
class NonCatholicForm < ReligiousInformationForm
class << self
def storable_fields
super + [:ethos_and_aims]
end

def unstorable_fields
%i[non_catholic_section_completed]
end

def load_form(model)
super.merge(completed_attrs(model, :non_catholic))
end
end

attr_accessor(:ethos_and_aims)

validates_presence_of :ethos_and_aims

validates :religious_reference_type, inclusion: { in: %w[referee no_referee], nil: false }, if: -> { non_catholic_section_completed && following_religion }

completed_attribute(:non_catholic)

def section_completed
non_catholic_section_completed
end
end
end
end

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def load_form(model)
new_attrs = {
has_ni_number: model.national_insurance_number.present? ? "yes" : "no",
}.merge(completed_attrs(model, :personal_details))
load_form_attributes(model.attributes.merge(new_attrs))
super.merge(new_attrs)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def unstorable_fields
end

def load_form(model)
load_form_attributes(model.attributes.merge(completed_attrs(model, :personal_statement)))
super.merge(completed_attrs(model, :personal_statement))
end
end
attr_accessor(*FIELDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ class ProfessionalStatusForm < BaseForm
qualified_teacher_status_details
statutory_induction_complete
teacher_reference_number
has_teacher_reference_number
statutory_induction_complete_details
].freeze

attr_accessor(*FIELDS)
attr_accessor(*FIELDS, :has_teacher_reference_number)

class << self
def storable_fields
Expand All @@ -27,18 +26,11 @@ def unstorable_fields
end

def load_form(model)
load_form_attributes(model.attributes.merge(completed_attrs(model, :professional_status)))
super.merge(completed_attrs(model, :professional_status))
.merge(has_teacher_reference_number: model[:teacher_reference_number].present? ? "yes" : "no")
end
end

def statutory_induction_complete_options
[
["yes", I18n.t("helpers.label.jobseekers_job_application_professional_status_form.statutory_induction_complete_options.yes")],
["no", I18n.t("helpers.label.jobseekers_job_application_professional_status_form.statutory_induction_complete_options.no")],

]
end

def initialize(attributes = {})
jobseeker_profile = attributes.delete(:jobseeker_profile)
super
Expand All @@ -65,9 +57,5 @@ def initialize(attributes = {})

completed_attribute(:professional_status)
end

def load(attrs)
super(attrs.merge(has_teacher_reference_number: attrs[:teacher_reference_number].present? ? "yes" : "no"))
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def unstorable_fields
end

def load_form(model)
load_form_attributes(model.attributes.merge(completed_attrs(model, :qualifications)))
super.merge(completed_attrs(model, :qualifications))
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def optional?
end

def load_form(model)
load_form_attributes(model.attributes.merge(references: model.references).merge(completed_attrs(model, :references)))
super.merge(references: model.references)
.merge(completed_attrs(model, :references))
end
end

Expand Down
Loading

0 comments on commit 708689f

Please sign in to comment.