Merge pull request #12857 from chahmedejaz/task/12626-add-clone-failure-explaination

[BUU] Fix No explanation why cloning failed
This commit is contained in:
Filipe
2024-09-27 17:58:31 -06:00
committed by GitHub
3 changed files with 13 additions and 4 deletions

View File

@@ -88,8 +88,8 @@ module Admin
@producer_options = producers
@category_options = categories
@tax_category_options = tax_category_options
rescue ActiveRecord::ActiveRecordError => _e
flash.now[:error] = t('.error')
rescue ActiveRecord::ActiveRecordError => e
flash.now[:error] = clone_error_message(e)
status = :unprocessable_entity
@product_index = "-1" # Create a unique enough index
end
@@ -213,6 +213,15 @@ module Admin
params.permit(products: ::PermittedAttributes::Product.attributes)
.to_h.with_indifferent_access
end
def clone_error_message(error)
case error
when ActiveRecord::RecordInvalid
error.record.errors.full_messages.to_sentence
else
t('.error')
end
end
end
end
# rubocop:enable Metrics/ClassLength

View File

@@ -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:

View File

@@ -303,7 +303,7 @@ RSpec.describe 'As an enterprise user, I can manage my products' do
click_product_clone "Apples"
expect(page).to have_content "Unable to clone the product"
expect(page).to have_content "Unit Scale can't be blank"
within "table.products" do
# Products does not include the cloned product.