From e35d8fe52ee74facb8ed5949e24bdc4d0d530e19 Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Thu, 16 May 2024 11:49:34 +0100 Subject: [PATCH] Refactor EBacc subjects This refactors how we determine whether a subject is an EBacc subject. --- app/models/subject.rb | 97 ++++++++++++++----------------------- spec/models/subject_spec.rb | 14 ++++++ 2 files changed, 51 insertions(+), 60 deletions(-) diff --git a/app/models/subject.rb b/app/models/subject.rb index 26392d859d..2062cf4711 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -3,40 +3,8 @@ class Subject include ActiveModel::Model - attr_accessor :value, :name - - def ebacc? - EBACC_VALUES.include?(value) - end - - EBACC_VALUES = %w[ - applied_biology - ancient_hebrew - applied_chemistry - applied_physics - arabic_languages - biology - chinese_languages - computer_science - english_studies - environmental_sciences - french_language - general_sciences - geography - german_language - history - italian_language - latin_language - materials_science - mathematics - portuguese_language - spanish_language - statistics - modern_languages - russian_languages - physics - chemistry - ].freeze + attr_accessor :value, :name, :ebacc + alias_method :ebacc?, :ebacc class << self def all @@ -50,27 +18,51 @@ def find(values) private def create(value:) - Subject.new(value:, name: I18n.t("subjects.#{value}")) + Subject.new( + value:, + name: I18n.t("subjects.#{value}"), + ebacc: EBACC_VALUES.include?(value), + ) end - ALL_VALUES = %w[ + EBACC_VALUES = %w[ ancient_hebrew applied_biology applied_chemistry - applied_computing applied_physics arabic_languages - art_and_design biology + chemistry + chinese_languages + computer_science + english_studies + environmental_sciences + french_language + general_sciences + geography + german_language + history + italian_language + latin_language + materials_science + mathematics + modern_languages + physics + portuguese_language + russian_languages + spanish_language + statistics + ].freeze + + NON_EBACC_VALUES = %w[ + applied_computing + art_and_design business_management business_studies - chemistry child_development - chinese_languages citizenship classical_greek_studies classical_studies - computer_science construction_and_the_built_environment dance design @@ -78,55 +70,40 @@ def create(value:) drama early_years_teaching economics - english_studies - environmental_sciences food_and_beverage_studies - french_language general_or_integrated_engineering - general_sciences - geography - german_language graphic_design hair_and_beauty_sciences health_and_social_care health_studies historical_linguistics - history hospitality information_technology - italian_language - latin_language law manufacturing_engineering - materials_science - mathematics media_and_communication_studies - modern_languages music_education_and_teaching performing_arts philosophy physical_education - physics - portuguese_language primary_teaching - production_and_manufacturing_engineering product_design + production_and_manufacturing_engineering psychology public_services recreation_and_leisure_studies religious_studies retail_management - russian_languages social_sciences - spanish_language specialist_teaching_primary_with_mathematics - sports_management sport_and_exercise_sciences - statistics + sports_management textiles_technology travel_and_tourism uk_government_parliamentary_studies welsh_language ].freeze + + ALL_VALUES = (EBACC_VALUES + NON_EBACC_VALUES).sort end end diff --git a/spec/models/subject_spec.rb b/spec/models/subject_spec.rb index e10a8b4df5..90c6bec0f2 100644 --- a/spec/models/subject_spec.rb +++ b/spec/models/subject_spec.rb @@ -18,4 +18,18 @@ expect(find.second.value).to eq("economics") end end + + describe "#ebacc?" do + subject(:ebacc?) { described_class.find([value]).first.ebacc? } + + context "with an EBacc subject" do + let(:value) { "ancient_hebrew" } + it { is_expected.to be true } + end + + context "with a non-EBacc subject" do + let(:value) { "applied_computing" } + it { is_expected.to be false } + end + end end