Skip to content

Commit

Permalink
copy religious information from previous job application
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Nov 5, 2024
1 parent 66a715f commit 9093a97
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: bundle exec rubocop

- name: Run Slim-Lint with PR annotations
run: bundle exec slim-lint -r github app/views app/components
run: bundle exec slim-lint app/views app/components

- name: Run Brakeman
run: bundle exec brakeman
Expand Down
63 changes: 6 additions & 57 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 350`
# on 2024-10-31 16:37:50 UTC using RuboCop version 1.64.1.
# on 2024-11-04 13:50:21 UTC using RuboCop version 1.64.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -36,7 +36,7 @@ Capybara/ClickLinkOrButtonStyle:
- 'spec/system/support_users/feedback_spec.rb'
- 'spec/system/support_users/service_data_spec.rb'

# Offense count: 326
# Offense count: 333
# This cop supports safe autocorrection (--autocorrect).
Capybara/CurrentPathExpectation:
Exclude:
Expand Down Expand Up @@ -317,61 +317,10 @@ Lint/MissingSuper:
Metrics/BlockLength:
Max: 28

# Offense count: 19
# Offense count: 20
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 188

# Offense count: 91
RSpec/AnyInstance:
Exclude:
- 'spec/controllers/jobseekers/subscriptions_controller_spec.rb'
- 'spec/form_models/publishers/job_listing/documents_form_spec.rb'
- 'spec/form_models/publishers/organisation/logo_form_spec.rb'
- 'spec/form_models/publishers/organisation/photo_form_spec.rb'
- 'spec/jobs/alert_mailer_job_spec.rb'
- 'spec/jobs/send_daily_alert_email_job_spec.rb'
- 'spec/jobs/send_weekly_alert_email_job_spec.rb'
- 'spec/lib/modules/aws_ip_ranges_spec.rb'
- 'spec/mailers/jobseekers/alert_mailer_spec.rb'
- 'spec/mailers/jobseekers/subscription_mailer_spec.rb'
- 'spec/rails_helper.rb'
- 'spec/requests/cors_spec.rb'
- 'spec/requests/jobseekers/job_applications/build_spec.rb'
- 'spec/requests/jobseekers/job_applications/employments_spec.rb'
- 'spec/requests/jobseekers/job_applications/qualifications_spec.rb'
- 'spec/requests/jobseekers/job_applications/references_spec.rb'
- 'spec/requests/jobseekers/profiles/employments_spec.rb'
- 'spec/requests/jobseekers/unsubscribe_feedbacks_spec.rb'
- 'spec/requests/publishers/notifications_spec.rb'
- 'spec/requests/publishers/organisations/logo_spec.rb'
- 'spec/requests/publishers/sessions_spec.rb'
- 'spec/requests/publishers/vacancies/application_forms_spec.rb'
- 'spec/requests/publishers/vacancies/build_spec.rb'
- 'spec/requests/publishers/vacancies/documents_spec.rb'
- 'spec/requests/publishers/vacancies/end_listing_spec.rb'
- 'spec/requests/publishers/vacancies/extend_deadline_spec.rb'
- 'spec/requests/publishers/vacancies/job_applications_spec.rb'
- 'spec/requests/publishers/vacancies/statistics_spec.rb'
- 'spec/requests/recaptcha_spec.rb'
- 'spec/services/image_manipulator_spec.rb'
- 'spec/services/jobseekers/account_transfer_spec.rb'
- 'spec/system/jobseekers/jobseekers_can_create_a_job_alert_from_a_mailing_campaign_spec.rb'
- 'spec/system/jobseekers/jobseekers_can_create_a_job_alert_from_a_search_spec.rb'
- 'spec/system/jobseekers/jobseekers_can_create_a_job_alert_from_the_dashboard_spec.rb'
- 'spec/system/jobseekers/jobseekers_can_give_job_alert_feedback_spec.rb'
- 'spec/system/jobseekers/jobseekers_can_search_for_jobs_spec.rb'
- 'spec/system/jobseekers/jobseekers_can_view_an_organisation_spec.rb'
- 'spec/system/other/general_feedback_spec.rb'
- 'spec/system/other/get_help_spec.rb'
- 'spec/system/publishers/publishers_can_delete_vacancies_spec.rb'
- 'spec/system/publishers/publishers_can_edit_a_published_vacancy_as_a_school_spec.rb'
- 'spec/system/publishers/publishers_can_manage_a_profile_spec.rb'
- 'spec/system/publishers/publishers_can_preview_a_profile_spec.rb'
- 'spec/system/publishers/publishers_can_publish_a_vacancy_as_a_school_spec.rb'
- 'spec/system/publishers/publishers_can_sign_in_by_email_spec.rb'
- 'spec/system/publishers/publishers_get_email_notifications_from_job_applications_spec.rb'
- 'spec/validators/form_file_validator_spec.rb'
Max: 190

# Offense count: 79
# This cop supports unsafe autocorrection (--autocorrect-all).
Expand Down Expand Up @@ -1417,7 +1366,7 @@ Rails/CompactBlank:
- 'app/services/search/criteria_inventor.rb'
- 'app/services/zendesk.rb'

# Offense count: 48
# Offense count: 50
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle, AllowToTime.
# SupportedStyles: strict, flexible
Expand Down Expand Up @@ -1825,7 +1774,7 @@ Style/DateTime:
- 'spec/system/publishers/publishers_are_reminded_of_application_functionality_spec.rb'
- 'spec/system/publishers/publishers_can_extend_a_deadline_spec.rb'

# Offense count: 298
# Offense count: 299
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
# SupportedStyles: percent, brackets
Expand Down
5 changes: 3 additions & 2 deletions app/components/job_application_review_component.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class JobApplicationReviewComponent < ReviewComponent
renders_many(:sections, lambda do |section_name, **kwargs|
if section_name == :religious_information
if section_name == :following_religion
ReligiousInformationSection.new(@job_application,
name: section_name,
allow_edit: @allow_edit)
else
JobApplicationReviewComponent::Section.new(
Section.new(
@job_application,
allow_edit: @allow_edit,
name: section_name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

class JobApplicationReviewComponent::ReligiousInformationSection < JobApplicationReviewComponent::Section
def initialize(job_application, allow_edit:)
# don't include the details for if we don't follow a religion
if job_application.following_religion
super(job_application, forms: %w[FollowingReligionForm ReligionDetailsForm], name: :following_religion, allow_edit: allow_edit)
else
super(job_application, forms: %w[FollowingReligionForm], name: :following_religion, allow_edit: allow_edit)
end
def initialize(job_application, allow_edit:, name:)
# only include the details form if we follow a religion
forms = if job_application.following_religion
%w[FollowingReligionForm ReligionDetailsForm]
else
%w[FollowingReligionForm]
end
super(job_application, forms: forms, name: name, allow_edit: allow_edit)
end
end
7 changes: 7 additions & 0 deletions app/form_models/base_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class BaseForm
valid_file_types: %i[JPG JPEG PNG].freeze,
}.freeze

DOCUMENT_VALIDATION_OPTIONS = {
file_type: :document,
content_types_allowed: %w[application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document].freeze,
file_size_limit: 10.megabytes,
valid_file_types: %i[PDF DOC DOCX],
}.freeze

include ActiveModel::Model
include ActiveModel::Validations::Callbacks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,5 @@ def self.fields
validates :baptism_address, :baptism_date,
presence: true, if: -> { religious_reference_type == "baptism_date" }

validates :baptism_certificate, form_file: true, presence: true, if: -> { religious_reference_type == "baptism_certificate" }

def file_type
:document
end

def valid_file_types
%i[PDF DOC DOCX]
end

def file_size_limit
10.megabytes
end

def content_types_allowed
%w[application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document].freeze
end
validates :baptism_certificate, form_file: DOCUMENT_VALIDATION_OPTIONS, presence: true, if: -> { religious_reference_type == "baptism_certificate" }
end
7 changes: 0 additions & 7 deletions app/form_models/publishers/job_listing/vacancy_form.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
class Publishers::JobListing::VacancyForm < BaseForm
attr_accessor :params, :vacancy, :completed_steps, :current_organisation

DOCUMENT_VALIDATION_OPTIONS = {
file_type: :document,
content_types_allowed: %w[application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document].freeze,
file_size_limit: 10.megabytes,
valid_file_types: %i[PDF DOC DOCX],
}.freeze

def initialize(params = {}, vacancy = nil, current_publisher = nil)
@params = params
@vacancy = vacancy
Expand Down
2 changes: 2 additions & 0 deletions app/models/job_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class JobApplication < ApplicationRecord
training_and_cpds: 9,
employment_history: 3,
personal_statement: 4,
following_religion: 10,
religion_details: 11,
references: 5,
equal_opportunities: 6,
ask_for_support: 7,
Expand Down
2 changes: 0 additions & 2 deletions app/models/vacancy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class Vacancy < ApplicationRecord

enum religion_type: { no_religion: 0, other_religion: 1, catholic: 2 }

enum religion_type: { no_religion: 0, other_religion: 1, catholic: 2 }

belongs_to :publisher, optional: true
belongs_to :publisher_organisation, class_name: "Organisation", optional: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,29 @@ def call
private

def copy_personal_info
new_job_application.assign_attributes(recent_job_application.slice(*attributes_to_copy))
attributes = attributes_to_copy
if attributes.include? :baptism_certificate
new_job_application.assign_attributes(recent_job_application.slice(*(attributes - [:baptism_certificate])))

if recent_job_application.baptism_certificate.present?
recent_job_application.baptism_certificate.blob.open do |tempfile|
new_job_application.baptism_certificate.attach({
io: tempfile,
filename: recent_job_application.baptism_certificate.blob.filename,
content_type: recent_job_application.baptism_certificate.blob.content_type,
})
end
end
else
new_job_application.assign_attributes(recent_job_application.slice(*attributes))
end
end

def attributes_to_copy
%i[personal_details professional_status ask_for_support personal_statement].select { |step| relevant_steps.include?(step) }
.map { |step| form_fields_from_step(step) }
.flatten - jobseeker_profile_fields
%i[personal_details professional_status ask_for_support personal_statement following_religion religion_details]
.select { |step| relevant_steps.include?(step) }
.map { |step| form_fields_from_step(step) }
.flatten - jobseeker_profile_fields
end

def jobseeker_profile_fields
Expand Down Expand Up @@ -87,11 +103,16 @@ 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.
Jobseekers::JobApplications::JobApplicationStepProcess.new(:review, job_application: new_job_application).steps
step_process = if vacancy.religion_type.present?
Jobseekers::JobApplications::ReligiousJobApplicationStepProcess.new(:review, job_application: new_job_application)
else
Jobseekers::JobApplications::JobApplicationStepProcess.new(:review, job_application: new_job_application)
end
step_process.steps
end

def completed_steps
completed_steps = %w[personal_details personal_statement references ask_for_support qualifications training_and_cpds].select { |step| relevant_steps.include?(step.to_sym) }
completed_steps = %w[personal_details personal_statement references ask_for_support qualifications training_and_cpds following_religion religion_details].select { |step| relevant_steps.include?(step.to_sym) }
completed_steps << "employment_history" unless previous_application_was_submitted_before_we_began_validating_gaps_in_work_history?
completed_steps << "professional_status" if previous_application_has_professional_status_details?
completed_steps
Expand Down
4 changes: 1 addition & 3 deletions app/services/step_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def initialize(current_step, step_groups = {})
@current_step = current_step.to_sym
@step_groups = step_groups.compact_blank

unless current_step.in?(steps)
raise MissingStepError, "Current step `#{current_step}` missing from steps (#{steps.join(', ')})"
end
raise MissingStepError, "Current step `#{current_step}` missing from steps (#{steps.join(', ')})" unless current_step.in?(steps)
end

