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 @@
18 y más
") + run_task + expect(age_range_category_names(workshop)).to eq [ "13-17", "18+" ] + end + end + + describe "skipped values" do + it "skips '0', 'x', 'n/a'" do + %w[0 x n/a].each do |val| + workshop = create(:workshop, age_range: val) + run_task + Rake::Task["data:convert_age_ranges"].reenable + expect(age_range_category_names(workshop)).to eq([]), "Expected '#{val}' to be skipped" + end + end + + it "skips nil/blank values" do + workshop = create(:workshop, age_range: nil, age_range_spanish: nil) + run_task + expect(age_range_category_names(workshop)).to eq [] + end + end + + describe "idempotency" do + it "does not duplicate categories on re-run" do + workshop = create(:workshop, age_range: "6-12") + run_task + Rake::Task["data:convert_age_ranges"].reenable + run_task + expect(age_range_category_names(workshop)).to eq [ "6-12" ] + end + end + + describe "nilling exact matches" do + it "nils age_range when it exactly matches a category name" do + workshop = create(:workshop, age_range: "18+") + run_task + expect(workshop.reload.age_range).to be_nil + end + + it "nils age_range_spanish when it exactly matches a category name" do + workshop = create(:workshop, age_range: nil, age_range_spanish: "18+") + run_task + expect(workshop.reload.age_range_spanish).to be_nil + end + + it "does not nil age_range when value does not match a category name" do + workshop = create(:workshop, age_range: "5-12") + run_task + expect(workshop.reload.age_range).to eq "5-12" + end + end + + describe "comments" do + it "creates an auto-applied comment with [AGE_RANGE_DATA] tag" do + workshop = create(:workshop, age_range: "6-12") + run_task + comment = workshop.reload.comments.first + expect(comment).to be_present + expect(comment.body).to include("[AGE_RANGE_DATA]") + expect(comment.body).to include("Auto-applied age range categories: 6-12") + expect(comment.body).to include("age_range: '6-12'") + end + + it "creates an unmatched comment with [AGE_RANGE_DATA] tag" do + workshop = create(:workshop, age_range: "potato") + run_task + comment = workshop.reload.comments.first + expect(comment).to be_present + expect(comment.body).to include("[AGE_RANGE_DATA]") + expect(comment.body).to include("Could not auto-apply") + expect(comment.body).to include("age_range: 'potato'") + end + + it "does not create a comment when already tagged" do + workshop = create(:workshop, age_range: "6-12") + workshop.categorizable_items.create!(category: cat_6_12) + run_task + expect(workshop.reload.comments.count).to eq 0 + end + end +end diff --git a/spec/views/workshop_ideas/edit.html.erb_spec.rb b/spec/views/workshop_ideas/edit.html.erb_spec.rb index 819c8a3c6..57db42f11 100644 --- a/spec/views/workshop_ideas/edit.html.erb_spec.rb +++ b/spec/views/workshop_ideas/edit.html.erb_spec.rb @@ -13,7 +13,6 @@ assign(:windows_types, []) assign(:sectors, []) assign(:categories_grouped, []) - assign(:age_ranges, []) assign(:potential_series_workshops, []) assign(:users, User.none) end diff --git a/spec/views/workshop_ideas/new.html.erb_spec.rb b/spec/views/workshop_ideas/new.html.erb_spec.rb index 1d6d18087..2ed237b26 100644 --- a/spec/views/workshop_ideas/new.html.erb_spec.rb +++ b/spec/views/workshop_ideas/new.html.erb_spec.rb @@ -11,7 +11,6 @@ assign(:windows_types, []) assign(:sectors, []) assign(:categories_grouped, []) - assign(:age_ranges, []) assign(:potential_series_workshops, []) assign(:users, User.none) end diff --git a/spec/views/workshops/edit.html.erb_spec.rb b/spec/views/workshops/edit.html.erb_spec.rb index c5806a0eb..0a21ec1fc 100644 --- a/spec/views/workshops/edit.html.erb_spec.rb +++ b/spec/views/workshops/edit.html.erb_spec.rb @@ -7,7 +7,6 @@ before(:each) do assign(:workshop, workshop) - assign(:age_ranges, []) assign(:potential_series_workshops, []) assign(:windows_types, []) assign(:workshop_ideas, [])