diff --git a/app/helpers/event_helper.rb b/app/helpers/event_helper.rb index 25ac9f890a..92f4e8fdea 100644 --- a/app/helpers/event_helper.rb +++ b/app/helpers/event_helper.rb @@ -143,7 +143,7 @@ def resolve_answer_text(field, submitted_answer) case field&.field_identifier when *FormField::SECTOR_FIELD_IDENTIFIERS resolve.call(Sector) - when "primary_age_group", "additional_age_group" + when *FormField::AGE_GROUP_FIELD_IDENTIFIERS resolve.call(Category) else submitted_answer diff --git a/app/models/form_field.rb b/app/models/form_field.rb index 6b7c55d1cc..ff1619dcfe 100644 --- a/app/models/form_field.rb +++ b/app/models/form_field.rb @@ -37,15 +37,20 @@ class FormField < ApplicationRecord # (as a string). Maps the field identifier to its backing CategoryType name. DYNAMIC_FIELD_CATEGORY_TYPES = { "primary_age_group" => "AgeRange", + "additional_age_groups" => "AgeRange", "additional_age_group" => "AgeRange" }.freeze # The "primary" and "additional" age group fields. Both are backed by AgeRange # categories but omit the catch-all "Mixed-age groups" category — a respondent # names the concrete age groups they serve, not the mixed bucket. + # + # The "additional" field is multi-select, so its current identifier is plural; + # the legacy singular name is kept so existing form data keeps resolving + # (current name first, legacy last — matching the sector identifiers). PRIMARY_AGE_GROUP_FIELD_IDENTIFIER = "primary_age_group" - ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIER = "additional_age_group" - AGE_GROUP_FIELD_IDENTIFIERS = [ PRIMARY_AGE_GROUP_FIELD_IDENTIFIER, ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIER ].freeze + ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIERS = %w[additional_age_groups additional_age_group].freeze + AGE_GROUP_FIELD_IDENTIFIERS = [ PRIMARY_AGE_GROUP_FIELD_IDENTIFIER, *ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIERS ].freeze # The payment-method field. Its answer options ("Credit card (now)", etc.) are # wired to Stripe charge logic in the controllers, so they must not be edited diff --git a/app/models/person.rb b/app/models/person.rb index 424dd07d15..d600ac8123 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -229,8 +229,9 @@ def remote_search_label end # Field identifiers whose "Other" free text maps onto the category-backed - # profile fields shown on the edit page. - OTHER_WORKSHOP_SETTING_IDENTIFIERS = %w[primary_age_group additional_age_group].freeze + # profile fields shown on the edit page. Mirrors the age group fields (current + # plural + legacy singular) so both keep resolving. + OTHER_WORKSHOP_SETTING_IDENTIFIERS = FormField::AGE_GROUP_FIELD_IDENTIFIERS # Free-text "Other" sectors the person typed on registration forms. # They can't be Sector records, so they're surfaced beside the sector tags. diff --git a/app/services/event_registration_services/public_registration.rb b/app/services/event_registration_services/public_registration.rb index ff7c3e3e82..dd00ad22d2 100644 --- a/app/services/event_registration_services/public_registration.rb +++ b/app/services/event_registration_services/public_registration.rb @@ -276,7 +276,7 @@ def assign_tags(person, organization) primary_sector_ids = collect_sector_ids(FormField::PRIMARY_SECTOR_FIELD_IDENTIFIERS) additional_sector_ids = collect_sector_ids(FormField::ADDITIONAL_SECTOR_FIELD_IDENTIFIERS) primary_age_ids = collect_ids_from_checkboxes("primary_age_group") - additional_age_ids = collect_ids_from_checkboxes("additional_age_group") + additional_age_ids = FormField::ADDITIONAL_AGE_GROUP_FIELD_IDENTIFIERS.flat_map { |id| collect_ids_from_checkboxes(id) } if primary_sector_ids.any? || additional_sector_ids.any? person.tag_sectors(primary_ids: primary_sector_ids, additional_ids: additional_sector_ids) diff --git a/app/services/form_builder_service.rb b/app/services/form_builder_service.rb index daa33f5721..49928c9b00 100644 --- a/app/services/form_builder_service.rb +++ b/app/services/form_builder_service.rb @@ -49,7 +49,7 @@ def call agency_street agency_city agency_state agency_zip agency_country ], person_background: %w[racial_ethnic_identity], - professional_info: %w[primary_sector_single additional_sectors primary_age_group additional_age_group], + professional_info: %w[primary_sector_single additional_sectors primary_age_group additional_age_groups], marketing: %w[referral_source training_motivation interested_in_more], scholarship: %w[scholarship_eligibility scholarship_contribution impact_description implementation_plan additional_comments], payment: %w[payment_method], @@ -86,7 +86,7 @@ def call "Organization Country" ], person_background: [ "How would you best describe yourself?" ], - professional_info: [ "Primary sector", "Additional sectors", "Primary Age Group(s) Served", "Additional Age Group(s) Served" ], + professional_info: [ "Primary sector", "Additional sectors", "Primary age group served", "Additional age groups served" ], marketing: [ "How did you hear about this AWBW training?", "What motivated you to sign up for AWBW's Facilitator Training?", @@ -450,11 +450,11 @@ def build_professional_info_fields(form, position) position = add_field(form, position, "Additional sectors", :multi_select_checkbox, key: "additional_sectors", group: "professional", required: false, subtitle: "Select all options that represent who you intend to serve through the art workshops (check all that apply)") - position = add_field(form, position, "Primary Age Group(s) Served", :single_select_dropdown, + position = add_field(form, position, "Primary age group served", :single_select_dropdown, key: "primary_age_group", group: "professional", required: false, subtitle: "Select the age group you primarily intend to serve through the art workshops") - position = add_field(form, position, "Additional Age Group(s) Served", :multi_select_checkbox, - key: "additional_age_group", group: "professional", required: false, + position = add_field(form, position, "Additional age groups served", :multi_select_checkbox, + key: "additional_age_groups", group: "professional", required: false, subtitle: "Select all additional age groups you may serve through the art workshops (check all that apply)") position end diff --git a/spec/models/form_field_spec.rb b/spec/models/form_field_spec.rb index 51a44c9e50..79307a81c5 100644 --- a/spec/models/form_field_spec.rb +++ b/spec/models/form_field_spec.rb @@ -445,12 +445,20 @@ def selectable_field(type:, option_names:) type = create(:category_type, name: "AgeRange") concrete = create(:category, :published, category_type: type, name: "3-5") mixed = create(:category, :published, category_type: type, name: Category::MIXED_AGE_RANGE_NAME) - field = create(:form_field, form: form, answer_type: :multi_select_checkbox, field_identifier: "additional_age_group") + field = create(:form_field, form: form, answer_type: :multi_select_checkbox, field_identifier: "additional_age_groups") expect(field.dynamic_categories).to eq([ concrete ]) expect(field.answer_inclusion_error([ concrete.id.to_s ])).to be_nil expect(field.answer_inclusion_error([ mixed.id.to_s ])).to eq("has an invalid selection") end + + it "still resolves the legacy singular additional_age_group identifier" do + type = create(:category_type, name: "AgeRange") + concrete = create(:category, :published, category_type: type, name: "3-5") + field = create(:form_field, form: form, answer_type: :multi_select_checkbox, field_identifier: "additional_age_group") + + expect(field.dynamic_categories).to eq([ concrete ]) + end end end diff --git a/spec/services/event_registration_services/public_registration_spec.rb b/spec/services/event_registration_services/public_registration_spec.rb index 7f9eb316a2..629237c75e 100644 --- a/spec/services/event_registration_services/public_registration_spec.rb +++ b/spec/services/event_registration_services/public_registration_spec.rb @@ -185,7 +185,7 @@ def register_with(position:) form: form, form_params: base_form_params(first_name: "Al", last_name: "Ng", email: "al@example.com").merge( field_id("primary_age_group") => [ young.id.to_s ], - field_id("additional_age_group") => [ teen.id.to_s ] + field_id("additional_age_groups") => [ teen.id.to_s ] ) ) diff --git a/spec/services/form_builder_service_spec.rb b/spec/services/form_builder_service_spec.rb index b6717e268c..bd7fc439a5 100644 --- a/spec/services/form_builder_service_spec.rb +++ b/spec/services/form_builder_service_spec.rb @@ -153,7 +153,7 @@ it "asks for a single primary age group via a dropdown alongside additional-age checkboxes" do primary = form.form_fields.find_by(field_identifier: "primary_age_group") - additional = form.form_fields.find_by(field_identifier: "additional_age_group") + additional = form.form_fields.find_by(field_identifier: "additional_age_groups") expect(primary.answer_type).to eq("single_select_dropdown") expect(additional.answer_type).to eq("multi_select_checkbox") diff --git a/spec/system/public_registration_form_submission_spec.rb b/spec/system/public_registration_form_submission_spec.rb index ac7c04f389..2a7b75726c 100644 --- a/spec/system/public_registration_form_submission_spec.rb +++ b/spec/system/public_registration_form_submission_spec.rb @@ -101,7 +101,7 @@ "primary_sector_single" => sector_education.id.to_s, "additional_sectors" => sector_mental_health.id.to_s, "primary_age_group" => age_adults.id.to_s, - "additional_age_group" => age_teens.id.to_s, + "additional_age_groups" => age_teens.id.to_s, "racial_ethnic_identity" => "Multi-racial", "referral_source" => "Online Search", "training_motivation" => "Address staff burnout through art", @@ -393,7 +393,7 @@ def fill_full_registration select_pr reg_field("primary_sector_single"), "Education" check_pr_box reg_field("additional_sectors"), sector_mental_health.id.to_s select_pr reg_field("primary_age_group"), "Adults (18+)" - check_pr_box reg_field("additional_age_group"), age_teens.id.to_s + check_pr_box reg_field("additional_age_groups"), age_teens.id.to_s choose_pr_radio reg_field("racial_ethnic_identity"), "Multi-racial" choose_pr_radio reg_field("referral_source"), "Online Search"