Skip to content

Commit

Permalink
use model.slice(*storable_fields) to avoid special case code for atta…
Browse files Browse the repository at this point in the history
…chments
  • Loading branch information
starswan committed Jan 22, 2025
1 parent 7724566 commit a8ac539
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ 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)
# when :references
# attributes.merge(references: job_application.references)
when :employment_history
attributes.merge(unexplained_employment_gaps: job_application.unexplained_employment_gaps)
else
Expand Down Expand Up @@ -128,8 +128,6 @@ def jobseeker_profile_attributes
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
5 changes: 1 addition & 4 deletions app/form_models/jobseekers/job_application/catholic_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ def unstorable_fields
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))
model.slice(*storable_fields).merge(completed_attrs(model, :catholic))
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, :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
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, :non_catholic)))
super.merge(completed_attrs(model, :non_catholic))
end
end

Expand Down
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,11 @@ 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(:has_teacher_reference_number)

class << self
def storable_fields
Expand All @@ -27,7 +27,8 @@ 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

Expand Down Expand Up @@ -65,9 +66,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
5 changes: 2 additions & 3 deletions app/form_models/jobseekers/job_application/references_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +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
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, :training_and_cpds)))
super.merge(completed_attrs(model, :training_and_cpds))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/jobseekers/job_applications/apply.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- content_for :page_title_prefix, job_application_page_title_prefix(review_form, t(".title"))

= job_application_review(@job_application) do |r|
= job_application_review(@job_applicationm, show_sidebar: false) do |r|
- r.with_header do
= render "banner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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

= form_for form, url: jobseekers_job_application_build_path(job_application, :catholic), method: :patch do |f|
= form_for form, url: jobseekers_job_application_build_path(job_application, :catholic), method: :patch, multipart: true do |f|
= f.govuk_error_summary

= f.govuk_radio_buttons_fieldset :following_religion do
Expand All @@ -33,8 +33,7 @@
= f.govuk_radio_button :religious_reference_type, :baptism_certificate do
= f.govuk_file_field :baptism_certificate,
label: { size: "s" },
accept: BaseForm::VALID_DOCUMENT_TYPES.map(&:downcase).join(","),
enctype: "multipart/form-data"
accept: BaseForm::VALID_DOCUMENT_TYPES.map(&:downcase).join(",")
= f.govuk_radio_button :religious_reference_type, :baptism_date do
= f.govuk_text_area :baptism_address, rows: 6
= f.govuk_date_field :baptism_date
Expand Down

0 comments on commit a8ac539

Please sign in to comment.