Skip to content

Commit

Permalink
rebase with task list
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Jan 20, 2025
1 parent 5a5a5d5 commit 8177c75
Show file tree
Hide file tree
Showing 22 changed files with 157 additions and 123 deletions.
4 changes: 1 addition & 3 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
--require spec_helper --tag ~smoke_test
--format progress
--format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log

--format progress
3 changes: 3 additions & 0 deletions .rspec_parallel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require spec_helper --tag ~smoke_test
--format progress
--format ParallelTests::RSpec::RuntimeLogger --out tmp/parallel_runtime_rspec.log
12 changes: 3 additions & 9 deletions app/controllers/jobseekers/job_applications/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ class Jobseekers::JobApplications::BaseController < Jobseekers::BaseController
helper_method :job_application

def step_process
if vacancy.religion_type.present?
Jobseekers::JobApplications::ReligiousJobApplicationStepProcess.new(
job_application: job_application,
)
else
Jobseekers::JobApplications::JobApplicationStepProcess.new(
job_application: job_application,
)
end
Jobseekers::JobApplications::JobApplicationStepProcess.new(
job_application: job_application,
)
end

def job_application
Expand Down
25 changes: 14 additions & 11 deletions app/controllers/jobseekers/job_applications/build_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ def show

def update
if form.valid?
job_application.update(update_params.except(:teacher_reference_number, :has_teacher_reference_number))
job_application.update!(update_params.except(:teacher_reference_number, :has_teacher_reference_number))
update_or_create_jobseeker_profile! if step == :professional_status

if redirect_to_review? && (step_process.last_of_group? || (step.in?(%i[catholic_following_religion non_catholic_following_religion]) && !job_application.following_religion))
if redirect_to_review?
redirect_to jobseekers_job_application_review_path(job_application), success: t("messages.jobseekers.job_applications.saved")
else
elsif steps_complete?
redirect_to jobseekers_job_application_apply_path job_application
else
redirect_to jobseekers_job_application_build_path(job_application, step_process.next_step(step))
end
else
render step
Expand All @@ -24,6 +26,10 @@ def update

private

def steps_complete?
step_process.last_of_group?(step) || (step.in?(%i[catholic_following_religion non_catholic_following_religion]) && !job_application.following_religion)
end

def back_path
@back_path ||= if redirect_to_review?
jobseekers_job_application_review_path(job_application)
Expand Down Expand Up @@ -52,13 +58,14 @@ def form_attributes
form_params
end

attributes[:unexplained_employment_gaps] = job_application.unexplained_employment_gaps if step == :employment_history

if step == :professional_status
case step
when :professional_status
attributes.merge(jobseeker_profile_attributes)
.merge(trn_params)
elsif step == :references
when :references
attributes.merge(references: job_application.references)
when :employment_history
attributes.merge(unexplained_employment_gaps: job_application.unexplained_employment_gaps)
else
attributes
end
Expand Down Expand Up @@ -142,8 +149,4 @@ def update_or_create_jobseeker_profile!
)
end
end

def set_steps
self.steps = step_process.all_possible_steps - [:review]
end
end
9 changes: 8 additions & 1 deletion app/controllers/jobseekers/job_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def step_valid?(step)
attributes = form_class.load_form(job_application)
attributes.merge!(trn_params) if step == :professional_status

form = form_class.new(form_class.load(attributes))
form = form_class.new(attributes)

form.valid?.tap do
job_application.errors.merge!(form.errors)
Expand Down Expand Up @@ -249,5 +249,12 @@ def previous_application?
def quick_apply?
previous_application? || profile.present?
end

def trn_params
{
teacher_reference_number: current_jobseeker&.jobseeker_profile&.teacher_reference_number,
has_teacher_reference_number: current_jobseeker&.jobseeker_profile&.has_teacher_reference_number,
}
end
end
# rubocop:enable Metrics/ClassLength
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
class Jobseekers::JobApplication::CatholicReligionDetailsForm < Jobseekers::JobApplication::BaseForm
include ActiveRecord::AttributeAssignment
include DateAttributeAssignment

