Skip to content

Commit

Permalink
Merge pull request #1676 from DFE-Digital/2172-subject-limited-countries
Browse files Browse the repository at this point in the history
2172 subject limited countries
  • Loading branch information
syed87 authored Sep 27, 2023
2 parents 75953c3 + fa8abaa commit 2e0c589
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 51 deletions.
3 changes: 2 additions & 1 deletion app/controllers/support_interface/countries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def edit
@form =
CountryForm.new(
country:,
subject_limited: country.subject_limited,
eligibility_enabled: country.eligibility_enabled,
eligibility_skip_questions: country.eligibility_skip_questions,
has_regions: country.regions.count > 1,
Expand Down Expand Up @@ -58,13 +59,13 @@ def country
def country_params
params.require(:support_interface_country_form).permit(
:eligibility_enabled,
:eligibility_skip_questions,
:has_regions,
:other_information,
:qualifications_information,
:region_names,
:sanction_information,
:status_information,
:eligibility_route,
)
end
end
Expand Down
32 changes: 31 additions & 1 deletion app/forms/support_interface/country_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
class SupportInterface::CountryForm
include ActiveModel::Model
include ActiveModel::Attributes
include ActiveModel::Dirty

attr_accessor :country
validates :country, presence: true

attribute :subject_limited, :boolean
attribute :eligibility_enabled, :boolean
attribute :eligibility_skip_questions, :boolean
attribute :has_regions, :boolean
Expand Down Expand Up @@ -42,7 +44,11 @@ def save!
end

def assign_country_attributes
country.assign_attributes(eligibility_enabled:, eligibility_skip_questions:)
country.assign_attributes(
eligibility_enabled:,
eligibility_skip_questions:,
subject_limited:,
)

if has_regions
country.assign_attributes(
Expand Down Expand Up @@ -81,4 +87,28 @@ def diff_actions
(delete_actions + create_actions).sort_by { |action| action[:name] }
end
end

def eligibility_route
if subject_limited
"expanded"
elsif eligibility_skip_questions
"reduced"
else
"standard"
end
end

def eligibility_route=(value)
case value
when "standard"
self.subject_limited = false
self.eligibility_skip_questions = false
when "reduced"
self.subject_limited = false
self.eligibility_skip_questions = true
when "expanded"
self.subject_limited = true
self.eligibility_skip_questions = false
end
end
end
6 changes: 0 additions & 6 deletions app/lib/country_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ def european_economic_area?(code)
Country::CODES_IN_EUROPEAN_ECONOMIC_AREA.include?(code)
end

def secondary_education_teaching_qualification_required?(code)
Country::CODES_REQUIRING_SECONDARY_EDUCATION_TEACHING_QUALIFICATION.include?(
code,
)
end

LOCATIONS_BY_COUNTRY_CODE =
Country::LOCATION_AUTOCOMPLETE_CANONICAL_LIST
.map { |row| [CountryCode.from_location(row.last), row.last] }
Expand Down
4 changes: 1 addition & 3 deletions app/models/application_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ def english_language_exempt?
end

def secondary_education_teaching_qualification_required?
CountryCode.secondary_education_teaching_qualification_required?(
country.code,
)
country.subject_limited
end

def created_under_new_regulations?
Expand Down
7 changes: 1 addition & 6 deletions app/models/country.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# qualifications_information :text default(""), not null
# sanction_information :string default(""), not null
# status_information :string default(""), not null
# subject_limited :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
#
Expand All @@ -31,11 +32,5 @@ class Country < ApplicationRecord
CODES_IN_EUROPEAN_ECONOMIC_AREA =
YAML.load(File.read("lib/countries-in-european-economic-area.yaml"))

CODES_ELIGIBLE_IN_FEBRUARY_2023 =
YAML.load(File.read("lib/countries-eligible-in-february-2023.yaml"))

CODES_REQUIRING_SECONDARY_EDUCATION_TEACHING_QUALIFICATION =
CODES_ELIGIBLE_IN_FEBRUARY_2023 - %w[HK UA]

validates :code, inclusion: { in: CODES }
end
4 changes: 1 addition & 3 deletions app/models/eligibility_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ def status
def qualified_for_subject_required?
return false if country_code.blank?

CountryCode.secondary_education_teaching_qualification_required?(
country_code,
)
Country.exists?(code: country_code, subject_limited: true)
end

private
Expand Down
7 changes: 4 additions & 3 deletions app/views/support_interface/countries/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
:label,
legend: { text: "Do we accept applications from this country?" } %>

<%= f.govuk_collection_radio_buttons :eligibility_skip_questions,
<%= f.govuk_collection_radio_buttons :eligibility_route,
[
OpenStruct.new(value: :false, label: "Standard – Asks 5 standard questions that most countries would need to be asked."),
OpenStruct.new(value: :true, label: "Reduced – Only asks if the applicant’s teaching qualification was completed in their country of recognition.")
OpenStruct.new(value: :standard, label: "Standard – Asks 5 standard questions that most countries would need to be asked."),
OpenStruct.new(value: :reduced, label: "Reduced – Only asks if the applicant’s teaching qualification was completed in their country of recognition."),
OpenStruct.new(value: :expanded, label: "Expanded – Asks 5 standard questions but the subjects are restricted and age range taught changes to 11-16 years.")
],
:value,
:label,
Expand Down
5 changes: 4 additions & 1 deletion app/views/support_interface/countries/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
<%= govuk_tag(text: "Ineligible", colour: "red", classes: ["govuk-!-margin-left-2"]) %>
<% end %>

<% if country.eligibility_skip_questions %>
<% if country.subject_limited %>
<%= govuk_tag(text: "Expanded eligibility", colour: "yellow", classes: ["govuk-!-margin-left-2"]) %>
<% elsif country.eligibility_skip_questions %>
<%= govuk_tag(text: "Reduced eligibility", colour: "yellow", classes: ["govuk-!-margin-left-2"]) %>
<% else %>
<%= govuk_tag(text: "Standard eligibility", colour: "grey", classes: ["govuk-!-margin-left-2"]) %>
<% end %>

</h2>
<% end %>
<% end %>
Expand Down
14 changes: 14 additions & 0 deletions app/views/support_interface/countries/preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@
<%= raw GovukMarkdown.render(@country.qualifications_information) %>
<% end %>

<% if @country.eligibility_skip_questions_changed? || @country.subject_limited_changed? %>
<h3 class="govuk-heading-s">Which route will applicants take through the eligibility checker?</h3>
<p class="govuk-body">
<% if @country.subject_limited %>
<%= govuk_tag(text: "Expanded", colour: "yellow") %>
<% elsif @country.eligibility_skip_questions %>
<%= govuk_tag(text: "Reduced", colour: "yellow") %>
<% else %>
<%= govuk_tag(text: "Standard", colour: "grey") %>
<% end %>
</p>
<% end %>

<%= form_with model: @form, url: [:support_interface, @country], method: :put do |f| %>
<%= f.hidden_field :eligibility_enabled, value: @form.eligibility_enabled %>
<%= f.hidden_field :eligibility_skip_questions, value: @form.eligibility_skip_questions %>
Expand All @@ -62,5 +75,6 @@
<%= f.hidden_field :region_names, value: @form.region_names %>
<%= f.hidden_field :sanction_information, value: @form.sanction_information %>
<%= f.hidden_field :status_information, value: @form.status_information %>
<%= f.hidden_field :eligibility_route, value: @form.eligibility_route %>
<%= f.govuk_submit "Save", name: "preview", value: "false" %>
<% end %>
1 change: 1 addition & 0 deletions config/analytics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
- sanction_information
- status_information
- updated_at
- subject_limited
:documents:
- available
- completed
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20230912081147_add_subject_limited_to_countries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddSubjectLimitedToCountries < ActiveRecord::Migration[7.0]
def change
add_column :countries,
:subject_limited,
:boolean,
default: false,
null: false
end
end
1 change: 1 addition & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,7 @@
name: english_language_provider[:name],
).update!(english_language_provider.except(:name))
end

subject_limited_countries = %w[GH IN JM NG SG ZA ZW]

Country.where(code: subject_limited_countries).update_all(subject_limited: true)
14 changes: 3 additions & 11 deletions spec/factories/countries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# qualifications_information :text default(""), not null
# sanction_information :string default(""), not null
# status_information :string default(""), not null
# subject_limited :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
#
Expand All @@ -21,17 +22,8 @@
factory :country do
sequence :code, Country::CODES.cycle

trait :requires_secondary_education_teaching_qualification do
sequence :code,
Country::CODES_REQUIRING_SECONDARY_EDUCATION_TEACHING_QUALIFICATION.cycle
end

trait :doesnt_require_secondary_education_teaching_qualification do
sequence :code,
(
Country::CODES -
Country::CODES_REQUIRING_SECONDARY_EDUCATION_TEACHING_QUALIFICATION
).cycle
trait :subject_limited do
subject_limited { true }
end

trait :with_national_region do
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/assessment_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@
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
Expand Down Expand Up @@ -332,6 +333,7 @@
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 Down
9 changes: 0 additions & 9 deletions spec/lib/country_code_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,4 @@

include_examples "true with codes", Country::CODES_IN_EUROPEAN_ECONOMIC_AREA
end

describe "#secondary_education_teaching_qualification_required?" do
subject(:secondary_education_teaching_qualification_required?) do
described_class.secondary_education_teaching_qualification_required?(code)
end

include_examples "true with codes",
Country::CODES_REQUIRING_SECONDARY_EDUCATION_TEACHING_QUALIFICATION
end
end
1 change: 1 addition & 0 deletions spec/lib/preliminary_assessment_sections_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:application_form) { create(:application_form) }

