From 2a4d275f4b2113975739f1a75565977b188f2e2d Mon Sep 17 00:00:00 2001 From: Ahmed Ejaz Date: Sat, 14 Sep 2024 02:44:43 +0500 Subject: [PATCH] 12626: use rails default error messages --- app/controllers/admin/products_v3_controller.rb | 15 +-------------- config/locales/en.yml | 2 +- spec/system/admin/products_v3/actions_spec.rb | 2 +- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index e2b6e4a9ad..7436ceab99 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -8,16 +8,6 @@ module Admin before_action :init_filters_params before_action :init_pagination_params - VIEW_FIELD_NAME_MAPPER = { - name: I18n.t("admin.products_page.columns.name"), - sku: I18n.t('admin.products_page.columns.sku'), - variant_unit: I18n.t('admin.products_page.columns.unit_scale'), - unit_presentation: I18n.t('admin.products_page.columns.unit'), - supplier_id: I18n.t('admin.products_page.columns.producer'), - primary_taxon_id: I18n.t('admin.products_page.columns.category'), - tax_category_id: I18n.t('admin.products_page.columns.tax_category') - }.freeze - def index fetch_products render "index", locals: { producers:, categories:, tax_category_options:, flash: } @@ -223,10 +213,7 @@ module Admin def clone_error_message(error) case error when ActiveRecord::RecordInvalid - field_names = error.record.errors.attribute_names - .map{ |field_name| VIEW_FIELD_NAME_MAPPER[field_name] }.join(', ') - - field_names.present? ? t('.invalid_fields_error', field_names:) : t('.error') + error.record.errors.full_messages.to_sentence else t('.error') end diff --git a/config/locales/en.yml b/config/locales/en.yml index 9b7ff82838..1900bd01c5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -70,7 +70,7 @@ en: price: "Price" primary_taxon_id: "Product Category" shipping_category_id: "Shipping Category" - variant_unit: "Variant Unit" + variant_unit: "Unit Scale" variant_unit_name: "Variant Unit Name" unit_value: "Unit value" spree/variant: diff --git a/spec/system/admin/products_v3/actions_spec.rb b/spec/system/admin/products_v3/actions_spec.rb index 176afcd7ee..839c47f690 100644 --- a/spec/system/admin/products_v3/actions_spec.rb +++ b/spec/system/admin/products_v3/actions_spec.rb @@ -269,7 +269,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do click_product_clone "Apples" - expect(page).to have_content "Product being cloned has invalid Unit scale" + expect(page).to have_content "Unit Scale can't be blank" within "table.products" do # Products does not include the cloned product.