Skip to content

Commit ad68c01

Browse files
dornerclaude
andcommitted
Rename KitItem STI class to Kit
Now that the standalone Kit model is gone and KitItem is the sole "kit" concept, rename the STI subclass from KitItem to Kit to match the UI label, the /kits routes, and the kit_item-free domain. - app/models/kit_item.rb -> app/models/kit.rb (class KitItem -> Kit) - Organization#kit_items association -> #kits - Update all class refs, is_a? checks, the create service, events, reports, views, seeds, factories and specs - Migration flips the items.type discriminator 'KitItem' -> 'Kit' - Drop two workarounds that were only needed while the class was KitItem: - EventsHelper#eventable_path: with the class named Kit, polymorphic routing resolves kit_path directly, so the event history row links the eventable normally again - the kit form's `url: kits_path, as: :kit` options: a new Kit now infers kits_path and the :kit param key by default Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3bb518d commit ad68c01

28 files changed

Lines changed: 140 additions & 132 deletions

app/controllers/items_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def index
1111
@items = @items.active unless params[:include_inactive_items]
1212

1313
@item_categories = current_organization.item_categories.includes(:items).order('name ASC')
14-
@kits = current_organization.kit_items.includes(line_items: :item)
14+
@kits = current_organization.kits.includes(line_items: :item)
1515
@storages = current_organization.storage_locations.active.order(id: :asc)
1616

1717
@include_inactive_items = params[:include_inactive_items]
@@ -139,7 +139,7 @@ def remove_category
139139

140140
def reporting_category_hint
141141
item = current_organization.items.find(params[:id])
142-
if item.is_a?(KitItem)
142+
if item.is_a?(Kit)
143143
"Kits are reported based on their contents."
144144
end
145145
end

app/controllers/kits_controller.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def show
44
end
55

66
def index
7-
@kits = current_organization.kit_items.includes(line_items: :item).class_filter(filter_params)
7+
@kits = current_organization.kits.includes(line_items: :item).class_filter(filter_params)
88
@inventory = View::Inventory.new(current_organization.id)
99
unless params[:include_inactive_items]
1010
@kits = @kits.active
@@ -15,7 +15,7 @@ def index
1515
def new
1616
load_form_collections
1717

18-
@kit = current_organization.kit_items.new
18+
@kit = current_organization.kits.new
1919
@kit.line_items.build
2020
end
2121

@@ -32,21 +32,21 @@ def create
3232
.join(", ")
3333

3434
load_form_collections
35-
@kit = current_organization.kit_items.new(kit_params)
35+
@kit = current_organization.kits.new(kit_params)
3636
@kit.line_items.build if @kit.line_items.empty?
3737

3838
render :new
3939
end
4040
end
4141

4242
def deactivate
43-
@kit = current_organization.kit_items.find(params[:id])
43+
@kit = current_organization.kits.find(params[:id])
4444
@kit.deactivate!
4545
redirect_back_or_to(dashboard_path, notice: "Kit has been deactivated!")
4646
end
4747

4848
def reactivate
49-
@kit = current_organization.kit_items.find(params[:id])
49+
@kit = current_organization.kits.find(params[:id])
5050
if @kit.can_reactivate?
5151
@kit.reactivate
5252
redirect_back_or_to(dashboard_path, notice: "Kit has been reactivated!")
@@ -56,15 +56,15 @@ def reactivate
5656
end
5757

5858
def allocations
59-
@kit = current_organization.kit_items.find(params[:id])
59+
@kit = current_organization.kits.find(params[:id])
6060
@storage_locations = current_organization.storage_locations.active
6161
@inventory = View::Inventory.new(current_organization.id)
6262

6363
load_form_collections
6464
end
6565

6666
def allocate
67-
@kit = current_organization.kit_items.find(params[:id])
67+
@kit = current_organization.kits.find(params[:id])
6868
@storage_location = current_organization.storage_locations.active.find(kit_adjustment_params[:storage_location_id])
6969
@change_by = kit_adjustment_params[:change_by].to_i
7070
begin
@@ -87,7 +87,7 @@ def load_form_collections
8787
end
8888

