Skip to content

Commit

Permalink
Refactor secondary_education_teaching_qualification_required?
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
thomasleese committed Sep 27, 2023
1 parent a4adeb8 commit ccffe53
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 127 deletions.
12 changes: 6 additions & 6 deletions app/lib/assessment_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down Expand Up @@ -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
),
Expand All @@ -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
),
Expand Down
4 changes: 2 additions & 2 deletions app/lib/preliminary_assessment_sections_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
192 changes: 77 additions & 115 deletions spec/lib/assessment_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ccffe53

Please sign in to comment.