From 9b26c2a73ad46b53c7358e3cee155b5b6ff0b1b9 Mon Sep 17 00:00:00 2001 From: Kyle MacPherson Date: Thu, 23 Jan 2025 12:19:50 +0000 Subject: [PATCH] Remove references to 'other_secondary' qualifications as they have been deleted in a previous PR --- .../jobseekers/qualification_form_concerns.rb | 2 - .../qualifications/secondary/other_form.rb | 3 - app/helpers/qualifications_helper.rb | 1 - app/models/qualification.rb | 6 +- app/services/qualifications_migration.rb | 19 ----- .../qualifications/_fields.html.slim | 2 +- .../fields/_secondary_school.html.slim | 3 - config/locales/forms.yml | 6 -- config/locales/jobseekers.yml | 3 - ...update_other_secondary_qualifications.rake | 9 -- spec/factories/qualifications.rb | 2 +- .../secondary/other_form_spec.rb | 8 -- spec/models/qualification_spec.rb | 6 +- .../services/qualifications_migration_spec.rb | 82 ------------------- spec/support/jobseeker_helpers.rb | 10 --- ...fications_to_their_job_application_spec.rb | 8 +- ...dd_qualifications_to_their_profile_spec.rb | 8 +- 17 files changed, 16 insertions(+), 162 deletions(-) delete mode 100644 app/form_models/jobseekers/qualifications/secondary/other_form.rb delete mode 100644 app/services/qualifications_migration.rb delete mode 100644 lib/tasks/update_other_secondary_qualifications.rake delete mode 100644 spec/form_models/jobseekers/qualifications/secondary/other_form_spec.rb delete mode 100644 spec/services/qualifications_migration_spec.rb diff --git a/app/controllers/concerns/jobseekers/qualification_form_concerns.rb b/app/controllers/concerns/jobseekers/qualification_form_concerns.rb index c79315b40a..87cf7d833a 100644 --- a/app/controllers/concerns/jobseekers/qualification_form_concerns.rb +++ b/app/controllers/concerns/jobseekers/qualification_form_concerns.rb @@ -9,8 +9,6 @@ def category_form_class(category) name = case category when "gcse", "a_level", "as_level" "Secondary::CommonForm" - when "other_secondary" - "Secondary::OtherForm" when "undergraduate", "postgraduate" "DegreeForm" when "other" diff --git a/app/form_models/jobseekers/qualifications/secondary/other_form.rb b/app/form_models/jobseekers/qualifications/secondary/other_form.rb deleted file mode 100644 index cd37e5c981..0000000000 --- a/app/form_models/jobseekers/qualifications/secondary/other_form.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Jobseekers::Qualifications::Secondary::OtherForm < Jobseekers::Qualifications::Secondary::CommonForm - validates :name, presence: true -end diff --git a/app/helpers/qualifications_helper.rb b/app/helpers/qualifications_helper.rb index b2f3dfc9f4..db2afc2a7c 100644 --- a/app/helpers/qualifications_helper.rb +++ b/app/helpers/qualifications_helper.rb @@ -5,7 +5,6 @@ module QualificationsHelper a_level as_level gcse - other_secondary other ].freeze diff --git a/app/models/qualification.rb b/app/models/qualification.rb index cf12cf5367..3a872d047a 100644 --- a/app/models/qualification.rb +++ b/app/models/qualification.rb @@ -8,9 +8,9 @@ class Qualification < ApplicationRecord accepts_nested_attributes_for :qualification_results has_encrypted :finished_studying_details - SECONDARY_QUALIFICATIONS = %w[gcse as_level a_level other_secondary].freeze + SECONDARY_QUALIFICATIONS = %w[gcse as_level a_level].freeze - enum :category, { gcse: 0, as_level: 1, a_level: 2, other_secondary: 3, undergraduate: 4, postgraduate: 5, other: 6 } + enum :category, { gcse: 0, as_level: 1, a_level: 2, undergraduate: 4, postgraduate: 5, other: 6 } before_validation :remove_inapplicable_data, :mark_emptied_qualification_results_for_destruction @@ -29,7 +29,7 @@ def duplicate end def name - return read_attribute(:name) if read_attribute(:name).present? || other? || other_secondary? + return read_attribute(:name) if read_attribute(:name).present? || other? I18n.t("helpers.label.jobseekers_qualifications_category_form.category_options.#{category}") end diff --git a/app/services/qualifications_migration.rb b/app/services/qualifications_migration.rb deleted file mode 100644 index 1fd86a4920..0000000000 --- a/app/services/qualifications_migration.rb +++ /dev/null @@ -1,19 +0,0 @@ -class QualificationsMigration - def self.perform - ActiveRecord::Base.transaction do - Qualification.includes(:qualification_results).where(category: "other_secondary").find_each(batch_size: 500) do |qualification| - qualification.qualification_results.each do |result| - Qualification.create!(category: "other", subject: result.subject, grade: result.grade, awarding_body: result.awarding_body, - institution: qualification.institution, name: qualification.name, year: qualification.year, - job_application_id: qualification.job_application_id, jobseeker_profile_id: qualification.jobseeker_profile_id, - finished_studying: qualification.finished_studying) - end - - qualification.destroy! - end - end - rescue StandardError => e - Rails.logger.error("Error migrating qualifications: #{e.message}") - raise - end -end diff --git a/app/views/jobseekers/qualifications/_fields.html.slim b/app/views/jobseekers/qualifications/_fields.html.slim index 6a613f90a1..36c8d8620a 100644 --- a/app/views/jobseekers/qualifications/_fields.html.slim +++ b/app/views/jobseekers/qualifications/_fields.html.slim @@ -1,7 +1,7 @@ = f.hidden_field :category - case category -- when "gcse", "as_level", "a_level", "other_secondary" +- when "gcse", "as_level", "a_level" = render "jobseekers/qualifications/fields/secondary_school", f: f, category: category - when "undergraduate", "postgraduate", "degree" = render "jobseekers/qualifications/fields/degree", f: f diff --git a/app/views/jobseekers/qualifications/fields/_secondary_school.html.slim b/app/views/jobseekers/qualifications/fields/_secondary_school.html.slim index 71bd88266f..944f5adecd 100644 --- a/app/views/jobseekers/qualifications/fields/_secondary_school.html.slim +++ b/app/views/jobseekers/qualifications/fields/_secondary_school.html.slim @@ -1,8 +1,5 @@ = f.govuk_text_field :institution, label: { size: "s" }, aria: { required: true }, width: "three-quarters" -- if category == "other_secondary" - = f.govuk_text_field :name, label: { size: "s" }, aria: { required: true }, width: "two-thirds" - = f.govuk_number_field :year, label: { size: "s" }, aria: { required: true }, width: 4 = f.govuk_fieldset legend: { text: t("helpers.legend.jobseekers_qualifications_shared_legends.subjects") }, class: "subjects-and-grades", data: { controller: "manage-qualifications" } do diff --git a/config/locales/forms.yml b/config/locales/forms.yml index 5a70fa5b79..e9f26fc37e 100644 --- a/config/locales/forms.yml +++ b/config/locales/forms.yml @@ -393,7 +393,6 @@ en: gcse: GCSEs as_level: AS Levels a_level: A Levels - other_secondary: Other secondary qualification undergraduate: Undergraduate degree postgraduate: Postgraduate qualification other: Other qualification @@ -453,7 +452,6 @@ en: gcse: GCSEs as_level: AS Levels a_level: A Levels - other_secondary: Other secondary qualification undergraduate: Undergraduate degree postgraduate: Postgraduate qualification other: Other qualification @@ -471,10 +469,6 @@ en: jobseekers_qualifications_secondary_common_form: <<: *jobseekers_qualifications_shared_labels institution: School, college, or other organisation - jobseekers_qualifications_secondary_other_form: - <<: *jobseekers_qualifications_shared_labels - institution: School, college, or other organisation - name: Qualification name jobseekers_profile_qualified_teacher_status_form: qualified_teacher_status_options: "yes": "Yes" diff --git a/config/locales/jobseekers.yml b/config/locales/jobseekers.yml index 87c70fdae1..7fb3072e1c 100644 --- a/config/locales/jobseekers.yml +++ b/config/locales/jobseekers.yml @@ -410,7 +410,6 @@ en: gcse: Edit GCSEs as_level: Edit AS Levels a_level: Edit A Levels - other_secondary: Edit secondary qualifications undergraduate: Edit undergraduate degree postgraduate: Edit postgraduate qualification other: Edit qualification @@ -421,7 +420,6 @@ en: gcse: Add GCSEs as_level: Add AS Levels a_level: Add A Levels - other_secondary: Add secondary qualifications undergraduate: Add an undergraduate degree postgraduate: Add a postgraduate qualification other: Add a qualification @@ -811,7 +809,6 @@ en: gcse: Add GCSEs as_level: Add AS Levels a_level: Add A Levels - other_secondary: Add secondary qualifications undergraduate: Add an undergraduate degree postgraduate: Add a postgraduate qualification other: Add a qualification diff --git a/lib/tasks/update_other_secondary_qualifications.rake b/lib/tasks/update_other_secondary_qualifications.rake deleted file mode 100644 index ac6f5580c1..0000000000 --- a/lib/tasks/update_other_secondary_qualifications.rake +++ /dev/null @@ -1,9 +0,0 @@ -namespace :qualifications do - desc "Migrate other_secondary qualifications to other category" - task migrate_to_other: :environment do - QualificationsMigration.perform - puts "Migration completed successfully." - rescue StandardError => e - puts "Migration failed: #{e.message}" - end -end diff --git a/spec/factories/qualifications.rb b/spec/factories/qualifications.rb index fbe2b58394..210512579e 100644 --- a/spec/factories/qualifications.rb +++ b/spec/factories/qualifications.rb @@ -23,7 +23,7 @@ end end institution { secondary? ? Faker::Educator.secondary_school : Faker::Educator.university } - name { other_secondary? || other? ? Faker::Educator.degree : "" } + name { other? ? Faker::Educator.degree : "" } subject { undergraduate? || postgraduate? || other? ? Faker::Educator.subject : "" } year { finished_studying == false ? nil : factory_rand(1970..2020) } diff --git a/spec/form_models/jobseekers/qualifications/secondary/other_form_spec.rb b/spec/form_models/jobseekers/qualifications/secondary/other_form_spec.rb deleted file mode 100644 index 88187c78dc..0000000000 --- a/spec/form_models/jobseekers/qualifications/secondary/other_form_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -require "rails_helper" - -RSpec.describe Jobseekers::Qualifications::Secondary::OtherForm, type: :model do - it { is_expected.to validate_presence_of(:category) } - it { is_expected.to validate_presence_of(:name) } - it { is_expected.to validate_presence_of(:institution) } - it { is_expected.to validate_numericality_of(:year).is_less_than_or_equal_to(Time.current.year) } -end diff --git a/spec/models/qualification_spec.rb b/spec/models/qualification_spec.rb index c670d1ab91..39682baf78 100644 --- a/spec/models/qualification_spec.rb +++ b/spec/models/qualification_spec.rb @@ -7,8 +7,8 @@ describe "#name" do let(:qualification) { build_stubbed(:qualification, name: name, category: category) } - context "when the category is 'other_secondary' or 'other'" do - let(:category) { "other_secondary" } + context "when the category is 'other'" do + let(:category) { "other" } let(:name) { "Welsh Baccalaureate" } context "when the name has been set" do @@ -26,7 +26,7 @@ end end - context "when the category is not 'other_secondary' or 'other' and the name has not been set" do + context "when the category is not 'other' and the name has not been set" do let(:category) { "undergraduate" } let(:name) { "" } diff --git a/spec/services/qualifications_migration_spec.rb b/spec/services/qualifications_migration_spec.rb deleted file mode 100644 index 37df2a1e9b..0000000000 --- a/spec/services/qualifications_migration_spec.rb +++ /dev/null @@ -1,82 +0,0 @@ -require "rails_helper" - -RSpec.describe QualificationsMigration, type: :model do - let!(:profile) { create(:jobseeker_profile) } - let!(:application) { create(:job_application) } - - let!(:profile_qualification) { create(:qualification, category: "other_secondary", jobseeker_profile: profile, job_application: nil) } - let!(:application_qualification) { create(:qualification, category: "other_secondary", job_application: application, jobseeker_profile: nil) } - let!(:unrelated_qualification) { create(:qualification, category: "a_level") } - - before do - profile_qualification.qualification_results.destroy_all - application_qualification.qualification_results.destroy_all - - QualificationResult.create!(qualification: profile_qualification, subject: "Science", grade: "A", awarding_body: "Oxford exam board") - QualificationResult.create!(qualification: application_qualification, subject: "History", grade: "B", awarding_body: "AXA") - end - - describe ".perform" do - it "migrates qualifications with category other_secondary to other" do - expect { - described_class.perform - }.to change { Qualification.where(category: "other").count }.by(2) - end - - it "creates new qualifications with the correct attributes" do - described_class.perform - new_qualifications = Qualification.where(category: "other") - - expect(new_qualifications.count).to eq(2) - expect(new_qualifications.pluck(:subject)).to contain_exactly("Science", "History") - expect(new_qualifications.pluck(:grade)).to contain_exactly("A", "B") - expect(new_qualifications.pluck(:awarding_body)).to contain_exactly("Oxford exam board", "AXA") - end - - it "ensures new qualifications maintain their associations" do - described_class.perform - - profile_other_qualification = Qualification.find_by(subject: "Science", category: "other") - application_other_qualification = Qualification.find_by(subject: "History", category: "other") - - expect(profile_other_qualification.jobseeker_profile).to eq(profile) - expect(profile_other_qualification.job_application).to be_nil - - expect(application_other_qualification.job_application).to eq(application) - expect(application_other_qualification.jobseeker_profile).to be_nil - end - - it "deletes the original qualifications with category other_secondary" do - expect { - described_class.perform - }.to change { Qualification.where(category: "other_secondary").count }.by(-2) - end - - it "does not change other qualification types" do - expect { - described_class.perform - }.not_to(change { Qualification.where(category: "a_level").count }) - - unaffected_qualification = Qualification.find_by(id: unrelated_qualification.id) - expect(unaffected_qualification).to be_present - expect(unaffected_qualification.category).to eq("a_level") - end - - context "when an error occurs during migration" do - before do - allow(Qualification).to receive(:create!).and_raise(StandardError, "Test error") - end - - it "logs the error and does not delete original qualifications" do - expect(Rails.logger).to receive(:error).with(/Error migrating qualifications: Test error/) - expect { - begin - described_class.perform - rescue StandardError - nil - end - }.not_to(change { Qualification.where(category: "other_secondary").count }) - end - end - end -end diff --git a/spec/support/jobseeker_helpers.rb b/spec/support/jobseeker_helpers.rb index c0f43d940a..530ddd981a 100644 --- a/spec/support/jobseeker_helpers.rb +++ b/spec/support/jobseeker_helpers.rb @@ -126,16 +126,6 @@ def fill_in_gcses fill_in I18n.t("helpers.label.jobseekers_qualifications_shared_labels.year"), with: "2020" end - def fill_in_custom_secondary_qualifications - fill_in "Qualification name", with: "Welsh Baccalaureate" - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][0][subject]", with: "Science" - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][0][grade]", with: "5" - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][1][subject]", with: "German" - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][1][grade]", with: "4" - fill_in "School, college, or other organisation", with: "Happy Rainbows School for High Achievers" - fill_in I18n.t("helpers.label.jobseekers_qualifications_shared_labels.year"), with: "2020" - end - def fill_in_undergraduate_degree fill_in "Subject", with: "Linguistics" fill_in "Awarding body", with: "University of Life" diff --git a/spec/system/jobseekers/jobseekers_can_add_qualifications_to_their_job_application_spec.rb b/spec/system/jobseekers/jobseekers_can_add_qualifications_to_their_job_application_spec.rb index b2fe011491..f7543c3a00 100644 --- a/spec/system/jobseekers/jobseekers_can_add_qualifications_to_their_job_application_spec.rb +++ b/spec/system/jobseekers/jobseekers_can_add_qualifications_to_their_job_application_spec.rb @@ -71,7 +71,7 @@ context "when the qualification has qualification results" do let!(:qualification) do create(:qualification, - category: "other_secondary", + category: "a_level", institution: "John Mason School", job_application: job_application) end @@ -79,7 +79,7 @@ it "allows jobseekers to edit the qualification and its results" do visit jobseekers_job_application_build_path(job_application, :qualifications) click_on I18n.t("buttons.change") - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][0][subject]", with: "Hard Knocks" + fill_in "jobseekers_qualifications_secondary_common_form[qualification_results_attributes][0][subject]", with: "Hard Knocks" empty_second_qualification_result fill_in "School", with: "St Nicholas School" expect { click_on I18n.t("buttons.save_qualification.one") }.to change { qualification.qualification_results.count }.by(-1) @@ -114,7 +114,7 @@ end def empty_second_qualification_result - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][1][subject]", with: "" - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][1][grade]", with: "" + fill_in "jobseekers_qualifications_secondary_common_form[qualification_results_attributes][1][subject]", with: "" + fill_in "jobseekers_qualifications_secondary_common_form[qualification_results_attributes][1][grade]", with: "" end end diff --git a/spec/system/jobseekers/jobseekers_can_add_qualifications_to_their_profile_spec.rb b/spec/system/jobseekers/jobseekers_can_add_qualifications_to_their_profile_spec.rb index d16ce28268..24ca900f28 100644 --- a/spec/system/jobseekers/jobseekers_can_add_qualifications_to_their_profile_spec.rb +++ b/spec/system/jobseekers/jobseekers_can_add_qualifications_to_their_profile_spec.rb @@ -98,7 +98,7 @@ context "when the qualification has qualification results" do let!(:qualification) do create(:qualification, - category: "other_secondary", + category: "a_level", institution: "John Mason School", jobseeker_profile_id: profile.id) end @@ -106,7 +106,7 @@ it "allows jobseekers to edit the qualification and its results" do visit review_jobseekers_profile_qualifications_path click_on "Change" - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][0][subject]", with: "Hard Knocks" + fill_in "jobseekers_qualifications_secondary_common_form[qualification_results_attributes][0][subject]", with: "Hard Knocks" empty_second_qualification_result fill_in "School", with: "St Nicholas School" click_on I18n.t("buttons.save_and_continue") @@ -136,7 +136,7 @@ end def empty_second_qualification_result - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][1][subject]", with: "" - fill_in "jobseekers_qualifications_secondary_other_form[qualification_results_attributes][1][grade]", with: "" + fill_in "jobseekers_qualifications_secondary_common_form[qualification_results_attributes][1][subject]", with: "" + fill_in "jobseekers_qualifications_secondary_common_form[qualification_results_attributes][1][grade]", with: "" end end