mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Validate length of some product fields
We know if the values are too long, so let's provide a useful message rather than generating an unhandled database error. This code seems rather repetetive, it would be good to use a shared module. I wonder if there's a gem for that. Note that the existing /products/*/edit screen doesn't even handle validation errors yet, but that's something for another day..
This commit is contained in:
committed by
Rachel Arnould
parent
fee126d6e1
commit
3ec6386e1c
@@ -54,7 +54,8 @@ module Spree
|
||||
has_many :variant_images, -> { order(:position) }, source: :images,
|
||||
through: :variants
|
||||
|
||||
validates :name, presence: true
|
||||
validates :name, presence: true, length: { maximum: columns_hash['name'].limit }
|
||||
validates :sku, length: { maximum: columns_hash['sku'].limit }
|
||||
|
||||
validates :variant_unit, presence: true
|
||||
validates :unit_value, numericality: {
|
||||
|
||||
@@ -163,6 +163,10 @@ module Spree
|
||||
expect(build(:product)).to be_valid
|
||||
end
|
||||
|
||||
it { is_expected.to validate_presence_of :name }
|
||||
it { is_expected.to validate_length_of(:name).is_at_most(255) }
|
||||
it { is_expected.to validate_length_of(:sku).is_at_most(255) }
|
||||
|
||||
it "requires a primary taxon" do
|
||||
expect(build(:simple_product, primary_taxon: nil)).not_to be_valid
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user