diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index be905c8ccc..88a6ef60c1 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -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: { diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 06ba1e2626..34d16b641f 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -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