Skip to content

Commit

Permalink
Refactor EBacc subjects
Browse files Browse the repository at this point in the history
This refactors how we determine whether a subject is an EBacc subject.
  • Loading branch information
thomasleese committed May 16, 2024
1 parent 45aa6aa commit e35d8fe
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 60 deletions.
97 changes: 37 additions & 60 deletions app/models/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,83 +18,92 @@ 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
design_and_technology
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
14 changes: 14 additions & 0 deletions spec/models/subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e35d8fe

Please sign in to comment.