8989
def kit_params
90-
params.require(:kit_item).permit(
90+
params.require(:kit).permit(
9191
:name,
9292
:visible_to_partners,
9393
:value_in_dollars,

app/events/kit_allocate_event.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class KitAllocateEvent < Event
2-
def self.event_line_items(kit_item, storage_location, quantity)
3-
items = kit_item.line_items.map do |item|
2+
def self.event_line_items(kit, storage_location, quantity)
3+
items = kit.line_items.map do |item|
44
EventTypes::EventLineItem.new(
55
quantity: item.quantity * quantity,
66
item_id: item.item_id,
@@ -11,22 +11,22 @@ def self.event_line_items(kit_item, storage_location, quantity)
1111
end
1212
items.push(EventTypes::EventLineItem.new(
1313
quantity: quantity,
14-
item_id: kit_item.id,
15-
item_value_in_cents: kit_item.value_in_cents,
14+
item_id: kit.id,
15+
item_value_in_cents: kit.value_in_cents,
1616
to_storage_location: storage_location,
1717
from_storage_location: nil
1818
))
1919
items
2020
end
2121

22-
def self.publish(kit_item, storage_location, quantity)
22+
def self.publish(kit, storage_location, quantity)
2323
create!(
24-
eventable: kit_item,
25-
group_id: "kit-allocate-#{kit_item.id}-#{SecureRandom.hex}",
26-
organization_id: kit_item.organization_id,
24+
eventable: kit,
25+
group_id: "kit-allocate-#{kit.id}-#{SecureRandom.hex}",
26+
organization_id: kit.organization_id,
2727
event_time: Time.zone.now,
2828
data: EventTypes::InventoryPayload.new(
29-
items: event_line_items(kit_item, storage_location, quantity)
29+
items: event_line_items(kit, storage_location, quantity)
3030
)
3131
)
3232
end

app/events/kit_deallocate_event.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class KitDeallocateEvent < Event
2-
def self.event_line_items(kit_item, storage_location, quantity)
3-
items = kit_item.line_items.map do |item|
2+
def self.event_line_items(kit, storage_location, quantity)
3+
items = kit.line_items.map do |item|
44
EventTypes::EventLineItem.new(
55
quantity: item.quantity * quantity,
66
item_id: item.item_id,
@@ -11,22 +11,22 @@ def self.event_line_items(kit_item, storage_location, quantity)
1111
end
1212
items.push(EventTypes::EventLineItem.new(
1313
quantity: quantity,
14-
item_id: kit_item.id,
15-
item_value_in_cents: kit_item.value_in_cents,
14+
item_id: kit.id,
15+
item_value_in_cents: kit.value_in_cents,
1616
from_storage_location: storage_location,
1717
to_storage_location: nil
1818
))
1919
items
2020
end
2121

22-
def self.publish(kit_item, storage_location, quantity)
22+
def self.publish(kit, storage_location, quantity)
2323
create(
24-
eventable: kit_item,
25-
group_id: "kit-deallocate-#{kit_item.id}-#{SecureRandom.hex}",
26-
organization_id: kit_item.organization_id,
24+
eventable: kit,
25+
group_id: "kit-deallocate-#{kit.id}-#{SecureRandom.hex}",
26+
organization_id: kit.organization_id,
2727
event_time: Time.zone.now,
2828
data: EventTypes::InventoryPayload.new(
29-
items: event_line_items(kit_item, storage_location, quantity)
29+
items: event_line_items(kit, storage_location, quantity)
3030
)
3131
)
3232
end

app/helpers/events_helper.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/models/event.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Event < ApplicationRecord
4545
def no_intervening_snapshot
4646
return if is_a?(SnapshotEvent)
4747
return unless eventable.respond_to?(:organization)
48-
return if eventable.is_a?(KitItem)
48+
return if eventable.is_a?(Kit)
4949

5050
intervening = SnapshotEvent.intervening(eventable)
5151
if intervening.present?

app/models/item.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def is_in_kit?(kits = nil)
101101
if kits
102102
kits.any? { |k| k.line_items.map(&:item_id).include?(id) }
103103
else
104-
organization.kit_items
104+
organization.kits
105105
.active
106106
.joins(:line_items)
107107
.where(line_items: { item_id: id}).any?
@@ -191,7 +191,7 @@ def set_default_distribution_quantity
191191
self.distribution_quantity ||= default_distribution_quantity
192192
end
193193

194-
# Overridden in KitItem (kits default to 1).
194+
# Overridden in Kit (kits default to 1).
195195
def default_distribution_quantity
196196
50
197197
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
# kit_id :integer
2323
# organization_id :integer
2424
#
25-
class KitItem < Item
25+
class Kit < Item
2626
scope :by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
2727

28-
# Kit items are managed through the kits UI (deactivate/reactivate), not the normal
28+
# Kits are managed through the kits UI (deactivate/reactivate), not the normal
2929
# item-deletion path.
3030
def can_delete?(inventory = nil, kits = nil)
3131
false

app/models/organization.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class Organization < ApplicationRecord
8686
class_name: "Tag", inverse_of: false
8787
has_many :inventory_items, through: :storage_locations
8888
has_many :concrete_items
89-
has_many :kit_items
89+
has_many :kits
9090
has_many :transfers
9191
has_many :users, -> { distinct }, through: :roles
9292
has_many :vendors

app/services/kit_create_service.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ def call
2323

2424
organization.transaction do
2525
if kit_params[:line_items_attributes].blank?
26-
@kit = build_kit_item
26+
@kit = build_kit
2727
@kit.errors.add(:base, 'At least one item is required')
2828
raise ActiveRecord::RecordInvalid.new(@kit)
2929
end
3030

31-
# A kit is just a KitItem - an Item that contains other items as line items.
31+
# A kit is an Item (STI type 'Kit') that contains other items as line items.
3232
item_creation = ItemCreateService.new(
3333
organization_id: organization.id,
34-
item_params: kit_item_params
34+
item_params: kit_attributes
3535
)
3636

3737
item_creation_result = item_creation.call
@@ -56,16 +56,16 @@ def organization
5656
@organization ||= Organization.find_by(id: organization_id)
5757
end
5858

59-
# All kit items share the same "Kit" base item / partner_key.
60-
def kit_item_params
59+
# All kits share the same "Kit" base item / partner_key.
60+
def kit_attributes
6161
kit_params.merge(
62-
type: 'KitItem',
62+
type: 'Kit',
6363
partner_key: KitCreateService.find_or_create_kit_base_item!.partner_key
6464
)
6565
end
6666

67-
def build_kit_item
68-
organization.kit_items.new(kit_params.except(:line_items_attributes))
67+
def build_kit
68+
organization.kits.new(kit_params.except(:line_items_attributes))
6969
end
7070

7171
def valid?
@@ -85,9 +85,9 @@ def kit_validation_errors
8585
return @kit_validation_errors if @kit_validation_errors
8686

8787
# Exclude line_items_attributes; the line item validity is checked when the item is saved.
88-
kit_item = build_kit_item
89-
kit_item.valid?
88+
kit = build_kit
89+
kit.valid?
9090

91-
@kit_validation_errors = kit_item.errors
91+
@kit_validation_errors = kit.errors
9292
end
9393
end

0 commit comments

Comments
 (0)