diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index 3ca3317aa8..039c1ebeca 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -61,6 +61,7 @@ module Spree localize_number :price, :weight + validates_lengths_from_database validate :check_currency validates :price, numericality: { greater_than_or_equal_to: 0 }, presence: true validates :tax_category, presence: true, diff --git a/app/views/admin/products_v3/_table.html.haml b/app/views/admin/products_v3/_table.html.haml index fe722ec40f..28d2a3ded3 100644 --- a/app/views/admin/products_v3/_table.html.haml +++ b/app/views/admin/products_v3/_table.html.haml @@ -67,15 +67,18 @@ - product.variants.each do |variant| = form.fields_for("products][][variants_attributes][", variant, index: nil) do |variant_form| %tr.condensed - %td.align-left + %td.field = variant_form.hidden_field :id = variant_form.text_field :display_name, 'aria-label': t('admin.products_page.columns.name'), placeholder: product.name - %td.align-right + = error_message_on variant, :display_name + %td.field = variant_form.text_field :sku, 'aria-label': t('admin.products_page.columns.sku') + = error_message_on variant, :sku %td.align-right .content= variant.unit_to_display - %td.align-right + %td.field = variant_form.text_field :price, 'aria-label': t('admin.products_page.columns.price'), value: number_to_currency(variant.price, unit: '')&.strip # TODO: add a spec to prove that this formatting is necessary. If so, it should be in a shared form helper for currency inputs + = error_message_on variant, :price %td.align-right .content= variant.on_hand || 0 #TODO: spec for this according to requirements. %td.align-left diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 85bf2e8c39..a706beeb41 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -263,11 +263,15 @@ describe 'As an admin, I can see the new product page' do end end - it "shows errors for product fields" do + it "shows errors for both product and variant fields" do within row_containing_name("Apples") do fill_in "Name", with: "" fill_in "SKU", with: "A" * 256 end + within row_containing_name("Medium box") do + fill_in "Name", with: "L" * 256 + fill_in "SKU", with: "1" * 256 + end expect { click_button "Save changes" @@ -282,6 +286,13 @@ describe 'As an admin, I can see the new product page' do expect(page).to have_content "is too long" end pending + within row_containing_name("L" * 256) do + expect(page).to have_field "Name", with: "L" * 256 + expect(page).to have_field "SKU", with: "1" * 256 + expect(page).to have_content "is too long" + expect(page).to have_field "Price", with: "10.25" + end + expect(page).to have_content "Please review the errors and try again" end end