diff --git a/app/controllers/windows_types_controller.rb b/app/controllers/windows_types_controller.rb index b0df30cde..5dd24a17f 100644 --- a/app/controllers/windows_types_controller.rb +++ b/app/controllers/windows_types_controller.rb @@ -33,7 +33,7 @@ def create @windows_type.categories = Category.where(id: selected_ids) if @windows_type.save - redirect_to @windows_type, notice: "Windows type was successfully created." + redirect_to @windows_type, notice: "Windows audience was successfully created." else set_form_variables render :new, status: :unprocessable_content @@ -47,7 +47,7 @@ def update @windows_type.categories = Category.where(id: selected_ids) if @windows_type.update(windows_type_params) - redirect_to @windows_type, notice: "Windows type was successfully updated.", status: :see_other + redirect_to @windows_type, notice: "Windows audience was successfully updated.", status: :see_other else set_form_variables render :edit, status: :unprocessable_content @@ -57,7 +57,7 @@ def update def destroy authorize! @windows_type @windows_type.destroy! - redirect_to windows_types_path, notice: "Windows type was successfully destroyed." + redirect_to windows_types_path, notice: "Windows audience was successfully destroyed." end # Optional hooks for setting variables for forms or index diff --git a/app/decorators/category_type_decorator.rb b/app/decorators/category_type_decorator.rb index e49c32ec3..81b71a3d7 100644 --- a/app/decorators/category_type_decorator.rb +++ b/app/decorators/category_type_decorator.rb @@ -1,6 +1,6 @@ class CategoryTypeDecorator < ApplicationDecorator def title - name.titleize + name.underscore.humanize end def detail(length: nil) diff --git a/app/helpers/admin_cards_helper.rb b/app/helpers/admin_cards_helper.rb index 22ba7ffb3..8c66b2dfc 100644 --- a/app/helpers/admin_cards_helper.rb +++ b/app/helpers/admin_cards_helper.rb @@ -52,7 +52,7 @@ def reference_cards intensity: 100, title: "Sectors", params: { published: true }), - custom_card("Windows types", windows_types_path, icon: "🪟") + custom_card("Windows audiences", windows_types_path, icon: "🪟") ] end diff --git a/app/models/category_type.rb b/app/models/category_type.rb index fab3eb068..885fae570 100644 --- a/app/models/category_type.rb +++ b/app/models/category_type.rb @@ -14,6 +14,6 @@ class CategoryType < ApplicationRecord scope :profile_specific, -> { where(profile_specific: true) } def display_label - display_text.presence || name.titleize + display_text.presence || name.underscore.humanize end end diff --git a/app/views/admin/ahoy_activities/charts.html.erb b/app/views/admin/ahoy_activities/charts.html.erb index 93e13251b..63a904abb 100644 --- a/app/views/admin/ahoy_activities/charts.html.erb +++ b/app/views/admin/ahoy_activities/charts.html.erb @@ -139,7 +139,7 @@
- <%= bar_chart(@ws_windows_types, title: "Workshop Search: Windows Types") %> + <%= bar_chart(@ws_windows_types, title: "Workshop search: Windows audiences") %>
diff --git a/app/views/bookmarks/_search_fields.html.erb b/app/views/bookmarks/_search_fields.html.erb index 6d90a04f1..fbf57ed33 100644 --- a/app/views/bookmarks/_search_fields.html.erb +++ b/app/views/bookmarks/_search_fields.html.erb @@ -42,7 +42,7 @@
- <%= label_tag :windows_type, "Windows type", class: "block text-sm font-medium text-gray-700 mb-1" %> + <%= label_tag :windows_type, "Windows audience", class: "block text-sm font-medium text-gray-700 mb-1" %>
<%= select_tag :windows_type, options_for_select(@windows_types_array, diff --git a/app/views/organizations/_form.html.erb b/app/views/organizations/_form.html.erb index d5ef7b191..0b32a516d 100644 --- a/app/views/organizations/_form.html.erb +++ b/app/views/organizations/_form.html.erb @@ -22,7 +22,7 @@
- +
@@ -50,7 +50,7 @@
<%= f.association :windows_type, - label: "Windows Type", + label: "Windows audience", include_blank: true, required: false, input_html: { diff --git a/app/views/organizations/_search_boxes.html.erb b/app/views/organizations/_search_boxes.html.erb index 8fa0d0bc0..c06da8533 100644 --- a/app/views/organizations/_search_boxes.html.erb +++ b/app/views/organizations/_search_boxes.html.erb @@ -10,7 +10,7 @@ focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %>
- <%= label_tag :windows_type_name, "Windows type", class: "text-sm font-medium text-gray-700 mb-1 block" %> + <%= label_tag :windows_type_name, "Windows audience", class: "text-sm font-medium text-gray-700 mb-1 block" %> <%= select_tag :windows_type_name, options_for_select(WindowsType::TYPES.map { |wt| [wt, wt] }, params[:windows_type_name]), diff --git a/app/views/stories/_story_results.html.erb b/app/views/stories/_story_results.html.erb index 2f978e48e..7573b259d 100644 --- a/app/views/stories/_story_results.html.erb +++ b/app/views/stories/_story_results.html.erb @@ -22,7 +22,7 @@ <%= sort_link.call("title", "Title") %> - <%= sort_link.call("windows_type", "Windows Type") %> + <%= sort_link.call("windows_type", "Windows audience") %> <%= sort_link.call("workshop", "Workshop") %> <%= sort_link.call("author", "Author") %> <%= sort_link.call("organization", "Organization") %> diff --git a/app/views/story_ideas/index.html.erb b/app/views/story_ideas/index.html.erb index 47112e8a6..6624fdc6d 100644 --- a/app/views/story_ideas/index.html.erb +++ b/app/views/story_ideas/index.html.erb @@ -22,7 +22,7 @@ Image Author Name - Windows Type + Windows audience Workshop Organization Updated At diff --git a/app/views/workshop_log_creation_wizard/_form.html.erb b/app/views/workshop_log_creation_wizard/_form.html.erb index feb5d759b..c2b79ac76 100644 --- a/app/views/workshop_log_creation_wizard/_form.html.erb +++ b/app/views/workshop_log_creation_wizard/_form.html.erb @@ -9,7 +9,7 @@ <%= f.hidden_field :id %> <%= f.hidden_field :log_id, value: @old_report ? @old_report.id : nil %> <% if @windows_types && !workshop.id %> - <%= f.label 'New Workshop Windows Type', class: 'bold' %> + <%= f.label 'New workshop windows audience', class: 'bold' %> <%= f.select :windows_type_id, @windows_types.map { |wtype| [wtype.name, wtype.id]} %> <% end %>
diff --git a/app/views/workshops/_dropdown_filter.html.erb b/app/views/workshops/_dropdown_filter.html.erb index d83dbba21..fa4fe75ff 100644 --- a/app/views/workshops/_dropdown_filter.html.erb +++ b/app/views/workshops/_dropdown_filter.html.erb @@ -41,7 +41,7 @@ id: "#{param_name}_#{item.id}", class: "category-checkbox" %> <%= label_tag "#{param_name}_#{item.id}", - item.public_send(label_method).titleize, + item.public_send(label_method).humanize, class: "text-sm text-gray-700" %>
<% end %> diff --git a/app/views/workshops/_filters.html.erb b/app/views/workshops/_filters.html.erb index 1d176ffe5..07d1c2955 100644 --- a/app/views/workshops/_filters.html.erb +++ b/app/views/workshops/_filters.html.erb @@ -26,7 +26,7 @@ <%= render "dropdown_filter", dom_id_prefix: "windows-types", - label_text: "Windows Audience", + label_text: "Windows audience", items: @windows_types, label_method: :short_name, param_name: :windows_types %> diff --git a/db/seeds.rb b/db/seeds.rb index be5255c60..944138a96 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -283,10 +283,10 @@ def find_or_create_by_name!(klass, name, **attrs, &block) category_type_categories = [ [ "AgeRange", "3-5" ], [ "AgeRange", "6-12" ], - [ "AgeRange", "Teen" ], + [ "AgeRange", "13-17" ], [ "AgeRange", "18+" ], [ "AgeRange", "Mixed-age groups" ], - [ "AgeRange", "Family Windows" ], + [ "AgeRange", "Family windows" ], # ["ArtType", "Boxes", 1], [ "ArtType", "Clay", 11 ], [ "ArtType", "Collage", 2 ], @@ -399,6 +399,12 @@ def find_or_create_by_name!(klass, name, **attrs, &block) cat.update!(published: true) unless cat.published? end +puts "Setting AgeRange category positions…" +age_range_order = [ "3-5", "6-12", "13-17", "18+", "Mixed-age groups", "Family windows" ] +age_range_order.each_with_index do |name, i| + Category.where("LOWER(name) = LOWER(?)", name).update_all(position: i + 1) +end + puts "Creating StoryPopulation CategoryType…" story_population_type = find_or_create_by_name!(CategoryType, "StoryPopulation") do |ct| ct.display_text = "Who is this story about?" diff --git a/spec/decorators/category_type_decorator_spec.rb b/spec/decorators/category_type_decorator_spec.rb new file mode 100644 index 000000000..16b06853c --- /dev/null +++ b/spec/decorators/category_type_decorator_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe CategoryTypeDecorator do + describe '#title' do + it 'returns the name in sentence case' do + category_type = build(:category_type, name: "art_type").decorate + expect(category_type.title).to eq("Art type") + end + + it 'capitalizes only the first word' do + category_type = build(:category_type, name: "emotional_theme").decorate + expect(category_type.title).to eq("Emotional theme") + end + end +end diff --git a/spec/models/category_type_spec.rb b/spec/models/category_type_spec.rb index a652e9790..c403c0e16 100644 --- a/spec/models/category_type_spec.rb +++ b/spec/models/category_type_spec.rb @@ -17,6 +17,18 @@ it { should validate_presence_of(:name) } end + describe '#display_label' do + it 'returns display_text when present' do + category_type = build(:category_type, name: "art_type", display_text: "Custom Label") + expect(category_type.display_label).to eq("Custom Label") + end + + it 'returns sentence-cased name when display_text is blank' do + category_type = build(:category_type, name: "art_type", display_text: nil) + expect(category_type.display_label).to eq("Art type") + end + end + describe 'scopes' do let!(:published_category_type) { create(:category_type, :published) } let!(:unpublished_category_type) { create(:category_type) } diff --git a/spec/system/person_filters_workshops_test.rb b/spec/system/person_filters_workshops_test.rb index 64d6977fe..f483c918d 100644 --- a/spec/system/person_filters_workshops_test.rb +++ b/spec/system/person_filters_workshops_test.rb @@ -41,7 +41,7 @@ expect(page).to have_content('The best workshop in the world') expect(page).to have_content('oh hello!') expect(page).to have_content('The best workshop on mars') - expect(page).to have_content('Windows Type') + expect(page).to have_content('Windows audience') expect(page).to have_content('Sector') expect(page).to have_content('Visibility') end diff --git a/spec/system/workshops_spec.rb b/spec/system/workshops_spec.rb index 5ee3b95e7..f9a6918e8 100644 --- a/spec/system/workshops_spec.rb +++ b/spec/system/workshops_spec.rb @@ -34,7 +34,7 @@ fill_in 'query', with: 'best workshop' # Open the dropdown - click_on "Windows Audience" # this clicks the