Skip to content

Commit

Permalink
rename findorcreatebaseitem to add !
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyli97 committed Aug 9, 2024
1 parent 7f166cc commit 2c5ed05
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/base_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def show
# TODO there are no buttons on the view to call this method, consider removing?
def destroy
@base_item = BaseItem.includes(:items).find(params[:id])
if (@base_item.id = KitCreateService.FindOrCreateKitBaseItem.id)
if (@base_item.id = KitCreateService.FindOrCreateKitBaseItem!.id)
redirect_to admin_base_items_path, alert: "You cannot delete the Kits base item. This is reserved for all Kits."
elsif @base_item.items.any? && @base_item.destroy
redirect_to admin_base_items_path, notice: "Base Item deleted!"
Expand Down
2 changes: 1 addition & 1 deletion app/models/base_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ def self.seed_base_items
end
end
# Create global 'Kit' base item
KitCreateService.FindOrCreateKitBaseItem
KitCreateService.FindOrCreateKitBaseItem!
end
end
6 changes: 3 additions & 3 deletions app/services/kit_create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class KitCreateService

attr_reader :kit

def self.FindOrCreateKitBaseItem
def self.FindOrCreateKitBaseItem!
BaseItem.find_or_create_by!(KIT_BASE_ITEM_ATTRS)
end

Expand All @@ -27,9 +27,9 @@ def call
@kit.save!

# Find or create the BaseItem for all items housing kits
item_housing_a_kit_base_item = BaseItem.find_or_create_by!(KIT_BASE_ITEM_ATTRS)
item_housing_a_kit_base_item = KitCreateService.FindOrCreateKitBaseItem!

# Create the Item.
# Create the item
item_creation = ItemCreateService.new(
organization_id: organization.id,
item_params: {
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/admin/base_items_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
end

it "doesn't let you delete the Kit base item" do
kit_base_item = KitCreateService.FindOrCreateKitBaseItem
kit_base_item = KitCreateService.FindOrCreateKitBaseItem!
delete admin_base_item_path(id: kit_base_item.id)
expect(flash[:alert]).to include("You cannot delete the Kits base item")
expect(response).to be_redirect
Expand Down

0 comments on commit 2c5ed05

Please sign in to comment.