Skip to content

Commit

Permalink
Convert religious forms to single step with 'complete later' field to…
Browse files Browse the repository at this point in the history
… match other task list steps
  • Loading branch information
starswan committed Jan 21, 2025
1 parent 8177c75 commit f5981cb
Show file tree
Hide file tree
Showing 28 changed files with 365 additions and 382 deletions.
2 changes: 1 addition & 1 deletion app/components/job_application_review_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class JobApplicationReviewComponent < ApplicationComponent
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[ReligiousInformationForm], 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

This file was deleted.

37 changes: 37 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,37 @@
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)
# baptism_certificate is an upload so is not an attribute
load_form_attributes(model.attributes.merge(completed_attrs(model, :catholic)).merge(baptism_certificate: model.baptism_certificate))
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.

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)
load_form_attributes(model.attributes.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 @@ -15,7 +15,9 @@ def optional?
end

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Jobseekers
module JobApplication
class ReligiousInformationForm < BaseForm
include ActiveRecord::AttributeAssignment
include ActiveModel::Attributes
include CompletedFormAttribute

FIELDS = %i[faith
place_of_worship
religious_reference_type
religious_referee_name
religious_referee_address
religious_referee_role
religious_referee_email
religious_referee_phone].freeze

STORABLE_FIELDS = (FIELDS + %i[following_religion]).freeze

class << self
def storable_fields
STORABLE_FIELDS
end
end

attr_accessor(*FIELDS)

attribute :following_religion, :boolean

validates :following_religion, inclusion: { in: [true, false], allow_nil: false }, if: -> { section_completed }

validates :faith, presence: true, if: -> { section_completed && following_religion }

validates :religious_referee_name, :religious_referee_address, :religious_referee_role, :religious_referee_email,
presence: true, if: -> { section_completed && following_religion && religious_reference_type == "referee" }
validates :religious_referee_email, email: true, if: -> { section_completed && following_religion && religious_reference_type == "referee" }

validates :baptism_address, :baptism_date,
presence: true, if: -> { section_completed && following_religion && religious_reference_type == "baptism_date" }

validates :baptism_certificate, form_file: DOCUMENT_VALIDATION_OPTIONS, presence: true, if: -> { section_completed && following_religion && religious_reference_type == "baptism_certificate" }
end
end
end
14 changes: 0 additions & 14 deletions app/form_models/jobseekers/job_application/school_ethos_form.rb

This file was deleted.

16 changes: 6 additions & 10 deletions app/models/job_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ class JobApplication < ApplicationRecord
training_and_cpds: 9,
employment_history: 3,
personal_statement: 4,
catholic_following_religion: 10,
catholic_religion_details: 11,
school_ethos: 12,
non_catholic_following_religion: 13,
non_catholic_religion_details: 14,
catholic: 10,
non_catholic: 11,
references: 5,
equal_opportunities: 6,
ask_for_support: 7,
Expand All @@ -30,11 +27,8 @@ class JobApplication < ApplicationRecord
training_and_cpds: 9,
employment_history: 3,
personal_statement: 4,
catholic_following_religion: 10,
catholic_religion_details: 11,
school_ethos: 12,
non_catholic_following_religion: 13,
non_catholic_religion_details: 14,
catholic: 10,
non_catholic: 11,
references: 5,
equal_opportunities: 6,
ask_for_support: 7,
Expand All @@ -52,6 +46,8 @@ class JobApplication < ApplicationRecord
personal_statement: 7,
declarations: 8,
ask_for_support: 9,
catholic: 10,
non_catholic: 11,
}

# If you want to add a status, be sure to add a `status_at` column to the `job_applications` table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,23 @@ class Jobseekers::JobApplications::JobApplicationStepProcess
review: %i[review],
}.freeze

ALL_CATHOLIC_STEPS = %i[catholic_following_religion catholic_religion_details].freeze
# ALL_CATHOLIC_STEPS = %i[catholic_following_religion catholic_religion_details].freeze

ALL_NON_CATHOLIC_STEPS = %i[school_ethos non_catholic_following_religion non_catholic_religion_details].freeze
# ALL_NON_CATHOLIC_STEPS = %i[school_ethos non_catholic_following_religion non_catholic_religion_details].freeze

def initialize(job_application:)
@job_application = job_application

religious_steps = case job_application.vacancy.religion_type
when "catholic"
catholic_steps job_application
{ catholic: [:catholic] }
when "other_religion"
other_religion_steps job_application
{ non_catholic: [:non_catholic] }
else
[]
{}
end

@step_groups = if religious_steps.any?
PRE_RELIGION_STEPS.merge(religious_information: religious_steps).merge(POST_RELIGION_STEPS)
else
PRE_RELIGION_STEPS.merge(POST_RELIGION_STEPS)
end
@step_groups = PRE_RELIGION_STEPS.merge(religious_steps).merge(POST_RELIGION_STEPS)
end

# Returns the keys of all individual steps in order
Expand All @@ -56,30 +52,30 @@ def last_of_group?(step)
def all_possible_steps
steps = case job_application.vacancy.religion_type
when "catholic"
PRE_RELIGION_STEPS.merge(religious_information: ALL_CATHOLIC_STEPS).merge(POST_RELIGION_STEPS)
PRE_RELIGION_STEPS.merge(religious_information: [:religious_information]).merge(POST_RELIGION_STEPS)
when "other_religion"
PRE_RELIGION_STEPS.merge(religious_information: ALL_NON_CATHOLIC_STEPS).merge(POST_RELIGION_STEPS)
PRE_RELIGION_STEPS.merge(non_catholic: [:non_catholic]).merge(POST_RELIGION_STEPS)
else
PRE_RELIGION_STEPS.merge(POST_RELIGION_STEPS)
end
steps.values.flatten
end

private
# private

def catholic_steps(job_application)
if job_application.following_religion || job_application.following_religion.nil?
ALL_CATHOLIC_STEPS
else
ALL_CATHOLIC_STEPS - [:catholic_religion_details]
end
end
# def catholic_steps(job_application)
# if job_application.following_religion || job_application.following_religion.nil?
# ALL_CATHOLIC_STEPS
# else
# ALL_CATHOLIC_STEPS - [:catholic_religion_details]
# end
# end

def other_religion_steps(job_application)
if job_application.following_religion || job_application.following_religion.nil?
ALL_NON_CATHOLIC_STEPS
else
ALL_NON_CATHOLIC_STEPS - [:non_catholic_religion_details]
end
end
# def other_religion_steps(job_application)
# if job_application.following_religion || job_application.following_religion.nil?
# ALL_NON_CATHOLIC_STEPS
# else
# ALL_NON_CATHOLIC_STEPS - [:non_catholic_religion_details]
# end
# end
end
Loading

0 comments on commit f5981cb

Please sign in to comment.