# Returns the keys of all individual steps in order
Expand Down
2 changes: 1 addition & 1 deletion app/views/jobseekers/job_applications/_show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- navigation.with_anchor text: t(".qualifications.heading"), href: "#qualifications"
- navigation.with_anchor text: t(".employment_history.heading"), href: "#employment_history"
- navigation.with_anchor text: t(".personal_statement.heading"), href: "#personal_statement"
- if vacancy.religion_type
- if vacancy.religion_type.present?
- navigation.with_anchor text: t(".religious_information.heading"), href: "#following_religion"
- navigation.with_anchor text: t(".references.heading"), href: "#references"
- navigation.with_anchor text: t(".ask_for_support.heading"), href: "#ask_for_support"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
= f.govuk_radio_buttons_fieldset :following_religion do
= f.govuk_radio_button :following_religion, true, link_errors: true, label: { text: t("helpers.label.jobseekers_job_application_following_religion_form.following_religion_options.yes") }
= f.govuk_radio_button :following_religion, false, label: { text: t("helpers.label.jobseekers_job_application_following_religion_form.following_religion_options.no") }
/ = f.govuk_radio_button :following_religion, :yes, link_errors: true
/ = f.govuk_radio_button :following_religion, :no

= 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

= f.govuk_text_field :faith, label: { size: "s" }