def self.fields
%i[faith
place_of_worship
religious_reference_type
religious_referee_name
religious_referee_address
religious_referee_role
religious_referee_email
religious_referee_phone
baptism_certificate
baptism_address
baptism_date]
include ActiveModel::Attributes

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

STORABLE_FIELDS = (FIELDS + [:baptism_date]).freeze

class << self
def storable_fields
STORABLE_FIELDS
end

def load_form(model)
load_form_attributes(model.attributes.merge(baptism_certificate: model.baptism_certificate))
end
end
attr_accessor(*fields)

attr_accessor(*FIELDS)

attribute :baptism_date, :date

validates :faith, presence: true
validates :religious_reference_type, inclusion: { in: JobApplication::RELIGIOUS_REFERENCE_TYPES.keys.map(&:to_s), nil: false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ class Jobseekers::JobApplication::FollowingReligionForm < Jobseekers::JobApplica
include ActiveModel::Model
include ActiveModel::Attributes

def self.fields
%i[following_religion]
class << self
def storable_fields
%i[following_religion]
end
end

attribute :following_religion, :boolean

validates :following_religion, inclusion: { in: [true, false], allow_nil: false }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
class Jobseekers::JobApplication::NonCatholicReligionDetailsForm < Jobseekers::JobApplication::BaseForm
def self.fields
%i[faith
place_of_worship
religious_reference_type
religious_referee_name
religious_referee_address
religious_referee_role
religious_referee_email
religious_referee_phone]
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

class << self
def storable_fields
FIELDS
end
end
attr_accessor(*fields)

attr_accessor(*FIELDS)

validates :faith, presence: true
validates :religious_reference_type, inclusion: { in: %w[referee no_referee], nil: false }
Expand Down
10 changes: 7 additions & 3 deletions app/form_models/jobseekers/job_application/school_ethos_form.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# frozen_string_literal: true

class Jobseekers::JobApplication::SchoolEthosForm < Jobseekers::JobApplication::BaseForm
def self.fields
%i[ethos_and_aims]
FIELDS = %i[ethos_and_aims].freeze

class << self
def storable_fields
FIELDS
end
end
attr_accessor(*fields)
attr_accessor(*FIELDS)

validates_presence_of :ethos_and_aims
end
1 change: 1 addition & 0 deletions app/helpers/status_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module StatusTagHelper
in_progress: "yellow",
imported: "blue",
}.freeze