describe "#call" do
before { create(:country, :subject_limited, code: "SG") }
subject(:assessment_sections) { described_class.call(application_form:) }

it { is_expected.to be_empty }
Expand Down
1 change: 1 addition & 0 deletions spec/models/country_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# qualifications_information :text default(""), not null
# sanction_information :string default(""), not null
# status_information :string default(""), not null
# subject_limited :boolean default(FALSE), not null
# created_at :datetime not null
# updated_at :datetime not null
#
Expand Down
9 changes: 3 additions & 6 deletions spec/models/eligibility_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@

context "when filtering by subject" do
before { eligibility_check.country_code = "IN" }
before { create(:country, :subject_limited, code: "IN") }

context "when teach_children is false" do
before { eligibility_check.teach_children = false }
Expand Down Expand Up @@ -289,12 +290,7 @@
subject { eligibility_check.status }

let(:eligibility_check) { described_class.new(attributes) }
let(:country) do
create(
:country,
:doesnt_require_secondary_education_teaching_qualification,
)
end
let(:country) { create(:country) }

context "when no attributes are present" do
let(:attributes) { nil }
Expand Down Expand Up @@ -401,6 +397,7 @@
before { eligibility_check.country_code = code }

context "with a relevant country" do
before { create(:country, :subject_limited, code: "JM") }
let(:code) { "JM" }

it { is_expected.to be true }
Expand Down
2 changes: 1 addition & 1 deletion spec/system/eligibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def given_countries_exist
it = create(:country, code: "IT")
create(:region, country: it, name: "Region")
create(:region, country: it, name: "Other Region")
create(:country, :with_national_region, code: "JM")
create(:country, :with_national_region, :subject_limited, code: "JM")
end

def then_i_do_not_see_the_start_page
Expand Down

0 comments on commit 2e0c589

Please sign in to comment.