From ed4ba4f74268a01de2d335ced83ac5cb7e941c40 Mon Sep 17 00:00:00 2001 From: maebeale Date: Sat, 7 Mar 2026 06:46:44 -0500 Subject: [PATCH 1/2] Remove legacy age_range fields and add rake task to migrate data Remove age_range/age_range_spanish from workshop display, forms, strong params, decorators, and specs. Remove rhino_age_range_spanish rich text and age_range validation. Remove age_range from workshop_idea entirely. Add data:convert_age_ranges rake task that converts free-text age_range values into AgeRange categorizable_items, with [AGE_RANGE_DATA] comments for audit trail. Nils column values that exactly match a category name. Rename "Teen" seed to "13-17". Co-Authored-By: Claude Opus 4.6 --- app/controllers/workshop_ideas_controller.rb | 3 - app/controllers/workshops_controller.rb | 4 - app/decorators/workshop_decorator.rb | 8 +- app/decorators/workshop_idea_decorator.rb | 6 +- app/models/workshop.rb | 4 +- app/models/workshop_idea.rb | 1 - app/services/workshop_from_idea_service.rb | 3 +- app/views/workshops/_show_body.html.erb | 2 - db/seeds.rb | 2 +- lib/tasks/convert_age_ranges.rake | 205 ++++++++++++++++++ spec/models/workshop_spec.rb | 1 - spec/requests/workshop_ideas_spec.rb | 1 - spec/tasks/convert_age_ranges_spec.rb | 196 +++++++++++++++++ .../workshop_ideas/edit.html.erb_spec.rb | 1 - .../views/workshop_ideas/new.html.erb_spec.rb | 1 - spec/views/workshops/edit.html.erb_spec.rb | 1 - 16 files changed, 411 insertions(+), 28 deletions(-) create mode 100644 lib/tasks/convert_age_ranges.rake create mode 100644 spec/tasks/convert_age_ranges_spec.rb diff --git a/app/controllers/workshop_ideas_controller.rb b/app/controllers/workshop_ideas_controller.rb index 681e2fd0a..60dffd937 100644 --- a/app/controllers/workshop_ideas_controller.rb +++ b/app/controllers/workshop_ideas_controller.rb @@ -79,7 +79,6 @@ def destroy # Optional hooks for setting variables for forms or index def set_form_variables - @age_ranges = Category.includes(:category_type).where("category_types.name = 'AgeRange'").pluck(:name) @potential_series_workshops = authorized_scope(Workshop.published).includes(:windows_type).order(:title) @sectors = Sector.published @windows_types = WindowsType.all @@ -111,7 +110,6 @@ def workshop_idea_params :time_hours, :time_intro, :time_minutes, :time_opening, :time_opening_circle, :time_warm_up, - :age_range, :age_range_spanish, :closing, :closing_spanish, :creation, :creation_spanish, :demonstration, :demonstration_spanish, @@ -149,7 +147,6 @@ def workshop_idea_params :rhino_objective_spanish, :rhino_materials_spanish, :rhino_optional_materials_spanish, - :rhino_age_range_spanish, :rhino_setup_spanish, :rhino_introduction_spanish, :rhino_opening_circle_spanish, diff --git a/app/controllers/workshops_controller.rb b/app/controllers/workshops_controller.rb index 03ac9f226..886f1e0ea 100644 --- a/app/controllers/workshops_controller.rb +++ b/app/controllers/workshops_controller.rb @@ -188,8 +188,6 @@ def set_show def set_form_variables - @age_ranges = Category.includes(:category_type) - .where("category_types.name = 'AgeRange'").pluck(:name) potential_series = authorized_scope(Workshop.published).includes(:windows_type) potential_series = potential_series.where.not(id: @workshop.id) if @workshop.persisted? @potential_series_workshops = authorized_scope(potential_series).order(:title) @@ -228,7 +226,6 @@ def workshop_params :time_intro, :time_closing, :time_creation, :time_demonstration, :time_warm_up, :time_opening, :time_opening_circle, - :age_range, :age_range_spanish, :closing, :closing_spanish, :creation, :creation_spanish, :demonstration, :demonstration_spanish, @@ -267,7 +264,6 @@ def workshop_params :rhino_objective_spanish, :rhino_materials_spanish, :rhino_optional_materials_spanish, - :rhino_age_range_spanish, :rhino_setup_spanish, :rhino_introduction_spanish, :rhino_opening_circle_spanish, diff --git a/app/decorators/workshop_decorator.rb b/app/decorators/workshop_decorator.rb index fb3a5ac10..102f3ff8a 100644 --- a/app/decorators/workshop_decorator.rb +++ b/app/decorators/workshop_decorator.rb @@ -108,21 +108,22 @@ def spanish_field_values def display_fields [ :objective, :materials, :optional_materials, :timeframe, - :age_range, :setup, :introduction, :demonstration, + :setup, :introduction, :demonstration, :opening_circle, :warm_up, :visualization, :creation, :closing, :notes, :tips, :misc1, :misc2 ] end def display_spanish_fields - [ + fields = [ :objective_spanish, :materials_spanish, :optional_materials_spanish, - :age_range_spanish, :setup_spanish, + :setup_spanish, :introduction_spanish, :demonstration_spanish, :opening_circle_spanish, :warm_up_spanish, :visualization_spanish, :creation_spanish, :closing_spanish, :notes_spanish, :tips_spanish, :misc1_spanish, :misc2_spanish, :extra_field_spanish # :timeframe_spanish, ] + fields end def labels_spanish @@ -131,7 +132,6 @@ def labels_spanish materials_spanish: "Materiales", optional_materials_spanish: "Materiales Opcionales", timeframe_spanish: "Periodo de tiempo", - age_range_spanish: "Rango de edad", setup_spanish: "Preparativos", introduction_spanish: "Introducción", demonstration_spanish: "Demostración", diff --git a/app/decorators/workshop_idea_decorator.rb b/app/decorators/workshop_idea_decorator.rb index 477d7fd89..7bc9607fe 100644 --- a/app/decorators/workshop_idea_decorator.rb +++ b/app/decorators/workshop_idea_decorator.rb @@ -8,13 +8,14 @@ def default_display_image end def display_spanish_fields - [ + fields = [ :objective_spanish, :materials_spanish, :optional_materials_spanish, - :age_range_spanish, :setup_spanish, + :setup_spanish, :introduction_spanish, :demonstration_spanish, :opening_circle_spanish, :warm_up_spanish, :visualization_spanish, :creation_spanish, :closing_spanish, :notes_spanish, :tips_spanish # :timeframe_spanish, ] + fields end def labels_spanish @@ -23,7 +24,6 @@ def labels_spanish materials_spanish: "Materiales", optional_materials_spanish: "Materiales Opcionales", timeframe_spanish: "Periodo de tiempo", - age_range_spanish: "Rango de edad", setup_spanish: "Preparativos", introduction_spanish: "Introducción", demonstration_spanish: "Demostración", diff --git a/app/models/workshop.rb b/app/models/workshop.rb index c683b1ece..a3955f301 100644 --- a/app/models/workshop.rb +++ b/app/models/workshop.rb @@ -14,7 +14,7 @@ def self.mentionable_rich_text_fields :rhino_introduction, :rhino_opening_circle, :rhino_demonstration, :rhino_warm_up, :rhino_visualization, :rhino_creation, :rhino_closing, :rhino_notes, :rhino_tips, :rhino_misc1, :rhino_misc2, :rhino_extra_field, :rhino_objective_spanish, - :rhino_materials_spanish, :rhino_optional_materials_spanish, :rhino_age_range_spanish, + :rhino_materials_spanish, :rhino_optional_materials_spanish, :rhino_setup_spanish, :rhino_introduction_spanish, :rhino_opening_circle_spanish, :rhino_demonstration_spanish, :rhino_warm_up_spanish, :rhino_visualization_spanish, :rhino_creation_spanish, :rhino_closing_spanish, :rhino_notes_spanish, @@ -97,7 +97,6 @@ def self.mentionable_rich_text_fields has_rich_text :rhino_objective_spanish has_rich_text :rhino_materials_spanish has_rich_text :rhino_optional_materials_spanish - has_rich_text :rhino_age_range_spanish has_rich_text :rhino_setup_spanish has_rich_text :rhino_introduction_spanish has_rich_text :rhino_opening_circle_spanish @@ -123,7 +122,6 @@ def self.mentionable_rich_text_fields # Validations validates_presence_of :title # validates_presence_of :month, :year, if: Proc.new { |workshop| workshop.legacy } - validates_length_of :age_range, maximum: 16 validates :rating, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 5 } # Nested attributes diff --git a/app/models/workshop_idea.rb b/app/models/workshop_idea.rb index 55a9e5b69..a0d794c9f 100644 --- a/app/models/workshop_idea.rb +++ b/app/models/workshop_idea.rb @@ -57,7 +57,6 @@ class WorkshopIdea < ApplicationRecord has_rich_text :rhino_objective_spanish has_rich_text :rhino_materials_spanish has_rich_text :rhino_optional_materials_spanish - has_rich_text :rhino_age_range_spanish has_rich_text :rhino_setup_spanish has_rich_text :rhino_introduction_spanish has_rich_text :rhino_opening_circle_spanish diff --git a/app/services/workshop_from_idea_service.rb b/app/services/workshop_from_idea_service.rb index 40b54ba19..9d22362ae 100644 --- a/app/services/workshop_from_idea_service.rb +++ b/app/services/workshop_from_idea_service.rb @@ -18,7 +18,7 @@ def call def attributes_from_idea workshop_idea.attributes.slice( - "title", "windows_type_id", "age_range", "author_credit_preference", + "title", "windows_type_id", "author_credit_preference", "time_intro", "time_closing", "time_creation", "time_demonstration", "time_warm_up", "time_opening", "time_opening_circle" @@ -42,7 +42,6 @@ def attributes_from_idea rhino_objective_spanish: workshop_idea.rhino_objective_spanish, rhino_materials_spanish: workshop_idea.rhino_materials_spanish, rhino_optional_materials_spanish: workshop_idea.rhino_optional_materials_spanish, - rhino_age_range_spanish: workshop_idea.rhino_age_range_spanish, rhino_setup_spanish: workshop_idea.rhino_setup_spanish, rhino_introduction_spanish: workshop_idea.rhino_introduction_spanish, rhino_opening_circle_spanish: workshop_idea.rhino_opening_circle_spanish, diff --git a/app/views/workshops/_show_body.html.erb b/app/views/workshops/_show_body.html.erb index 90f3936f0..f25a24696 100644 --- a/app/views/workshops/_show_body.html.erb +++ b/app/views/workshops/_show_body.html.erb @@ -95,7 +95,6 @@ <% end %> <% workshop_sections = { "Objective" => workshop.rhino_objective, - "Age range" => workshop.age_range, "Materials" => workshop.rhino_materials, "Optional materials" => workshop.rhino_optional_materials, "Suggested time frame" => workshop.time_frame_total, @@ -155,7 +154,6 @@