From 33c31915b6c92f5bba0251adc7cf5a322e2494dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Carranza?= <56557289+Glitch-art@users.noreply.github.com> Date: Tue, 25 Feb 2025 00:12:42 -0500 Subject: [PATCH] Add package size validation to Item model and update form input --- app/models/item.rb | 1 + app/views/items/_form.html.erb | 2 +- spec/models/item_spec.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/item.rb b/app/models/item.rb index 480bff9a83..71549af5fe 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -41,6 +41,7 @@ class Item < ApplicationRecord validates :distribution_quantity, numericality: { greater_than: 0 }, allow_blank: true validates :on_hand_recommended_quantity, numericality: { greater_than_or_equal_to: 0 }, allow_blank: true validates :on_hand_minimum_quantity, numericality: { greater_than_or_equal_to: 0 } + validates :package_size, numericality: { greater_than_or_equal_to: 0 }, allow_blank: true has_many :line_items, dependent: :destroy has_many :inventory_items, dependent: :destroy diff --git a/app/views/items/_form.html.erb b/app/views/items/_form.html.erb index a1f6bc43cb..7af1f6e98e 100644 --- a/app/views/items/_form.html.erb +++ b/app/views/items/_form.html.erb @@ -40,7 +40,7 @@ <% end %> <%= f.input :name, label: "Package size", wrapper: :input_group do %> - <%= f.input_field :package_size, class: "form-control" %> + <%= f.input_field :package_size, class: "form-control", min: 0 %> <% end %> <% if Flipper.enabled?(:enable_packs) %> diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index b643412c32..91c40c9af7 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -41,6 +41,7 @@ it { should validate_numericality_of(:on_hand_minimum_quantity).is_greater_than_or_equal_to(0) } it { should validate_numericality_of(:on_hand_recommended_quantity).is_greater_than_or_equal_to(0) } it { should validate_length_of(:additional_info).is_at_most(500) } + it { should validate_numericality_of(:package_size).is_greater_than_or_equal_to(0) } end context "Filtering >" do