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
4 changes: 2 additions & 2 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index
filtered = unfiltered.category_type_id(params[:category_type_id])
.category_name(params[:category_name])
.published_search(params[:published_search])
.order(Arel.sql("metadata.name, categories.position, categories.name"))
.order(Arel.sql("category_types.name, categories.position, categories.name"))
@categories = filtered.paginate(page: params[:page], per_page: per_page)

@count_display = if filtered.count == unfiltered.count
Expand Down Expand Up @@ -70,7 +70,7 @@ def set_category
# Strong parameters
def category_params
params.require(:category).permit(
:name, :category_type_id, :metadatum_id, :published, :position
:name, :category_type_id, :published, :position
)
end
end
2 changes: 1 addition & 1 deletion app/controllers/taggings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def matrix
.includes(:category_type)
.joins(:category_type, :categorizable_items)
.published
.select("categories.*, metadata.name AS category_type_name")
.select("categories.*, category_types.name AS category_type_name")
.distinct
.order(Arel.sql("category_type_name, categories.position, categories.name"))

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def categories
.includes(:category_type, :categorizable_items)
.references(:category_type, :categorizable_items)
.published
.select("categories.*, metadata.name AS category_type_name")
.select("categories.*, category_types.name AS category_type_name")
.distinct
.order(Arel.sql("category_type_name, categories.position, categories.name"))

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/workshop_ideas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def set_form_variables
@workshop_idea.build_primary_asset if @workshop_idea.primary_asset.blank?
@workshop_idea.gallery_assets.build

@age_ranges = Category.includes(:category_type).where("metadata.name = 'AgeRange'").pluck(:name)
@age_ranges = Category.includes(:category_type).where("category_types.name = 'AgeRange'").pluck(:name)
@potential_series_workshops = Workshop.published.order(:title)
@category_types = CategoryType.includes(:categories).published.decorate
@sectors = Sector.published
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/workshops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def set_form_variables
@workshop.build_primary_asset if @workshop.primary_asset.blank?
@workshop.gallery_assets.build

@age_ranges = Category.includes(:category_type).where("metadata.name = 'AgeRange'").pluck(:name)
@age_ranges = Category.includes(:category_type).where("category_types.name = 'AgeRange'").pluck(:name)
@potential_series_workshops = Workshop.published.where.not(id: @workshop.id).order(:title)
@windows_types = WindowsType.all
@workshop_ideas = WorkshopIdea.order(created_at: :desc)
Expand Down
7 changes: 0 additions & 7 deletions app/decorators/metadatum_decorator.rb

This file was deleted.

6 changes: 3 additions & 3 deletions app/models/category.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class Category < ApplicationRecord
include NameFilterable

belongs_to :category_type, class_name: "CategoryType", foreign_key: :metadatum_id
belongs_to :category_type, class_name: "CategoryType", foreign_key: :category_type_id
has_many :categorizable_items, dependent: :destroy
has_many :workshops, through: :categorizable_items, source: :categorizable, source_type: "Workshop"

scope :age_ranges, -> { joins(:category_type).where("metadata.name = 'AgeRange'") }
scope :age_ranges, -> { joins(:category_type).where("category_types.name = 'AgeRange'") }
scope :published, -> { where(published: true) }

# Validations
Expand All @@ -18,7 +18,7 @@ class Category < ApplicationRecord

# Scopes
scope :category_type_id, ->(category_type_id) {
category_type_id.present? ? where(metadatum_id: category_type_id) : all }
category_type_id.present? ? where(category_type_id: category_type_id) : all }
scope :category_name, ->(category_name) {
category_name.present? ? where("categories.name LIKE ?", "%#{category_name}%") : all }
scope :published, ->(published = nil) {
Expand Down
4 changes: 1 addition & 3 deletions app/models/category_type.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class CategoryType < ApplicationRecord
self.table_name = "metadata"

has_many :categories, class_name: "Category", foreign_key: :metadatum_id, dependent: :destroy
has_many :categories, class_name: "Category", foreign_key: :category_type_id, dependent: :destroy
has_many :categorizable_items, through: :categories, dependent: :destroy

# Validations
Expand Down
9 changes: 0 additions & 9 deletions app/models/metadatum.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/categories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<!-- Category Type -->
<div class="flex-1 min-w-[220px]">
<%= f.input :metadatum_id,
<%= f.input :category_type_id,
label: "Category Type",
collection: @category_types,
label_method: :name,
Expand Down
2 changes: 1 addition & 1 deletion app/views/workshops/_show_tags.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<div class="flex flex-wrap gap-2">
<% categories
.order(Arel.sql("metadata.name, categories.position, categories.name")).each do |category| %>
.order(Arel.sql("category_types.name, categories.position, categories.name")).each do |category| %>
<%= render "categories/tagging_label", category: category %>
<% end %>
</div>
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20260124053505_rename_metadata_to_category_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class RenameMetadataToCategoryType < ActiveRecord::Migration[8.1]
def change
rename_table :metadata, :category_types
rename_column :categories, :metadatum_id, :category_type_id
end
end
24 changes: 12 additions & 12 deletions 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_01_20_212705) do
ActiveRecord::Schema[8.1].define(version: 2026_01_24_053505) 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 Expand Up @@ -213,14 +213,14 @@
end

