Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/windows_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/category_type_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CategoryTypeDecorator < ApplicationDecorator
def title
name.titleize
name.underscore.humanize
end

def detail(length: nil)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/admin_cards_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/models/category_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/views/admin/ahoy_activities/charts.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
</div>

<div class="bg-white border border-gray-200 rounded-xl shadow-sm p-6">
<%= bar_chart(@ws_windows_types, title: "Workshop Search: Windows Types") %>
<%= bar_chart(@ws_windows_types, title: "Workshop search: Windows audiences") %>
</div>

<div class="bg-white border border-gray-200 rounded-xl shadow-sm p-6">
Expand Down
2 changes: 1 addition & 1 deletion app/views/bookmarks/_search_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<!-- Type Dropdown -->
<div>
<%= 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" %>
<div class="relative">
<%= select_tag :windows_type,
options_for_select(@windows_types_array,
Expand Down
4 changes: 2 additions & 2 deletions app/views/organizations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
</div>

<!-- Sectors & Windows Type -->
<!-- Sectors & Windows audience -->
<div class="grid grid-cols-1 md:grid-cols-[3fr_1fr] gap-4 items-start">
<div class="form-group space-y-4">
<div class="font-semibold text-gray-700 mb-2">
Expand Down Expand Up @@ -50,7 +50,7 @@

<div>
<%= f.association :windows_type,
label: "Windows Type",
label: "Windows audience",
include_blank: true,
required: false,
input_html: {
Expand Down
2 changes: 1 addition & 1 deletion app/views/organizations/_search_boxes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
focus:border-blue-500 focus:ring focus:ring-blue-200 focus:outline-none" %>
</div>
<div>
<%= 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]),
Expand Down
2 changes: 1 addition & 1 deletion app/views/stories/_story_results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700"><%= sort_link.call("title", "Title") %></th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700"><%= sort_link.call("windows_type", "Windows Type") %></th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700"><%= sort_link.call("windows_type", "Windows audience") %></th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700"><%= sort_link.call("workshop", "Workshop") %></th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700"><%= sort_link.call("author", "Author") %></th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700"><%= sort_link.call("organization", "Organization") %></th>
Expand Down
2 changes: 1 addition & 1 deletion app/views/story_ideas/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700"><span class="pl-3">Image</span></th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700">Author</th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700">Name</th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700">Windows Type</th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700">Windows audience</th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700">Workshop</th>
<th class="px-4 py-2 text-left text-sm font-medium text-gray-700">Organization</th>
<th class="px-4 py-2 text-center text-sm font-medium text-gray-700">Updated At</th>
Expand Down
2 changes: 1 addition & 1 deletion app/views/workshop_log_creation_wizard/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
<br>
Expand Down
2 changes: 1 addition & 1 deletion app/views/workshops/_dropdown_filter.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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" %>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/workshops/_filters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
10 changes: 8 additions & 2 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ],
Expand Down Expand Up @@ -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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding position to age range seeds so they match prod


puts "Creating StoryPopulation CategoryType…"
story_population_type = find_or_create_by_name!(CategoryType, "StoryPopulation") do |ct|
ct.display_text = "Who is this story about?"
Expand Down
15 changes: 15 additions & 0 deletions spec/decorators/category_type_decorator_spec.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions spec/models/category_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion spec/system/person_filters_workshops_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/system/workshops_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
fill_in 'query', with: 'best workshop'

# Open the dropdown
click_on "Windows Audience" # this clicks the <button> text/label
click_on "Windows audience" # this clicks the <button> text/label
check("windows_types_#{adult_window.id}")

expect(page).to have_content(workshop_world.title)
Expand Down Expand Up @@ -74,7 +74,7 @@
expect(page).to have_content(workshop_adult.title)

# Also check a windows type checkbox
click_on "Windows Audience"
click_on "Windows audience"
check("windows_types_#{adult_window.id}")
expect(page).to have_content(workshop_adult.title)

Expand Down
6 changes: 3 additions & 3 deletions spec/views/stories/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@
expect(rendered).to include("Adults")
end

it "displays general category type with titleized name" do
it "displays general category type with sentence-cased name" do
render

expect(rendered).to include("Age Range")
expect(rendered).to include("Age range")
end

it "displays general category checkboxes" do
Expand All @@ -244,7 +244,7 @@
render

population_pos = rendered.index("Who is this story about?")
age_range_pos = rendered.index("Age Range")
age_range_pos = rendered.index("Age range")
expect(population_pos).to be < age_range_pos
end
end
Expand Down