# rubocop:disable Lint/DuplicateBranch
def review_section_tag(resource, form_classes)
steps = form_classes.map(&:target_name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Jobseekers::JobApplications::JobApplicationStepProcess < StepProcess
class Jobseekers::JobApplications::JobApplicationStepProcess
attr_reader :job_application

PRE_RELIGION_STEPS = { personal_details: %i[personal_details],
Expand All @@ -20,7 +20,7 @@ class Jobseekers::JobApplications::JobApplicationStepProcess < StepProcess

ALL_NON_CATHOLIC_STEPS = %i[school_ethos non_catholic_following_religion non_catholic_religion_details].freeze

def initialize(current_step, job_application:)
def initialize(job_application:)
@job_application = job_application

religious_steps = case job_application.vacancy.religion_type
Expand All @@ -32,13 +32,25 @@ def initialize(current_step, job_application:)
[]
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 = 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
end

# Returns the keys of all individual steps in order
def steps
@step_groups.values.flatten
end

def next_step(step)
steps[steps.index(step) + 1]
end

super(current_step, step_groups)
def last_of_group?(step)
group = @step_groups.values.detect { |g| g.include?(step) }
step == group.last
end

def all_possible_steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@ def relevant_steps
# The step process is needed in order to filter out the steps that are not relevant to the new job application,
# for eg. professional status - see https://github.com/DFE-Digital/teaching-vacancies/blob/75cec792d9e229fb866bdafc017f82501bd01001/app/services/jobseekers/job_applications/job_application_step_process.rb#L23
# The review step is used as a current step is required.
step_process = if vacancy.religion_type.present?
Jobseekers::JobApplications::ReligiousJobApplicationStepProcess.new(job_application: new_job_application)
else
Jobseekers::JobApplications::JobApplicationStepProcess.new(job_application: new_job_application)
end
step_process.steps
Jobseekers::JobApplications::JobApplicationStepProcess.new(job_application: new_job_application).steps
end

def completed_steps
Expand Down
10 changes: 10 additions & 0 deletions app/views/jobseekers/job_applications/apply.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
html_attributes: { id: :personal_statement },
status: review_section_tag(job_application, [Jobseekers::JobApplication::PersonalStatementForm]))

- case job_application.vacancy.religion_type
- when "catholic"
- task_list.with_item(title: t("jobseekers.job_applications.build.religious_information.step_title"), href: jobseekers_job_application_build_path(job_application, :catholic_following_religion),
html_attributes: { id: :religious_information },
status: review_section_tag(job_application, [Jobseekers::JobApplication::FollowingReligionForm]))
- when "other_religion"
- task_list.with_item(title: t("jobseekers.job_applications.build.religious_information.step_title"), href: jobseekers_job_application_build_path(job_application, :school_ethos),
html_attributes: { id: :religious_information },
status: review_section_tag(job_application, [Jobseekers::JobApplication::FollowingReligionForm]))

- task_list.with_item(title: t("jobseekers.job_applications.build.references.heading"), href: jobseekers_job_application_build_path(job_application, :references),
html_attributes: { id: :references },
status: review_section_tag(job_application, [Jobseekers::JobApplication::ReferencesForm]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
= render "banner", vacancy: vacancy, back_path: back_path

.govuk-grid-row
.govuk-grid-column-two-thirds
- if current_jobseeker.job_applications.not_draft.none?
= render "caption"
div
h2.govuk-heading-l = t(".heading")

p.govuk-body = t(".is_a_catholic_school", name: vacancy.organisation.name)
Expand All @@ -16,7 +14,7 @@

p.govuk-body = t(".non_catholics_apply")

= form_for form, url: wizard_path, method: :patch do |f|
= form_for form, url: jobseekers_job_application_build_path(job_application, :catholic_following_religion), method: :patch do |f|
= f.govuk_error_summary

= f.govuk_radio_buttons_fieldset :following_religion do
Expand All @@ -25,7 +23,3 @@

= f.govuk_submit job_application_build_submit_button_text do
= govuk_link_to t("buttons.cancel_and_return_to_account"), jobseekers_job_applications_path, class: "govuk-link--no-visited-state"

- if current_jobseeker.job_applications.not_draft.none?
.govuk-grid-column-one-third
= render "steps"
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
= render "banner", vacancy: vacancy, back_path: back_path

.govuk-grid-row
.govuk-grid-column-two-thirds
- if current_jobseeker.job_applications.not_draft.none?
= render "caption"
div
h2.govuk-heading-l = t(".heading")

= form_for form, url: wizard_path, method: :patch do |f|
= form_for form, url: jobseekers_job_application_build_path(job_application, :catholic_religion_details), method: :patch do |f|
= f.govuk_error_summary

= f.govuk_text_field :faith, label: { size: "s" }
Expand All @@ -34,7 +32,3 @@

= f.govuk_submit job_application_build_submit_button_text do
= govuk_link_to t("buttons.cancel_and_return_to_account"), jobseekers_job_applications_path, class: "govuk-link--no-visited-state"

- if current_jobseeker.job_applications.not_draft.none?
.govuk-grid-column-one-third
= render "steps"
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
= render "banner", vacancy: vacancy, back_path: back_path

.govuk-grid-row
.govuk-grid-column-two-thirds
- if current_jobseeker.job_applications.not_draft.none?
= render "caption"
div
h2.govuk-heading-l = t(".heading")

= form_for form, url: wizard_path, method: :patch do |f|
= form_for form, url: jobseekers_job_application_build_path(job_application, :non_catholic_following_religion), method: :patch do |f|
= f.govuk_error_summary

= f.govuk_radio_buttons_fieldset :following_religion do
Expand All @@ -17,7 +15,3 @@

= f.govuk_submit job_application_build_submit_button_text do
= govuk_link_to t("buttons.cancel_and_return_to_account"), jobseekers_job_applications_path, class: "govuk-link--no-visited-state"

- if current_jobseeker.job_applications.not_draft.none?
.govuk-grid-column-one-third
= render "steps"
Loading

0 comments on commit 8177c75

Please sign in to comment.