diff --git a/app/forms/candidate_interface/equality_and_diversity/ethnic_background_form.rb b/app/forms/candidate_interface/equality_and_diversity/ethnic_background_form.rb index 1a812fe8c58..b0eb8f64d66 100644 --- a/app/forms/candidate_interface/equality_and_diversity/ethnic_background_form.rb +++ b/app/forms/candidate_interface/equality_and_diversity/ethnic_background_form.rb @@ -46,7 +46,7 @@ def save(application_form) end def self.listed_ethnic_background?(group, background) - ETHNIC_BACKGROUNDS[group].include?(background) || OTHER_ETHNIC_BACKGROUNDS[group] == background + ETHNIC_BACKGROUNDS[group]&.include?(background) || OTHER_ETHNIC_BACKGROUNDS[group] == background end private diff --git a/spec/forms/candidate_interface/equality_and_diversity/ethnic_background_form_spec.rb b/spec/forms/candidate_interface/equality_and_diversity/ethnic_background_form_spec.rb index 2ea024381ce..928ed1d9791 100644 --- a/spec/forms/candidate_interface/equality_and_diversity/ethnic_background_form_spec.rb +++ b/spec/forms/candidate_interface/equality_and_diversity/ethnic_background_form_spec.rb @@ -140,4 +140,21 @@ describe 'validations' do it { is_expected.to validate_presence_of(:ethnic_background) } end + + describe '.listed_ethnic_background?' do + it 'returns true if the group and background are in the ethnic backgrounds' do + result = described_class.listed_ethnic_background?('Another ethnic group', 'Arab') + expect(result).to be_truthy + end + + it 'returns false if the group and background are not the ethnic backgrounds' do + result = described_class.listed_ethnic_background?('Another ethnic group', 'Another ethnic group') + expect(result).to be_falsey + end + + it 'returns false if the group does not exist' do + result = described_class.listed_ethnic_background?('wrong group', '') + expect(result).to be_falsey + end + end end