Skip to content

Commit ac8a209

Browse files
authored
Add package size validation to Item model and update form input (#5039)
1 parent 397c4dd commit ac8a209

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

app/models/item.rb

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Item < ApplicationRecord
4141
validates :distribution_quantity, numericality: { greater_than: 0 }, allow_blank: true
4242
validates :on_hand_recommended_quantity, numericality: { greater_than_or_equal_to: 0 }, allow_blank: true
4343
validates :on_hand_minimum_quantity, numericality: { greater_than_or_equal_to: 0 }
44+
validates :package_size, numericality: { greater_than_or_equal_to: 0 }, allow_blank: true
4445

4546
has_many :line_items, dependent: :destroy
4647
has_many :inventory_items, dependent: :destroy

app/views/items/_form.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<% end %>
4141

4242
<%= f.input :name, label: "Package size", wrapper: :input_group do %>
43-
<%= f.input_field :package_size, class: "form-control" %>
43+
<%= f.input_field :package_size, class: "form-control", min: 0 %>
4444
<% end %>
4545

4646
<% if Flipper.enabled?(:enable_packs) %>

spec/models/item_spec.rb

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
it { should validate_numericality_of(:on_hand_minimum_quantity).is_greater_than_or_equal_to(0) }
4242
it { should validate_numericality_of(:on_hand_recommended_quantity).is_greater_than_or_equal_to(0) }
4343
it { should validate_length_of(:additional_info).is_at_most(500) }
44+
it { should validate_numericality_of(:package_size).is_greater_than_or_equal_to(0) }
4445
end
4546

4647
context "Filtering >" do

0 commit comments

Comments
 (0)