create_table "categories", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.integer "category_type_id"
t.datetime "created_at", precision: nil, null: false
t.integer "legacy_id"
t.integer "metadatum_id"
t.string "name"
t.integer "position", default: 10, null: false
t.boolean "published", default: false
t.datetime "updated_at", precision: nil, null: false
t.index ["metadatum_id"], name: "index_categories_on_metadatum_id"
t.index ["category_type_id"], name: "index_categories_on_category_type_id"
end

create_table "categorizable_items", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
Expand All @@ -236,6 +236,14 @@
t.index ["category_id"], name: "index_categorizable_items_on_category_id"
end

create_table "category_types", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.datetime "created_at", precision: nil, null: false
t.string "legacy_id"
t.string "name"
t.boolean "published", default: false
t.datetime "updated_at", precision: nil, null: false
end

create_table "ckeditor_assets", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "actual_url"
t.integer "assetable_id"
Expand Down Expand Up @@ -450,14 +458,6 @@
t.integer "workshop_log_id"
end

create_table "metadata", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.datetime "created_at", precision: nil, null: false
t.string "legacy_id"
t.string "name"
t.boolean "published", default: false
t.datetime "updated_at", precision: nil, null: false
end

create_table "monthly_reports", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "best_call_time"
t.boolean "call_requested"
Expand Down Expand Up @@ -1079,7 +1079,7 @@
add_foreign_key "banners", "users", column: "updated_by_id"
add_foreign_key "bookmark_annotations", "bookmarks"
add_foreign_key "bookmarks", "users"
add_foreign_key "categories", "metadata"
add_foreign_key "categories", "category_types"
add_foreign_key "community_news", "projects"
add_foreign_key "community_news", "users", column: "author_id"
add_foreign_key "community_news", "users", column: "created_by_id"
Expand Down
6 changes: 0 additions & 6 deletions spec/factories/metadata.rb

This file was deleted.

29 changes: 29 additions & 0 deletions spec/models/category_type_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rails_helper'

RSpec.describe CategoryType do
# let(:category_type) { build(:category_type) } # Keep if needed

describe 'associations' do
it { should have_many(:categories).class_name("Category").dependent(:destroy) }
it 'has the correct foreign key for categories' do
expect(CategoryType.reflect_on_association(:categories).foreign_key.to_sym).to eq(:category_type_id)
end
it { should have_many(:categorizable_items).through(:categories).dependent(:destroy) }
end

describe 'validations' do
let!(:existing_category_type) { create(:category_type) }
subject { build(:category_type, name: existing_category_type.name) }
it { should validate_presence_of(:name) }
end

describe 'scopes' do
let!(:published_category_type) { create(:category_type, published: true) }
let!(:unpublished_category_type) { create(:category_type, published: false) }

it '.published returns only published category types' do
expect(CategoryType.published).to include(published_category_type)
expect(CategoryType.published).not_to include(unpublished_category_type)
end
end
end
26 changes: 0 additions & 26 deletions spec/models/metadatum_spec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/requests/categories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
let(:valid_attributes) do
{
name: "Test Category",
metadatum_id: create(:category_type).id,
category_type_id: create(:category_type).id,
published: true
}
end

let(:invalid_attributes) do
{
name: "", # invalid: required
metadatum_id: nil, # invalid: must exist
category_type_id: nil, # invalid: must exist
published: nil # invalid: boolean required
}
end
Expand Down
2 changes: 1 addition & 1 deletion spec/views/categories/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
assert_select "input[name=?]", "category[name]"

# Category Type select
assert_select "select[name=?]", "category[metadatum_id]"
assert_select "select[name=?]", "category[category_type_id]"

# Position field
assert_select "input[name=?][type=number]", "category[position]"
Expand Down
2 changes: 1 addition & 1 deletion spec/views/categories/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

assert_select "form[action=?][method=?]", categories_path, "post" do
assert_select "input[name=?]", "category[name]"
assert_select "select[name=?]", "category[metadatum_id]"
assert_select "select[name=?]", "category[category_type_id]"
assert_select "input[name=?][type=number]", "category[position]"
assert_select "input[name=?]", "category[published]"
end
Expand Down