Skip to content

Commit

Permalink
Add package size validation to Item model and update form input
Browse files Browse the repository at this point in the history
  • Loading branch information
Glitch-art committed Feb 25, 2025
1 parent d73c67a commit 33c3191
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/items/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>
Expand Down
1 change: 1 addition & 0 deletions spec/models/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 33c3191

Please sign in to comment.