Skip to content

Commit

Permalink
Merge branch 'main' into ats-api-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ddippolito committed Jan 14, 2025
2 parents 656dfcc + 73321ff commit 87217a6
Show file tree
Hide file tree
Showing 53 changed files with 451 additions and 278 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ GEM
bindex (0.8.1)
binding_of_caller (1.0.1)
debug_inspector (>= 1.2.0)
brakeman (6.2.2)
brakeman (7.0.0)
racc
breasal (0.0.1)
builder (3.3.0)
Expand All @@ -165,7 +165,7 @@ GEM
climate_control (1.2.0)
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
connection_pool (2.5.0)
crack (1.0.0)
bigdecimal
rexml
Expand All @@ -176,7 +176,7 @@ GEM
cssbundling-rails (1.4.1)
railties (>= 6.0.0)
csv (3.3.2)
database_consistency (1.7.26)
database_consistency (2.0.3)
activerecord (>= 3.2)
date (3.4.1)
debug (1.10.0)
Expand Down Expand Up @@ -332,7 +332,7 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
lockbox (2.0.1)
logger (1.6.4)
logger (1.6.5)
loofah (2.24.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down
24 changes: 9 additions & 15 deletions app/controllers/concerns/jobseekers/qualification_form_concerns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@ def qualification_form_param_key(category)
end

def category_form_class(category)
name = if %w[select_category submit_category].include?(action_name)
"CategoryForm"
elsif %w[confirm_destroy].include?(action_name)
"DeleteForm"
else
case category
when "gcse", "a_level", "as_level"
"Secondary::CommonForm"
when "other_secondary"
"Secondary::OtherForm"
when "undergraduate", "postgraduate"
"DegreeForm"
when "other"
"OtherForm"
end
name = case category
when "gcse", "a_level", "as_level"
"Secondary::CommonForm"
when "other_secondary"
"Secondary::OtherForm"
when "undergraduate", "postgraduate"
"DegreeForm"
when "other"
"OtherForm"
end
"Jobseekers::Qualifications::#{name}".constantize
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,78 @@
class Jobseekers::JobApplications::QualificationsController < Jobseekers::BaseController
include Jobseekers::QualificationFormConcerns

helper_method :back_path, :category, :form, :job_application, :qualification, :secondary?, :qualification_form_param_key
helper_method :back_path, :job_application, :qualification_form_param_key

before_action :set_qualification, only: %i[edit update destroy]

def select_category
@form = Jobseekers::Qualifications::CategoryForm.new
end

def submit_category
if form.valid?
redirect_to new_jobseekers_job_application_qualification_path(qualification_params)
@category = category_param
@form = Jobseekers::Qualifications::CategoryForm.new(submit_category_params)

if @form.valid?
redirect_to new_jobseekers_job_application_qualification_path(submit_category_params)
else
render :select_category
render :select_category, status: :unprocessable_entity
end
end

def new
@category = category_param
@form = category_form_class(@category).new(category: @category)
end

def edit
@category = @qualification.category
edit_attributes = @qualification
.slice(:category, :finished_studying, :finished_studying_details, :grade, :institution, :name, :subject, :year, :qualification_results)
.reject { |_, v| v.blank? && v != false }

@form = category_form_class(@category).new(edit_attributes)
end

def create
if form.valid?
@category = category_param
@form = category_form_class(@category).new(qualification_params)

if @form.valid?
job_application.qualifications.create(qualification_params)
redirect_to back_path
else
render :new
render :new, status: :unprocessable_entity
end
end

def update
if form.valid?
qualification.update(qualification_params)
@category = @qualification.category
@form = category_form_class(@category).new(qualification_params)

if @form.valid?
@qualification.update(qualification_params)
redirect_to back_path
else
render :edit
render :edit, status: :unprocessable_entity
end
end

def destroy
qualification.destroy
@qualification.destroy
redirect_to back_path, success: t(".success")
end

private

def form
@form ||= category_form_class(category).new(form_attributes)
end

def form_attributes
case action_name
when "new"
{ category: category }
when "select_category"
{}
when "edit"
qualification
.slice(:category, :finished_studying, :finished_studying_details, :grade, :institution, :name, :subject, :year, :qualification_results)
.reject { |_, v| v.blank? && v != false }
when "create", "update", "submit_category"
qualification_params
end
def submit_category_params
key = ActiveModel::Naming.param_key(Jobseekers::Qualifications::CategoryForm)
(params[key] || params).permit(:category)
end

def qualification_params
case action_name
when "new", "select_category", "submit_category"
(params[qualification_form_param_key(category)] || params).permit(:category)
when "create", "edit", "update"
params.require(qualification_form_param_key(category))
.permit(:category, :finished_studying, :finished_studying_details, :grade, :institution, :name, :subject, :year, qualification_results_attributes: %i[id subject grade])
end
end

def category
@category ||= action_name.in?(%w[edit update]) ? qualification.category : category_param
params.require(qualification_form_param_key(@category))
.permit(:category, :finished_studying, :finished_studying_details, :grade, :institution, :name, :subject, :year, qualification_results_attributes: %i[id subject grade awarding_body])
end

def category_param
Expand All @@ -81,11 +87,7 @@ def job_application
@job_application ||= current_jobseeker.job_applications.draft.find(params[:job_application_id])
end

def qualification
@qualification ||= job_application.qualifications.find(params[:id])
end

def secondary?
category.in?(Qualification::SECONDARY_QUALIFICATIONS)
def set_qualification
@qualification = job_application.qualifications.find(params[:id])
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ def form_attributes
when "create", "update"
training_and_cpd_form_params
when "edit"
training_and_cpd.slice(:name, :provider, :grade, :year_awarded)
training_and_cpd.slice(:name, :provider, :grade, :year_awarded, :course_length)
end
end

def training_and_cpd_form_params
params.require(:jobseekers_training_and_cpd_form)
.permit(:name, :provider, :grade, :year_awarded)
.permit(:name, :provider, :grade, :year_awarded, :course_length)
end

def training_and_cpd
Expand Down
62 changes: 35 additions & 27 deletions app/controllers/jobseekers/profiles/qualifications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
class Jobseekers::Profiles::QualificationsController < Jobseekers::ProfilesController
include Jobseekers::QualificationFormConcerns

helper_method :category, :form, :jobseeker_profile, :qualification, :secondary?, :qualification_form_param_key
helper_method :jobseeker_profile, :qualification, :qualification_form_param_key

before_action :set_form_and_category, only: %i[new create edit update]

def select_category
@form = Jobseekers::Qualifications::CategoryForm.new
end

def submit_category
if form.valid?
redirect_to new_jobseekers_profile_qualification_path(qualification_params)
@category = category_param
@form = Jobseekers::Qualifications::CategoryForm.new(submit_category_params)

if @form.valid?
redirect_to new_jobseekers_profile_qualification_path(submit_category_params)
else
render :select_category
render :select_category, status: :unprocessable_entity
end
end

def new; end

def create
if form.valid?
if @form.valid?
profile.qualifications.create(qualification_params)
redirect_to review_jobseekers_profile_qualifications_path
else
render :new
render :new, status: :unprocessable_entity
end
end

Expand All @@ -27,11 +36,11 @@ def edit; end
def review; end

def update
if form.valid?
if @form.valid?
qualification.update(qualification_params)
redirect_to review_jobseekers_profile_qualifications_path
else
render :edit
render :edit, status: :unprocessable_entity
end
end

Expand All @@ -40,41 +49,44 @@ def destroy
redirect_to review_jobseekers_profile_qualifications_path, success: t(".success")
end

def confirm_destroy; end
def confirm_destroy
@category = qualification.category
@form = Jobseekers::Qualifications::DeleteForm.new
end

private

def form
@form ||= category_form_class(category).new(form_attributes)
end

def form_attributes
case action_name
when "new"
{ category: category }
when "select_category", "confirm_destroy"
{}
{ category: @category }
when "edit"
qualification
.slice(:category, :finished_studying, :finished_studying_details, :grade, :institution, :name, :subject, :year, :qualification_results)
.reject { |_, v| v.blank? && v != false }
when "create", "update", "submit_category"
when "create", "update"
qualification_params
end
end

def submit_category_params
key = ActiveModel::Naming.param_key(Jobseekers::Qualifications::CategoryForm)
(params[key] || params).permit(:category)
end

def qualification_params
case action_name
when "new", "select_category", "submit_category", "confirm_destroy"
(params[qualification_form_param_key(category)] || params).permit(:category)
when "new", "confirm_destroy"
(params[qualification_form_param_key(@category)] || params).permit(:category)
when "create", "edit", "update"
params.require(qualification_form_param_key(category))
.permit(:category, :finished_studying, :finished_studying_details, :grade, :institution, :name, :subject, :year, qualification_results_attributes: %i[id subject grade])
params.require(qualification_form_param_key(@category))
.permit(:category, :finished_studying, :finished_studying_details, :grade, :institution, :name, :subject, :year, qualification_results_attributes: %i[id subject grade awarding_body])
end
end

def category
@category ||= action_name.in?(%w[edit update confirm_destroy]) ? qualification.category : category_param
def set_form_and_category
@category = action_name.in?(%w[edit update]) ? qualification.category : category_param
@form = category_form_class(@category).new(form_attributes)
end

def category_param
Expand All @@ -84,8 +96,4 @@ def category_param
def qualification
@qualification ||= profile.qualifications.find(params[:id] || params[:qualification_id])
end

def secondary?
category.in?(Qualification::SECONDARY_QUALIFICATIONS)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ def form_attributes
when "create", "update"
training_and_cpd_form_params
when "edit"
training_and_cpd.slice(:name, :provider, :grade, :year_awarded)
training_and_cpd.slice(:name, :provider, :grade, :year_awarded, :course_length)
end
end

def training_and_cpd_form_params
params.require(:jobseekers_training_and_cpd_form)
.permit(:name, :provider, :grade, :year_awarded)
.permit(:name, :provider, :grade, :year_awarded, :course_length)
end

def training_and_cpd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ class Jobseekers::Qualifications::QualificationForm
validates :finished_studying_details, presence: true, if: -> { finished_studying == "false" }
validates :year, numericality: { less_than_or_equal_to: proc { Time.current.year } },
if: -> { finished_studying == "true" }

def secondary?
false
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def initialize(attributes = nil)
pad_qualification_results
end

def secondary?
true
end

def qualification_results_attributes=(attrs)
@qualification_results = attrs.map { |_, params| QualificationResultForm.new(params) }
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Jobseekers::Qualifications::Secondary::QualificationResultForm
include ActiveModel::Model

attr_accessor :id, :subject, :grade
attr_accessor :id, :subject, :grade, :awarding_body

validates :subject, presence: true
validates :grade, presence: true
Expand Down
4 changes: 2 additions & 2 deletions app/form_models/jobseekers/training_and_cpd_form.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Jobseekers::TrainingAndCpdForm
include ActiveModel::Model

attr_accessor :name, :provider, :grade, :year_awarded
attr_accessor :name, :provider, :grade, :year_awarded, :course_length

validates :name, :provider, :year_awarded, presence: true
validates :name, :provider, :year_awarded, :course_length, presence: true
end
Loading

0 comments on commit 87217a6

Please sign in to comment.