From ccffe538805e0fc211748b790eee74c2aeff66e5 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Wed, 27 Sep 2023 11:37:15 +0100 Subject: [PATCH] Refactor secondary_education_teaching_qualification_required? This removes the method and instead gets all users of this method to access the value directly. The reason for this is that we don't store the subject limited value on the application form (i.e. it can change if a country is made subject limited after an application is created). --- app/lib/assessment_factory.rb | 12 +- ...preliminary_assessment_sections_factory.rb | 4 +- app/models/application_form.rb | 4 - spec/lib/assessment_factory_spec.rb | 192 +++++++----------- 4 files changed, 85 insertions(+), 127 deletions(-) diff --git a/app/lib/assessment_factory.rb b/app/lib/assessment_factory.rb index 16318b847d..0d25093bf3 100644 --- a/app/lib/assessment_factory.rb +++ b/app/lib/assessment_factory.rb @@ -72,12 +72,12 @@ def qualifications_section "teaching_qualifications_completed_in_eligible_country", "qualified_in_mainstream_education", ( - if application_form.secondary_education_teaching_qualification_required? + if application_form.country.subject_limited "qualified_to_teach_children_11_to_16" end ), ( - if application_form.secondary_education_teaching_qualification_required? + if application_form.country.subject_limited "teaching_qualification_subjects_criteria" end ), @@ -124,12 +124,12 @@ def qualifications_section FailureReasons::QUALIFICATIONS_DONT_MATCH_SUBJECTS, FailureReasons::QUALIFICATIONS_DONT_MATCH_OTHER_DETAILS, ( - if application_form.secondary_education_teaching_qualification_required? + if application_form.country.subject_limited FailureReasons::QUALIFIED_TO_TEACH_CHILDREN_11_TO_16 end ), ( - if application_form.secondary_education_teaching_qualification_required? + if application_form.country.subject_limited FailureReasons::TEACHING_QUALIFICATION_SUBJECTS_CRITERIA end ), @@ -148,12 +148,12 @@ def age_range_subjects_section checks = [ "qualified_in_mainstream_education", ( - if application_form.secondary_education_teaching_qualification_required? + if application_form.country.subject_limited "qualified_to_teach_children_11_to_16" end ), ( - if application_form.secondary_education_teaching_qualification_required? + if application_form.country.subject_limited "teaching_qualification_subjects_criteria" end ), diff --git a/app/lib/preliminary_assessment_sections_factory.rb b/app/lib/preliminary_assessment_sections_factory.rb index fe10d56fe0..c56078801d 100644 --- a/app/lib/preliminary_assessment_sections_factory.rb +++ b/app/lib/preliminary_assessment_sections_factory.rb @@ -25,7 +25,7 @@ def qualifications end def qualifications_checks - if application_form.secondary_education_teaching_qualification_required? + if application_form.country.subject_limited %w[ qualifications_meet_level_6_or_equivalent teaching_qualification_subjects_criteria @@ -38,7 +38,7 @@ def qualifications_checks def qualifications_failure_reasons [ FailureReasons::TEACHING_QUALIFICATIONS_NOT_AT_REQUIRED_LEVEL, - if application_form.secondary_education_teaching_qualification_required? + if application_form.country.subject_limited FailureReasons::TEACHING_QUALIFICATION_SUBJECTS_CRITERIA end, ].compact diff --git a/app/models/application_form.rb b/app/models/application_form.rb index 77ac8a4683..67568810df 100644 --- a/app/models/application_form.rb +++ b/app/models/application_form.rb @@ -249,10 +249,6 @@ def english_language_exempt? english_language_citizenship_exempt || english_language_qualification_exempt end - def secondary_education_teaching_qualification_required? - country.subject_limited - end - def created_under_new_regulations? created_at >= Date.parse(ENV.fetch("NEW_REGS_DATE", "2023-02-01")) end diff --git a/spec/lib/assessment_factory_spec.rb b/spec/lib/assessment_factory_spec.rb index 32c3cbe4bf..ae6b3105e6 100644 --- a/spec/lib/assessment_factory_spec.rb +++ b/spec/lib/assessment_factory_spec.rb @@ -3,10 +3,12 @@ require "rails_helper" RSpec.describe AssessmentFactory do + let(:country) { create(:country) } let(:application_form) do create( :application_form, :old_regs, + region: create(:region, country:), needs_work_history: false, needs_written_statement: false, needs_registration_number: false, @@ -83,56 +85,44 @@ end context "under the old regulations" do - context "when secondary education teaching qualification is not required" do - before do - allow(application_form).to receive( - :secondary_education_teaching_qualification_required?, - ).and_return(false) - end - - it "has the right checks and failure reasons" do - section = sections.qualifications.first + it "has the right checks and failure reasons" do + section = sections.qualifications.first - expect(section.checks).to eq( - %w[ - qualifications_meet_level_6_or_equivalent - teaching_qualifications_completed_in_eligible_country - qualified_in_mainstream_education - has_teacher_qualification_certificate - has_teacher_qualification_transcript - has_university_degree_certificate - has_university_degree_transcript - has_additional_qualification_certificate - has_additional_degree_transcript - ], - ) + expect(section.checks).to eq( + %w[ + qualifications_meet_level_6_or_equivalent + teaching_qualifications_completed_in_eligible_country + qualified_in_mainstream_education + has_teacher_qualification_certificate + has_teacher_qualification_transcript + has_university_degree_certificate + has_university_degree_transcript + has_additional_qualification_certificate + has_additional_degree_transcript + ], + ) - expect(section.failure_reasons).to eq( - %w[ - application_and_qualification_names_do_not_match - teaching_qualifications_from_ineligible_country - teaching_qualifications_not_at_required_level - teaching_hours_not_fulfilled - not_qualified_to_teach_mainstream - qualifications_dont_match_subjects - qualifications_dont_match_other_details - teaching_certificate_illegible - teaching_transcript_illegible - degree_certificate_illegible - degree_transcript_illegible - additional_degree_certificate_illegible - additional_degree_transcript_illegible - ], - ) - end + expect(section.failure_reasons).to eq( + %w[ + application_and_qualification_names_do_not_match + teaching_qualifications_from_ineligible_country + teaching_qualifications_not_at_required_level + teaching_hours_not_fulfilled + not_qualified_to_teach_mainstream + qualifications_dont_match_subjects + qualifications_dont_match_other_details + teaching_certificate_illegible + teaching_transcript_illegible + degree_certificate_illegible + degree_transcript_illegible + additional_degree_certificate_illegible + additional_degree_transcript_illegible + ], + ) end context "when secondary education teaching qualification is required" do - before do - allow(application_form).to receive( - :secondary_education_teaching_qualification_required?, - ).and_return(true) - end + let(:country) { create(:country, :subject_limited) } it "has the right checks and failure reasons" do section = sections.qualifications.first @@ -177,62 +167,52 @@ end context "under the new regulations" do - let(:application_form) { create(:application_form) } - - context "when secondary education teaching qualification is not required" do - before do - allow(application_form).to receive( - :secondary_education_teaching_qualification_required?, - ).and_return(false) - end + let(:application_form) do + create(:application_form, region: create(:region, country:)) + end - it "has the right checks and failure reasons" do - section = sections.qualifications.first + it "has the right checks and failure reasons" do + section = sections.qualifications.first - expect(section.checks).to eq( - %w[ - qualifications_meet_level_6_or_equivalent - teaching_qualifications_completed_in_eligible_country - qualified_in_mainstream_education - has_teacher_qualification_certificate - has_teacher_qualification_transcript - has_university_degree_certificate - has_university_degree_transcript - has_additional_qualification_certificate - has_additional_degree_transcript - teaching_qualification_pedagogy - teaching_qualification_1_year - ], - ) + expect(section.checks).to eq( + %w[ + qualifications_meet_level_6_or_equivalent + teaching_qualifications_completed_in_eligible_country + qualified_in_mainstream_education + has_teacher_qualification_certificate + has_teacher_qualification_transcript + has_university_degree_certificate + has_university_degree_transcript + has_additional_qualification_certificate + has_additional_degree_transcript + teaching_qualification_pedagogy + teaching_qualification_1_year + ], + ) - expect(section.failure_reasons).to eq( - %w[ - application_and_qualification_names_do_not_match - teaching_qualifications_from_ineligible_country - teaching_qualifications_not_at_required_level - teaching_hours_not_fulfilled - teaching_qualification_pedagogy - teaching_qualification_1_year - not_qualified_to_teach_mainstream - qualifications_dont_match_subjects - qualifications_dont_match_other_details - teaching_certificate_illegible - teaching_transcript_illegible - degree_certificate_illegible - degree_transcript_illegible - additional_degree_certificate_illegible - additional_degree_transcript_illegible - ], - ) - end + expect(section.failure_reasons).to eq( + %w[ + application_and_qualification_names_do_not_match + teaching_qualifications_from_ineligible_country + teaching_qualifications_not_at_required_level + teaching_hours_not_fulfilled + teaching_qualification_pedagogy + teaching_qualification_1_year + not_qualified_to_teach_mainstream + qualifications_dont_match_subjects + qualifications_dont_match_other_details + teaching_certificate_illegible + teaching_transcript_illegible + degree_certificate_illegible + degree_transcript_illegible + additional_degree_certificate_illegible + additional_degree_transcript_illegible + ], + ) end context "when secondary education teaching qualification is required" do - before do - allow(application_form).to receive( - :secondary_education_teaching_qualification_required?, - ).and_return(true) - end + let(:country) { create(:country, :subject_limited) } it "has the right checks and failure reasons" do section = sections.qualifications.first @@ -282,18 +262,11 @@ end describe "age range and subjects section" do - before { create(:country, :subject_limited, code: "SG") } it "is created" do expect(sections.age_range_subjects.count).to eq(1) end context "when secondary education teaching qualification is not required" do - before do - allow(application_form).to receive( - :secondary_education_teaching_qualification_required?, - ).and_return(false) - end - it "has the right checks and failure reasons" do section = sections.age_range_subjects.first expect(section.checks).to eq( @@ -306,12 +279,7 @@ end context "with an application form with subject criteria" do - let(:application_form) do - create( - :application_form, - region: create(:region, :in_country, country_code: "SG"), - ) - end + let(:country) { create(:country, :subject_limited) } it "has the right checks and failure reasons" do section = sections.age_range_subjects.first @@ -333,7 +301,6 @@ end describe "preliminary qualifications section" do - before { create(:country, :subject_limited, code: "SG") } it "is not created" do expect(sections.preliminary.qualifications.count).to eq(0) end @@ -354,12 +321,7 @@ end context "with an application form with subject criteria" do - let(:application_form) do - create( - :application_form, - region: create(:region, :in_country, country_code: "SG"), - ) - end + let(:country) { create(:country, :subject_limited) } it "has the right checks and failure reasons" do section = sections.preliminary.qualifications.first