Skip to content
Merged
2 changes: 1 addition & 1 deletion app/controllers/concerns/ahoy_tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def track_index_intent(resource_class, scope, params)
if scope.respond_to?(:total_entries) # will_paginate
scope.total_entries
elsif scope.respond_to?(:count)
count = scope.count
count = scope.unscope(:select).count
Copy link
Collaborator

Choose a reason for hiding this comment

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

an ahoy test was breaking bc of this

count.is_a?(Hash) ? count.size : count
else
0
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/workshops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class WorkshopsController < ApplicationController

def index
authorize!
@category_types = CategoryType.published.order(:name).decorate
@sectors = Sector.published
@category_types = CategoryType.published.where(story_specific: false).order(:name).decorate
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't show story population on workshops tags dropdowns

@sectors = Sector.published.order(:name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

alphabetize sector names in dropdowns

@windows_types = WindowsType.all

if turbo_frame_request?
Expand All @@ -21,6 +21,7 @@ def index

render :workshop_results
else
@sort = params[:sort].presence || "title"
render :index
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default class extends Controller {
input.checked = false;
});
// this.element.reset();
this.element.reset();
this.submitForm();
}

Expand Down
2 changes: 1 addition & 1 deletion app/services/workshop_search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def call

# Compute the effective sort
def default_sort
params[:sort].presence || "created"
params[:sort].presence || "title"
Copy link
Collaborator

Choose a reason for hiding this comment

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

change default sort

# return params[:sort] if params[:sort].present?
# return 'keywords' if params[:query].present? # only when returning weighted results from # search_by_query
# 'title'
Expand Down
14 changes: 7 additions & 7 deletions app/views/workshops/_filters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@

<div class="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4 overflow-visible p-4">

<%= render "dropdown_filter",
dom_id_prefix: "windows-types",
label_text: "Windows Audience",
items: @windows_types,
label_method: :short_name,
param_name: :windows_types %>

Copy link
Collaborator

Choose a reason for hiding this comment

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

move windows audience first bc people weren't noticing it

<%= render "categories_fields", category_types: @category_types %>

<%= render "dropdown_filter",
Expand All @@ -32,12 +39,5 @@
items: @sectors.reject { |sector| sector.name == "Other" },
param_name: :sectors %>

<%= render "dropdown_filter",
dom_id_prefix: "windows-types",
label_text: "Windows Type",
items: @windows_types,
label_method: :short_name,
param_name: :windows_types %>

<%= render "inactive_fields" if allowed_to?(:manage?, Workshop) %>
</div>
2 changes: 1 addition & 1 deletion app/views/workshops/_sort_by_options.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="flex items-center gap-1">
<label class="flex items-center gap-1 cursor-pointer">
<%= radio_button_tag :sort, "created",
@sort == "created" || !params[:sort].present? %>
@sort == "created" %>
<span class="text-sm">Newest</span>
</label>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class AddNotNullConstraintsToAffiliations < ActiveRecord::Migration[8.1]
def up
# Clean up any orphaned records before adding constraints
Affiliation.where(organization_id: nil).destroy_all
Affiliation.where(person_id: nil).destroy_all

change_column_null :affiliations, :organization_id, false
change_column_null :affiliations, :person_id, false

# Fix column type so foreign key can be added (people.id is int, not bigint)
change_column :affiliations, :person_id, :integer, null: false

unless foreign_key_exists?(:affiliations, :people, column: :person_id)
add_foreign_key :affiliations, :people, column: :person_id
end
end

def down
change_column_null :affiliations, :organization_id, true
change_column_null :affiliations, :person_id, true

if foreign_key_exists?(:affiliations, :people, column: :person_id)
remove_foreign_key :affiliations, :people, column: :person_id
end

change_column :affiliations, :person_id, :bigint
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2026_02_16_120927) do
ActiveRecord::Schema[8.1].define(version: 2026_02_16_231506) do
create_table "action_text_mentions", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.bigint "action_text_rich_text_id", null: false
t.datetime "created_at", null: false
Expand Down
2 changes: 1 addition & 1 deletion spec/models/affiliation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
build(:affiliation, organization: create(:organization), person: create(:person))
end
it { should validate_presence_of(:organization_id) }
it { should belong_to(:person) }
# it { should validate_presence_of(:person_id) } # we needed to not have this to support nested attrs
end

describe 'enums' do
Expand Down
39 changes: 37 additions & 2 deletions spec/services/workshop_search_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,41 @@
end
end

context "sorting by title ignores punctuation" do
let!(:hyphenated) { create(:workshop, :published, title: "Self-Care Workshop") }
let!(:spaced) { create(:workshop, :published, title: "Self Care Zen") }
let!(:quoted) { create(:workshop, :published, title: '"I Am" Mandalas') }
let!(:numbered) { create(:workshop, :published, title: "100 New Ideas") }
let!(:lowercase) { create(:workshop, :published, title: "a lowercase title") }

it "sorts case-insensitively" do
service = WorkshopSearchService.new({ sort: "title" }, user: user).call
titles = service.workshops.map(&:title)

lowercase_idx = titles.index("a lowercase title")
b_workshop_idx = titles.index("B Workshop")
expect(lowercase_idx).to be < b_workshop_idx
end

it "sorts numbers before letters" do
service = WorkshopSearchService.new({ sort: "title" }, user: user).call
titles = service.workshops.map(&:title)

numbered_idx = titles.index("100 New Ideas")
quoted_idx = titles.index('"I Am" Mandalas')
expect(numbered_idx).to be < quoted_idx
end

it "sorts hyphenated and spaced titles adjacently" do
service = WorkshopSearchService.new({ sort: "title" }, user: user).call
titles = service.workshops.map(&:title)

care_idx = titles.index("Self-Care Workshop")
zen_idx = titles.index("Self Care Zen")
expect((care_idx - zen_idx).abs).to eq(1)
end
end

context "sorting by led" do
it "orders descending by led_count then title" do
service = WorkshopSearchService.new({ sort: 'led' }, user: user).call
Expand Down Expand Up @@ -125,9 +160,9 @@
expect(service.sort).to eq('keywords')
end

it "defaults to created if no query or sort is provided" do
it "defaults to title if no query or sort is provided" do
service = WorkshopSearchService.new({}, user: user).call
expect(service.sort).to eq('created')
expect(service.sort).to eq('title')
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/system/workshops_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
fill_in 'query', with: 'best workshop'

# Open the dropdown
click_on "Windows Type" # 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