= f.govuk_text_area :place_of_worship, label: { size: "s", text: t(".place_of_worship.text") }, rows: 6, hint: { text: t(".place_of_worship.hint") }
= f.govuk_text_area :place_of_worship, label: { size: "s" }, rows: 6

= f.govuk_radio_buttons_fieldset :religious_reference_type, hint: -> { t(".referee_type.hints_html") } do
= f.govuk_radio_button :religious_reference_type, :referee, link_errors: true do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- r.with_section :religious_information
- r.with_section :following_religion
p.govuk-body = t("jobseekers.job_applications.review.religious_information.heading")

= govuk_summary_list do |summary_list|
- if job_application.following_religion.in? [true,false]
- if job_application.following_religion.in? [true, false]
- summary_list.with_row do |row|
- row.with_key text: t("helpers.legend.jobseekers_job_application_following_religion_form.following_religion")
- row.with_value text: job_application.following_religion ? t("helpers.label.jobseekers_job_application_following_religion_form.following_religion_options.yes") : t("helpers.label.jobseekers_job_application_following_religion_form.following_religion_options.no")
Expand Down
3 changes: 0 additions & 3 deletions config/locales/jobseekers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ en:
religion_details:
heading: Religious information
title: Religious information — Application
place_of_worship:
text: Address of place of worship (optional)
hint: For example, Westminster Abbey, Dean's Yard, London.
referee_type:
text: Can you provide a religious referee?
hints_html: >-
Expand Down
5 changes: 0 additions & 5 deletions db/migrate/20241025154606_add_religion_type_to_vacancy.rb

This file was deleted.

13 changes: 12 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_10_29_154606) do
ActiveRecord::Schema[7.1].define(version: 2024_10_30_134844) do
# These are extensions that must be enabled in order to support this database
enable_extension "btree_gist"
enable_extension "citext"
Expand Down Expand Up @@ -246,6 +246,17 @@
t.text "safeguarding_issue_details"
t.boolean "training_and_cpds_section_completed"
t.integer "imported_steps", default: [], null: false, array: true
t.boolean "following_religion"
t.integer "religious_reference_type"
t.string "faith"
t.string "place_of_worship"
t.string "religious_referee_name"
t.string "religious_referee_address"
t.string "religious_referee_role"
t.string "religious_referee_email"
t.string "religious_referee_phone"
t.string "baptism_address"
t.date "baptism_date"
t.index ["jobseeker_id"], name: "index_job_applications_jobseeker_id"
t.index ["vacancy_id"], name: "index_job_applications_on_vacancy_id"
end
Expand Down
3 changes: 2 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# require "spec_helper"
require "spec_helper"
ENV["RAILS_ENV"] ||= "test"
require File.expand_path("../config/environment", __dir__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
Expand Down Expand Up @@ -32,6 +32,7 @@
Capybara::Selenium::Driver.new(app, browser: :chrome, options:)
end
end

Capybara.register_driver :chrome do |app|
options = Selenium::WebDriver::Chrome::Options.new(args: %w[no-sandbox disable-gpu window-size=1400,1800])

Expand Down
2 changes: 1 addition & 1 deletion spec/requests/jobseekers/govuk_one_login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
end

before do
allow_any_instance_of(ApplicationController).to receive(:stored_location_for).and_return(devise_stored_location) # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(ApplicationController).to receive(:stored_location_for).and_return(devise_stored_location)
allow(Jobseekers::GovukOneLogin::UserFromAuthResponse).to receive(:call).and_return(govuk_one_login_user)
get root_path # Loads OneLogin Sign-in button and sets session values for user.
end
Expand Down
Loading

0 comments on commit 9093a97

Please sign in to comment.